Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/sol auth #653

Merged
merged 9 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/poor-fans-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@moralisweb3/auth': minor
---

Added solana authentication to auth package
3 changes: 2 additions & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"@moralisweb3/api-utils": "^2.3.1",
"@moralisweb3/core": "^2.3.1",
"@moralisweb3/evm-utils": "^2.3.1"
"@moralisweb3/evm-utils": "^2.3.1",
"@moralisweb3/sol-utils": "^2.3.1"
}
}
17 changes: 15 additions & 2 deletions packages/auth/src/MoralisAuth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { ApiModule, MoralisCore, MoralisCoreProvider } from '@moralisweb3/core';
import { makeRequestMessage, RequestMessageOptions } from './methods/requestMessage';
import { makeVerify, VerifyOptions } from './methods/verify';
import {
makeVerify,
VerifyEvmData,
VerifyEvmOptions,
VerifyOptions,
VerifySolData,
VerifySolOptions,
} from './methods/verify';

export const BASE_URL = 'https://auth-api.do-prod-1.moralis.io';

Expand All @@ -24,5 +31,11 @@ export class MoralisAuth extends ApiModule {
}

public requestMessage = (options: RequestMessageOptions) => makeRequestMessage(this.core)(options);
public verify = (options: VerifyOptions) => makeVerify(this.core)(options);

// Function overloading to make typescript happy
public verify(options: VerifyEvmOptions): VerifyEvmData;
public verify(options: VerifySolOptions): VerifySolData;
public verify(options: VerifyOptions) {
return makeVerify(this.core)(options);
}
}
258 changes: 253 additions & 5 deletions packages/auth/src/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export interface paths {
"/challenge/verify/evm": {
post: operations["verifyChallengeEvm"];
};
"/challenge/request/solana": {
post: operations["requestChallengeSolana"];
};
"/challenge/verify/solana": {
post: operations["verifyChallengeSolana"];
};
}

export interface components {
Expand All @@ -27,8 +33,24 @@ export interface components {
/**
* @description EIP-155 Chain ID to which the session is bound, and the network where Contract Accounts must be resolved.
* @example 1
* @enum {string}
*/
chainId: number;
chainId:
| "1"
| "3"
| "4"
| "5"
| "25"
| "42"
| "56"
| "97"
| "137"
| "250"
| "338"
| "1337"
| "43113"
| "43114"
| "80001";
/**
* @description Ethereum address performing the signing conformant to capitalization encoded checksum specified in EIP-55 where applicable.
* @example 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B
Expand Down Expand Up @@ -75,8 +97,8 @@ export interface components {
};
EvmChallengeResponseDto: {
/**
* @description Secret Challenge ID used to identify this particular request. Is should be used at the backend of the calling service to identify the completed request.
* @example fRyt67D3eRss3RrX
* @description 17-characters Alphanumeric string Secret Challenge ID used to identify this particular request. Is should be used at the backend of the calling service to identify the completed request.
* @example fRyt67D3eRss3RrXa
*/
id: string;
/**
Expand Down Expand Up @@ -110,7 +132,7 @@ export interface components {
};
EvmCompleteChallengeResponseDto: {
/**
* @description Secret Challenge ID used to identify this particular request. Is should be used at the backend of the calling service to identify the completed request.
* @description 17-characters Alphanumeric string Secret Challenge ID used to identify this particular request. Is should be used at the backend of the calling service to identify the completed request.
* @example fRyt67D3eRss3RrX
*/
id: string;
Expand All @@ -123,8 +145,24 @@ export interface components {
/**
* @description EIP-155 Chain ID to which the session is bound, and the network where Contract Accounts must be resolved.
* @example 1
* @enum {string}
*/
chainId: number;
chainId:
| "1"
| "3"
| "4"
| "5"
| "25"
| "42"
| "56"
| "97"
| "137"
| "250"
| "338"
| "1337"
| "43113"
| "43114"
| "80001";
/**
* @description Ethereum address performing the signing conformant to capitalization encoded checksum specified in EIP-55 where applicable.
* @example 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B
Expand Down Expand Up @@ -175,6 +213,184 @@ export interface components {
*/
profileId: string;
};
SolanaChallengeRequestDto: {
/**
* Format: hostname
* @description RFC 4501 dns authority that is requesting the signing.
* @example defi.finance
*/
domain: string;
/**
* @description The network where Contract Accounts must be resolved.
* @example mainnet
* @enum {string}
*/
network: "mainnet" | "testnet" | "devnet";
/**
* @description Solana public key with a length of 44 characters that is used to perform the signing
* @example 26qv4GCcx98RihuK3c4T6ozB3J7L6VwCuFVc7Ta2A3Uo
*/
address: string;
/**
* @description Human-readable ASCII assertion that the user will sign, and it must not contain `
* `.
* @example Please confirm
*/
statement?: string;
/**
* Format: uri
* @description RFC 3986 URI referring to the resource that is the subject of the signing (as in the __subject__ of a claim).
* @example https://defi.finance/
*/
uri: string;
/**
* Format: date-time
* @description ISO 8601 datetime string that, if present, indicates when the signed authentication message is no longer valid.
* @example 2020-01-01T00:00:00.000Z
*/
expirationTime?: string;
/**
* Format: date-time
* @description ISO 8601 datetime string that, if present, indicates when the signed authentication message will become valid.
* @example 2020-01-01T00:00:00.000Z
*/
notBefore?: string;
/**
* @description List of information or references to information the user wishes to have resolved as part of authentication by the relying party. They are expressed as RFC 3986 URIs separated by `
* - `.
* @example [
* "https://docs.moralis.io/"
* ]
*/
resources?: string[];
/**
* @description Time in seconds before the challenge is expired
* @default 15
* @example 15
*/
timeout: number;
};
SolanaChallengeResponseDto: {
/**
* @description 17-characters Alphanumeric string Secret Challenge ID used to identify this particular request. Is should be used at the backend of the calling service to identify the completed request.
* @example fRyt67D3eRss3RrX
*/
id: string;
/**
* @description Message that needs to be signed by the end user
* @example defi.finance wants you to sign in with your Solana account:
* 26qv4GCcx98RihuK3c4T6ozB3J7L6VwCuFVc7Ta2A3Uo
*
* I am a third party API
*
* URI: http://defi.finance
* Version: 1
* Network: mainnet
* Nonce: PYxxb9msdjVXsMQ9x
* Issued At: 2022-08-25T11:02:34.097Z
* Expiration Time: 2022-08-25T11:12:38.243Z
* Resources:
* - https://docs.moralis.io/
*/
message: string;
/**
* @description Unique identifier with a length of 66 characters
* @example 0xbfbcfab169c67072ff418133124480fea02175f1402aaa497daa4fd09026b0e1
*/
profileId: string;
};
SolanaCompleteChallengeRequestDto: {
/**
* @description Message that needs to be signed by the end user
* @example defi.finance wants you to sign in with your Solana account:
* 26qv4GCcx98RihuK3c4T6ozB3J7L6VwCuFVc7Ta2A3Uo
*
* I am a third party API
*
* URI: http://defi.finance
* Version: 1
* Network: mainnet
* Nonce: PYxxb9msdjVXsMQ9x
* Issued At: 2022-08-25T11:02:34.097Z
* Expiration Time: 2022-08-25T11:12:38.243Z
* Resources:
* - https://docs.moralis.io/
*/
message: string;
/**
* @description Base58 signature that needs to be used to verify end user
* @example 2pH9DqD5rve2qV4yBDshcAjWd2y8TqMx8BPb7f3KoNnuLEhE5JwjruYi4jaFaD4HN6wriLz2Vdr32kRBAJmHcyny
*/
signature: string;
};
SolanaCompleteChallengeResponseDto: {
/**
* @description 17-characters Alphanumeric string Secret Challenge ID used to identify this particular request. Is should be used at the backend of the calling service to identify the completed request.
* @example fRyt67D3eRss3RrX
*/
id: string;
/**
* Format: hostname
* @description RFC 4501 dns authority that is requesting the signing.
* @example defi.finance
*/
domain: string;
/**
* @description The network where Contract Accounts must be resolved.
* @example mainnet
* @enum {string}
*/
network: "mainnet" | "testnet" | "devnet";
/**
* @description Solana public key with a length of 44 characters that is used to perform the signing
* @example 26qv4GCcx98RihuK3c4T6ozB3J7L6VwCuFVc7Ta2A3Uo
*/
address: string;
/**
* @description Human-readable ASCII assertion that the user will sign, and it must not contain `
* `.
* @example Please confirm
*/
statement?: string;
/**
* Format: uri
* @description RFC 3986 URI referring to the resource that is the subject of the signing (as in the __subject__ of a claim).
* @example https://defi.finance/
*/
uri: string;
/**
* Format: date-time
* @description ISO 8601 datetime string that, if present, indicates when the signed authentication message is no longer valid.
* @example 2020-01-01T00:00:00.000Z
*/
expirationTime?: string;
/**
* Format: date-time
* @description ISO 8601 datetime string that, if present, indicates when the signed authentication message will become valid.
* @example 2020-01-01T00:00:00.000Z
*/
notBefore?: string;
/**
* @description List of information or references to information the user wishes to have resolved as part of authentication by the relying party. They are expressed as RFC 3986 URIs separated by `
* - `.
* @example [
* "https://docs.moralis.io/"
* ]
*/
resources?: string[];
/**
* @description EIP-155 Chain ID to which the session is bound, and the network where Contract Accounts must be resolved.
* @example 1.0
*/
version: string;
/** @example 0x1234567890abcdef0123456789abcdef1234567890abcdef */
nonce: string;
/**
* @description Unique identifier with a length of 66 characters
* @example 0xbfbcfab169c67072ff418133124480fea02175f1402aaa497daa4fd09026b0e1
*/
profileId: string;
};
};
}

Expand Down Expand Up @@ -305,6 +521,38 @@ export interface operations {
};
};
};
requestChallengeSolana: {
parameters: {};
responses: {
/** The back channel challenge containing the id to store on the api and the message to be signed by the user */
201: {
content: {
"application/json": components["schemas"]["SolanaChallengeResponseDto"];
};
};
};
requestBody: {
content: {
"application/json": components["schemas"]["SolanaChallengeRequestDto"];
};
};
};
verifyChallengeSolana: {
parameters: {};
responses: {
/** The token to be used to call the third party API from the client */
201: {
content: {
"application/json": components["schemas"]["SolanaCompleteChallengeResponseDto"];
};
};
};
requestBody: {
content: {
"application/json": components["schemas"]["SolanaCompleteChallengeRequestDto"];
};
};
};
}

export interface external {}
Loading