Skip to content

Commit

Permalink
feat: SolAuth
Browse files Browse the repository at this point in the history
Implement solana auth in auth package
  • Loading branch information
sogunshola committed Sep 6, 2022
1 parent 0708f49 commit dd3602a
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 31 deletions.
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': major
---

Added solana authentication to auth package
4 changes: 2 additions & 2 deletions demos/parse-server/src/auth/MoralisAuthAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function validateAuthData(authData: any) {
const data = result.toJSON();

if (id === data.profileId && authId === data.id) {
authData.chainId = result.result.chain.decimal;
authData.chainId = result.result.chain?.decimal;
authData.nonce = data.nonce;
authData.address = result.result.address.checksum;
authData.address = result.result.address.format();
authData.version = data.version;
authData.domain = data.domain;
authData.expirationTime = data.expirationTime;
Expand Down
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:
| "ETH"
| "ROPSTEN"
| "RINKEBY"
| "GOERLI"
| "CRONOS"
| "KOVAN"
| "BSC"
| "BSC_TESTNET"
| "POLYGON"
| "FANTOM"
| "CRONOS_TESTNET"
| "LOCALDEVCHAIN"
| "AVALANCHE_TESTNET"
| "AVALANCHE"
| "MUMBAI";
/**
* @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:
| "ETH"
| "ROPSTEN"
| "RINKEBY"
| "GOERLI"
| "CRONOS"
| "KOVAN"
| "BSC"
| "BSC_TESTNET"
| "POLYGON"
| "FANTOM"
| "CRONOS_TESTNET"
| "LOCALDEVCHAIN"
| "AVALANCHE_TESTNET"
| "AVALANCHE"
| "MUMBAI";
/**
* @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

0 comments on commit dd3602a

Please sign in to comment.