@metamask-previews/seedless-onboarding-controller 7.1.0-preview-40468f94 → 7.1.0-preview-fb7aa07ff
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -12
- package/dist/SeedlessOnboardingController.cjs +21 -128
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +3 -86
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +3 -86
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +22 -129
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +67 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +67 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +1 -31
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +0 -8
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +0 -8
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +0 -29
- package/dist/utils.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { SeedlessOnboardingController, getInitialSeedlessOnboardingControllerStateWithDefaults as getDefaultSeedlessOnboardingControllerState, } from "./SeedlessOnboardingController.mjs";
|
|
2
|
-
export type { SeedlessOnboardingControllerOptions, SeedlessOnboardingControllerMessenger, SeedlessOnboardingControllerGetStateAction,
|
|
3
|
-
export type { AuthenticatedUserDetails, SocialBackupsMetadata, SeedlessOnboardingControllerState, ToprfKeyDeriver, RecoveryErrorData, } from "./types.mjs";
|
|
2
|
+
export type { AuthenticatedUserDetails, SocialBackupsMetadata, SeedlessOnboardingControllerState, SeedlessOnboardingControllerOptions, SeedlessOnboardingControllerMessenger, SeedlessOnboardingControllerGetStateAction, SeedlessOnboardingControllerStateChangeEvent, SeedlessOnboardingControllerActions, SeedlessOnboardingControllerEvents, ToprfKeyDeriver, RecoveryErrorData, } from "./types.mjs";
|
|
4
3
|
export { Web3AuthNetwork, SeedlessOnboardingControllerErrorMessage, AuthConnection, SecretType, } from "./constants.mjs";
|
|
5
4
|
export { SecretMetadata } from "./SecretMetadata.mjs";
|
|
6
5
|
export { RecoveryError } from "./errors.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,uDAAuD,IAAI,2CAA2C,GACvG,2CAAuC;AACxC,YAAY,EACV,mCAAmC,EACnC,qCAAqC,EACrC,0CAA0C,EAC1C,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,uDAAuD,IAAI,2CAA2C,GACvG,2CAAuC;AACxC,YAAY,EACV,wBAAwB,EACxB,qBAAqB,EACrB,iCAAiC,EACjC,mCAAmC,EACnC,qCAAqC,EACrC,0CAA0C,EAC1C,4CAA4C,EAC5C,mCAAmC,EACnC,kCAAkC,EAClC,eAAe,EACf,iBAAiB,GAClB,oBAAgB;AACjB,OAAO,EACL,eAAe,EACf,wCAAwC,EACxC,cAAc,EACd,UAAU,GACX,wBAAoB;AACrB,OAAO,EAAE,cAAc,EAAE,6BAAyB;AAClD,OAAO,EAAE,aAAa,EAAE,qBAAiB"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,uDAAuD,IAAI,2CAA2C,EACvG,2CAAuC;
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,uDAAuD,IAAI,2CAA2C,EACvG,2CAAuC;AAcxC,OAAO,EACL,eAAe,EACf,wCAAwC,EACxC,cAAc,EACd,UAAU,EACX,wBAAoB;AACrB,OAAO,EAAE,cAAc,EAAE,6BAAyB;AAClD,OAAO,EAAE,aAAa,EAAE,qBAAiB","sourcesContent":["export {\n SeedlessOnboardingController,\n getInitialSeedlessOnboardingControllerStateWithDefaults as getDefaultSeedlessOnboardingControllerState,\n} from './SeedlessOnboardingController';\nexport type {\n AuthenticatedUserDetails,\n SocialBackupsMetadata,\n SeedlessOnboardingControllerState,\n SeedlessOnboardingControllerOptions,\n SeedlessOnboardingControllerMessenger,\n SeedlessOnboardingControllerGetStateAction,\n SeedlessOnboardingControllerStateChangeEvent,\n SeedlessOnboardingControllerActions,\n SeedlessOnboardingControllerEvents,\n ToprfKeyDeriver,\n RecoveryErrorData,\n} from './types';\nexport {\n Web3AuthNetwork,\n SeedlessOnboardingControllerErrorMessage,\n AuthConnection,\n SecretType,\n} from './constants';\nexport { SecretMetadata } from './SecretMetadata';\nexport { RecoveryError } from './errors';\n"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Encryptor } from '@metamask/keyring-controller';\nimport type { KeyPair, NodeAuthTokens } from '@metamask/toprf-secure-backup';\nimport type { MutexInterface } from 'async-mutex';\n\nimport type {\n AuthConnection,\n SecretMetadataVersion,\n SecretType,\n} from './constants';\n\n/**\n * The backup state of the secret data.\n * Each secret data added/restored will be stored in the state locally.\n *\n * This is used to track the backup status of the secret data.\n */\nexport type SocialBackupsMetadata = {\n /**\n * The hash of the secret data.\n */\n hash: string;\n\n /**\n * The type of the secret data.\n */\n type: SecretType;\n\n /**\n * The optional keyringId to identify the keyring that the secret data belongs to.\n *\n * This is only required for `Mnemonic` secret data.\n */\n keyringId?: string;\n};\n\nexport type AuthenticatedUserDetails = {\n /**\n * Type of social login provider.\n */\n authConnection: AuthConnection;\n\n /**\n * The node auth tokens from OAuth User authentication after the Social login.\n *\n * This values are used to authenticate users when they go through the Seedless Onboarding flow.\n */\n nodeAuthTokens: NodeAuthTokens;\n\n /**\n * OAuth connection id from web3auth dashboard.\n */\n authConnectionId: string;\n\n /**\n * The optional grouped authConnectionId to authenticate the user with Web3Auth network.\n */\n groupedAuthConnectionId?: string;\n\n /**\n * The user email or ID from Social login.\n */\n userId: string;\n\n /**\n * The user email from Social login.\n */\n socialLoginEmail: string;\n\n /**\n * The refresh token used to refresh expired nodeAuthTokens.\n */\n refreshToken: string;\n};\n\nexport type SRPBackedUpUserDetails = {\n /**\n * The public key of the authentication key pair in base64 format.\n *\n * This value is used to check if the password is outdated compare to the global password and find backed up old password.\n */\n authPubKey: string;\n};\n\n/**\n * The data of the recovery error.\n */\nexport type RecoveryErrorData = {\n /**\n * The remaining time in seconds before the user can try again.\n */\n remainingTime: number;\n\n /**\n * The number of attempts made by the user.\n */\n numberOfAttempts: number;\n};\n\n// State\nexport type SeedlessOnboardingControllerState =\n Partial<AuthenticatedUserDetails> &\n Partial<SRPBackedUpUserDetails> & {\n /**\n * Encrypted array of serialized keyrings data.\n */\n vault?: string;\n\n /**\n * The hashes of the seed phrase backups.\n *\n * This is to facilitate the UI to display backup status of the seed phrases.\n */\n socialBackupsMetadata: SocialBackupsMetadata[];\n\n /**\n * The encryption key derived from the password and used to encrypt\n * the vault.\n */\n vaultEncryptionKey?: string;\n\n /**\n * The salt used to derive the encryption key from the password.\n */\n vaultEncryptionSalt?: string;\n\n /**\n * Cache for checkIsPasswordOutdated result and timestamp.\n */\n passwordOutdatedCache?: { isExpiredPwd: boolean; timestamp: number };\n\n /**\n * The refresh token used to refresh expired nodeAuthTokens.\n * This is persisted in state.\n */\n refreshToken?: string;\n\n /**\n * The revoke token used to revoke refresh token and get new refresh token and new revoke token.\n * This is temporarily stored in state during authentication and then persisted in the vault.\n */\n revokeToken?: string;\n\n /**\n * The refresh token and revoke token to be revoked.\n * This is persisted in state to revoke old refresh token when possible.\n */\n pendingToBeRevokedTokens?: {\n refreshToken: string;\n revokeToken: string;\n }[];\n\n /**\n * The encrypted seedless encryption key used to encrypt the seedless vault.\n */\n encryptedSeedlessEncryptionKey?: string;\n\n /**\n * The encrypted keyring encryption key used to encrypt the keyring vault.\n */\n encryptedKeyringEncryptionKey?: string;\n\n /**\n * The access token used for pairing with profile sync auth service and to access other services.\n */\n accessToken?: string;\n\n /**\n * The metadata access token used to access the metadata service.\n *\n * This token is used to access the metadata service before the vault is created or unlocked.\n */\n metadataAccessToken?: string;\n\n /**\n * Whether the user is authenticated with social login and TOPRF service.\n */\n isSeedlessOnboardingUserAuthenticated: boolean;\n };\n\n/**\n * Encryptor interface for encrypting and decrypting seedless onboarding vault.\n */\nexport type VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams> =\n Encryptor<EncryptionKey, SupportedKeyDerivationParams>;\n\n/**\n * Additional key deriver for the TOPRF client.\n *\n * This is a function that takes a seed and salt and returns a key in bytes (Uint8Array).\n * It is used as an additional step during key derivation. This can be used, for example, to inject a slow key\n * derivation step to protect against local brute force attacks on the password.\n *\n * @default browser-passworder @link https://github.com/MetaMask/browser-passworder\n */\nexport type ToprfKeyDeriver = {\n /**\n * Derive a key from a seed and salt.\n *\n * @param seed - The seed to derive the key from.\n * @param salt - The salt to derive the key from.\n * @returns The derived key.\n */\n deriveKey: (seed: Uint8Array, salt: Uint8Array) => Promise<Uint8Array>;\n};\n\nexport type RefreshJWTToken = (params: {\n connection: AuthConnection;\n refreshToken: string;\n}) => Promise<{\n idTokens: string[];\n accessToken: string;\n metadataAccessToken: string;\n}>;\n\nexport type RevokeRefreshToken = (params: {\n connection: AuthConnection;\n revokeToken: string;\n}) => Promise<void>;\n\nexport type RenewRefreshToken = (params: {\n connection: AuthConnection;\n revokeToken: string;\n}) => Promise<{\n newRevokeToken: string;\n newRefreshToken: string;\n}>;\n\n/**\n * A function executed within a mutually exclusive lock, with\n * a mutex releaser in its option bag.\n *\n * @param releaseLock - A function to release the lock.\n */\nexport type MutuallyExclusiveCallback<Result> = ({\n releaseLock,\n}: {\n releaseLock: MutexInterface.Releaser;\n}) => Promise<Result>;\n\n/**\n * The structure of the data which is serialized and stored in the vault.\n */\nexport type VaultData = {\n /**\n * The encryption key to encrypt the seed phrase.\n */\n toprfEncryptionKey: string;\n /**\n * The encryption key to encrypt the password.\n */\n toprfPwEncryptionKey: string;\n /**\n * The authentication key pair to authenticate the TOPRF.\n */\n toprfAuthKeyPair: string;\n /**\n * The revoke token to revoke refresh token and get new refresh token and new revoke token.\n * The revoke token may no longer be available after a large number of password changes. In this case, re-authentication is advised.\n */\n revokeToken: string;\n /**\n * The access token used for pairing with profile sync auth service and to access other services.\n */\n accessToken: string;\n};\n\nexport type DeserializedVaultData = Pick<\n VaultData,\n 'accessToken' | 'revokeToken'\n> & {\n toprfEncryptionKey: Uint8Array;\n toprfPwEncryptionKey: Uint8Array;\n toprfAuthKeyPair: KeyPair;\n};\n\nexport type SecretDataType = Uint8Array | string | number;\n\n/**\n * The constructor options for the seed phrase metadata.\n */\nexport type SecretMetadataOptions = {\n /**\n * The timestamp when the seed phrase was created.\n */\n timestamp: number;\n /**\n * The type of the seed phrase.\n */\n type: SecretType;\n /**\n * The version of the seed phrase metadata.\n */\n version: SecretMetadataVersion;\n};\n\nexport type DecodedNodeAuthToken = {\n /**\n * The expiration time of the token in seconds.\n */\n exp: number;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n temp_key_x: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n temp_key_y: string;\n aud: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n verifier_name: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n verifier_id: string;\n scope: string;\n signature: string;\n};\n\nexport type DecodedBaseJWTToken = {\n /**\n * The expiration time of the token in seconds.\n */\n exp: number;\n /**\n * The issued at time of the token in seconds.\n */\n iat: number;\n /**\n * The audience of the token.\n */\n aud: string;\n /**\n * The issuer of the token.\n */\n iss: string;\n /**\n * The subject of the token.\n */\n sub: string;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Encryptor } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { KeyPair, NodeAuthTokens } from '@metamask/toprf-secure-backup';\nimport type { MutexInterface } from 'async-mutex';\n\nimport type {\n AuthConnection,\n controllerName,\n SecretMetadataVersion,\n SecretType,\n Web3AuthNetwork,\n} from './constants';\n\n/**\n * The backup state of the secret data.\n * Each secret data added/restored will be stored in the state locally.\n *\n * This is used to track the backup status of the secret data.\n */\nexport type SocialBackupsMetadata = {\n /**\n * The hash of the secret data.\n */\n hash: string;\n\n /**\n * The type of the secret data.\n */\n type: SecretType;\n\n /**\n * The optional keyringId to identify the keyring that the secret data belongs to.\n *\n * This is only required for `Mnemonic` secret data.\n */\n keyringId?: string;\n};\n\nexport type AuthenticatedUserDetails = {\n /**\n * Type of social login provider.\n */\n authConnection: AuthConnection;\n\n /**\n * The node auth tokens from OAuth User authentication after the Social login.\n *\n * This values are used to authenticate users when they go through the Seedless Onboarding flow.\n */\n nodeAuthTokens: NodeAuthTokens;\n\n /**\n * OAuth connection id from web3auth dashboard.\n */\n authConnectionId: string;\n\n /**\n * The optional grouped authConnectionId to authenticate the user with Web3Auth network.\n */\n groupedAuthConnectionId?: string;\n\n /**\n * The user email or ID from Social login.\n */\n userId: string;\n\n /**\n * The user email from Social login.\n */\n socialLoginEmail: string;\n\n /**\n * The refresh token used to refresh expired nodeAuthTokens.\n */\n refreshToken: string;\n};\n\nexport type SRPBackedUpUserDetails = {\n /**\n * The public key of the authentication key pair in base64 format.\n *\n * This value is used to check if the password is outdated compare to the global password and find backed up old password.\n */\n authPubKey: string;\n};\n\n/**\n * The data of the recovery error.\n */\nexport type RecoveryErrorData = {\n /**\n * The remaining time in seconds before the user can try again.\n */\n remainingTime: number;\n\n /**\n * The number of attempts made by the user.\n */\n numberOfAttempts: number;\n};\n\n// State\nexport type SeedlessOnboardingControllerState =\n Partial<AuthenticatedUserDetails> &\n Partial<SRPBackedUpUserDetails> & {\n /**\n * Encrypted array of serialized keyrings data.\n */\n vault?: string;\n\n /**\n * The hashes of the seed phrase backups.\n *\n * This is to facilitate the UI to display backup status of the seed phrases.\n */\n socialBackupsMetadata: SocialBackupsMetadata[];\n\n /**\n * The encryption key derived from the password and used to encrypt\n * the vault.\n */\n vaultEncryptionKey?: string;\n\n /**\n * The salt used to derive the encryption key from the password.\n */\n vaultEncryptionSalt?: string;\n\n /**\n * Cache for checkIsPasswordOutdated result and timestamp.\n */\n passwordOutdatedCache?: { isExpiredPwd: boolean; timestamp: number };\n\n /**\n * The refresh token used to refresh expired nodeAuthTokens.\n * This is persisted in state.\n */\n refreshToken?: string;\n\n /**\n * The revoke token used to revoke refresh token and get new refresh token and new revoke token.\n * This is temporarily stored in state during authentication and then persisted in the vault.\n */\n revokeToken?: string;\n\n /**\n * The refresh token and revoke token to be revoked.\n * This is persisted in state to revoke old refresh token when possible.\n */\n pendingToBeRevokedTokens?: {\n refreshToken: string;\n revokeToken: string;\n }[];\n\n /**\n * The encrypted seedless encryption key used to encrypt the seedless vault.\n */\n encryptedSeedlessEncryptionKey?: string;\n\n /**\n * The encrypted keyring encryption key used to encrypt the keyring vault.\n */\n encryptedKeyringEncryptionKey?: string;\n\n /**\n * The access token used for pairing with profile sync auth service and to access other services.\n */\n accessToken?: string;\n\n /**\n * The metadata access token used to access the metadata service.\n *\n * This token is used to access the metadata service before the vault is created or unlocked.\n */\n metadataAccessToken?: string;\n\n /**\n * Whether the user is authenticated with social login and TOPRF service.\n */\n isSeedlessOnboardingUserAuthenticated: boolean;\n };\n\n// Actions\nexport type SeedlessOnboardingControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n SeedlessOnboardingControllerState\n >;\nexport type SeedlessOnboardingControllerActions =\n SeedlessOnboardingControllerGetStateAction;\n\ntype AllowedActions = never;\n\n// Events\nexport type SeedlessOnboardingControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n SeedlessOnboardingControllerState\n >;\nexport type SeedlessOnboardingControllerEvents =\n SeedlessOnboardingControllerStateChangeEvent;\n\ntype AllowedEvents = never;\n\n// Messenger\nexport type SeedlessOnboardingControllerMessenger = Messenger<\n typeof controllerName,\n SeedlessOnboardingControllerActions | AllowedActions,\n SeedlessOnboardingControllerEvents | AllowedEvents\n>;\n\n/**\n * Encryptor interface for encrypting and decrypting seedless onboarding vault.\n */\nexport type VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams> = Omit<\n Encryptor<EncryptionKey, SupportedKeyDerivationParams>,\n 'encryptWithKey'\n>;\n\n/**\n * Additional key deriver for the TOPRF client.\n *\n * This is a function that takes a seed and salt and returns a key in bytes (Uint8Array).\n * It is used as an additional step during key derivation. This can be used, for example, to inject a slow key\n * derivation step to protect against local brute force attacks on the password.\n *\n * @default browser-passworder @link https://github.com/MetaMask/browser-passworder\n */\nexport type ToprfKeyDeriver = {\n /**\n * Derive a key from a seed and salt.\n *\n * @param seed - The seed to derive the key from.\n * @param salt - The salt to derive the key from.\n * @returns The derived key.\n */\n deriveKey: (seed: Uint8Array, salt: Uint8Array) => Promise<Uint8Array>;\n};\n\nexport type RefreshJWTToken = (params: {\n connection: AuthConnection;\n refreshToken: string;\n}) => Promise<{\n idTokens: string[];\n accessToken: string;\n metadataAccessToken: string;\n}>;\n\nexport type RevokeRefreshToken = (params: {\n connection: AuthConnection;\n revokeToken: string;\n}) => Promise<void>;\n\nexport type RenewRefreshToken = (params: {\n connection: AuthConnection;\n revokeToken: string;\n}) => Promise<{\n newRevokeToken: string;\n newRefreshToken: string;\n}>;\n\n/**\n * Seedless Onboarding Controller Options.\n *\n * @param messenger - The messenger to use for this controller.\n * @param state - The initial state to set on this controller.\n * @param encryptor - The encryptor to use for encrypting and decrypting seedless onboarding vault.\n */\nexport type SeedlessOnboardingControllerOptions<\n EncryptionKey,\n SupportedKeyDerivationParams,\n> = {\n messenger: SeedlessOnboardingControllerMessenger;\n\n /**\n * Initial state to set on this controller.\n */\n state?: Partial<SeedlessOnboardingControllerState>;\n\n /**\n * Encryptor to use for encrypting and decrypting seedless onboarding vault.\n *\n * @default browser-passworder @link https://github.com/MetaMask/browser-passworder\n */\n encryptor: VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams>;\n\n /**\n * A function to get a new jwt token using refresh token.\n */\n refreshJWTToken: RefreshJWTToken;\n\n /**\n * A function to revoke the refresh token.\n */\n revokeRefreshToken: RevokeRefreshToken;\n\n /**\n * A function to renew the refresh token and get new revoke token.\n */\n renewRefreshToken: RenewRefreshToken;\n\n /**\n * Optional key derivation interface for the TOPRF client.\n *\n * If provided, it will be used as an additional step during\n * key derivation. This can be used, for example, to inject a slow key\n * derivation step to protect against local brute force attacks on the\n * password.\n *\n * @default browser-passworder @link https://github.com/MetaMask/browser-passworder\n */\n toprfKeyDeriver?: ToprfKeyDeriver;\n\n /**\n * Type of Web3Auth network to be used for the Seedless Onboarding flow.\n *\n * @default Web3AuthNetwork.Mainnet\n */\n network?: Web3AuthNetwork;\n\n /**\n * The TTL of the password outdated cache in milliseconds.\n *\n * @default PASSWORD_OUTDATED_CACHE_TTL_MS\n */\n passwordOutdatedCacheTTL?: number;\n};\n\n/**\n * A function executed within a mutually exclusive lock, with\n * a mutex releaser in its option bag.\n *\n * @param releaseLock - A function to release the lock.\n */\nexport type MutuallyExclusiveCallback<Result> = ({\n releaseLock,\n}: {\n releaseLock: MutexInterface.Releaser;\n}) => Promise<Result>;\n\n/**\n * The structure of the data which is serialized and stored in the vault.\n */\nexport type VaultData = {\n /**\n * The encryption key to encrypt the seed phrase.\n */\n toprfEncryptionKey: string;\n /**\n * The encryption key to encrypt the password.\n */\n toprfPwEncryptionKey: string;\n /**\n * The authentication key pair to authenticate the TOPRF.\n */\n toprfAuthKeyPair: string;\n /**\n * The revoke token to revoke refresh token and get new refresh token and new revoke token.\n * The revoke token may no longer be available after a large number of password changes. In this case, re-authentication is advised.\n */\n revokeToken: string;\n /**\n * The access token used for pairing with profile sync auth service and to access other services.\n */\n accessToken: string;\n};\n\nexport type DeserializedVaultData = Pick<\n VaultData,\n 'accessToken' | 'revokeToken'\n> & {\n toprfEncryptionKey: Uint8Array;\n toprfPwEncryptionKey: Uint8Array;\n toprfAuthKeyPair: KeyPair;\n};\n\nexport type SecretDataType = Uint8Array | string | number;\n\n/**\n * The constructor options for the seed phrase metadata.\n */\nexport type SecretMetadataOptions = {\n /**\n * The timestamp when the seed phrase was created.\n */\n timestamp: number;\n /**\n * The type of the seed phrase.\n */\n type: SecretType;\n /**\n * The version of the seed phrase metadata.\n */\n version: SecretMetadataVersion;\n};\n\nexport type DecodedNodeAuthToken = {\n /**\n * The expiration time of the token in seconds.\n */\n exp: number;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n temp_key_x: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n temp_key_y: string;\n aud: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n verifier_name: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n verifier_id: string;\n scope: string;\n signature: string;\n};\n\nexport type DecodedBaseJWTToken = {\n /**\n * The expiration time of the token in seconds.\n */\n exp: number;\n /**\n * The issued at time of the token in seconds.\n */\n iat: number;\n /**\n * The audience of the token.\n */\n aud: string;\n /**\n * The issuer of the token.\n */\n iss: string;\n /**\n * The subject of the token.\n */\n sub: string;\n};\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
1
2
|
import type { Encryptor } from "@metamask/keyring-controller";
|
|
3
|
+
import type { Messenger } from "@metamask/messenger";
|
|
2
4
|
import type { KeyPair, NodeAuthTokens } from "@metamask/toprf-secure-backup";
|
|
3
5
|
import type { MutexInterface } from "async-mutex";
|
|
4
|
-
import type { AuthConnection, SecretMetadataVersion, SecretType } from "./constants.cjs";
|
|
6
|
+
import type { AuthConnection, controllerName, SecretMetadataVersion, SecretType, Web3AuthNetwork } from "./constants.cjs";
|
|
5
7
|
/**
|
|
6
8
|
* The backup state of the secret data.
|
|
7
9
|
* Each secret data added/restored will be stored in the state locally.
|
|
@@ -145,10 +147,17 @@ export type SeedlessOnboardingControllerState = Partial<AuthenticatedUserDetails
|
|
|
145
147
|
*/
|
|
146
148
|
isSeedlessOnboardingUserAuthenticated: boolean;
|
|
147
149
|
};
|
|
150
|
+
export type SeedlessOnboardingControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SeedlessOnboardingControllerState>;
|
|
151
|
+
export type SeedlessOnboardingControllerActions = SeedlessOnboardingControllerGetStateAction;
|
|
152
|
+
type AllowedActions = never;
|
|
153
|
+
export type SeedlessOnboardingControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SeedlessOnboardingControllerState>;
|
|
154
|
+
export type SeedlessOnboardingControllerEvents = SeedlessOnboardingControllerStateChangeEvent;
|
|
155
|
+
type AllowedEvents = never;
|
|
156
|
+
export type SeedlessOnboardingControllerMessenger = Messenger<typeof controllerName, SeedlessOnboardingControllerActions | AllowedActions, SeedlessOnboardingControllerEvents | AllowedEvents>;
|
|
148
157
|
/**
|
|
149
158
|
* Encryptor interface for encrypting and decrypting seedless onboarding vault.
|
|
150
159
|
*/
|
|
151
|
-
export type VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams> = Encryptor<EncryptionKey, SupportedKeyDerivationParams>;
|
|
160
|
+
export type VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams> = Omit<Encryptor<EncryptionKey, SupportedKeyDerivationParams>, 'encryptWithKey'>;
|
|
152
161
|
/**
|
|
153
162
|
* Additional key deriver for the TOPRF client.
|
|
154
163
|
*
|
|
@@ -187,6 +196,61 @@ export type RenewRefreshToken = (params: {
|
|
|
187
196
|
newRevokeToken: string;
|
|
188
197
|
newRefreshToken: string;
|
|
189
198
|
}>;
|
|
199
|
+
/**
|
|
200
|
+
* Seedless Onboarding Controller Options.
|
|
201
|
+
*
|
|
202
|
+
* @param messenger - The messenger to use for this controller.
|
|
203
|
+
* @param state - The initial state to set on this controller.
|
|
204
|
+
* @param encryptor - The encryptor to use for encrypting and decrypting seedless onboarding vault.
|
|
205
|
+
*/
|
|
206
|
+
export type SeedlessOnboardingControllerOptions<EncryptionKey, SupportedKeyDerivationParams> = {
|
|
207
|
+
messenger: SeedlessOnboardingControllerMessenger;
|
|
208
|
+
/**
|
|
209
|
+
* Initial state to set on this controller.
|
|
210
|
+
*/
|
|
211
|
+
state?: Partial<SeedlessOnboardingControllerState>;
|
|
212
|
+
/**
|
|
213
|
+
* Encryptor to use for encrypting and decrypting seedless onboarding vault.
|
|
214
|
+
*
|
|
215
|
+
* @default browser-passworder @link https://github.com/MetaMask/browser-passworder
|
|
216
|
+
*/
|
|
217
|
+
encryptor: VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams>;
|
|
218
|
+
/**
|
|
219
|
+
* A function to get a new jwt token using refresh token.
|
|
220
|
+
*/
|
|
221
|
+
refreshJWTToken: RefreshJWTToken;
|
|
222
|
+
/**
|
|
223
|
+
* A function to revoke the refresh token.
|
|
224
|
+
*/
|
|
225
|
+
revokeRefreshToken: RevokeRefreshToken;
|
|
226
|
+
/**
|
|
227
|
+
* A function to renew the refresh token and get new revoke token.
|
|
228
|
+
*/
|
|
229
|
+
renewRefreshToken: RenewRefreshToken;
|
|
230
|
+
/**
|
|
231
|
+
* Optional key derivation interface for the TOPRF client.
|
|
232
|
+
*
|
|
233
|
+
* If provided, it will be used as an additional step during
|
|
234
|
+
* key derivation. This can be used, for example, to inject a slow key
|
|
235
|
+
* derivation step to protect against local brute force attacks on the
|
|
236
|
+
* password.
|
|
237
|
+
*
|
|
238
|
+
* @default browser-passworder @link https://github.com/MetaMask/browser-passworder
|
|
239
|
+
*/
|
|
240
|
+
toprfKeyDeriver?: ToprfKeyDeriver;
|
|
241
|
+
/**
|
|
242
|
+
* Type of Web3Auth network to be used for the Seedless Onboarding flow.
|
|
243
|
+
*
|
|
244
|
+
* @default Web3AuthNetwork.Mainnet
|
|
245
|
+
*/
|
|
246
|
+
network?: Web3AuthNetwork;
|
|
247
|
+
/**
|
|
248
|
+
* The TTL of the password outdated cache in milliseconds.
|
|
249
|
+
*
|
|
250
|
+
* @default PASSWORD_OUTDATED_CACHE_TTL_MS
|
|
251
|
+
*/
|
|
252
|
+
passwordOutdatedCacheTTL?: number;
|
|
253
|
+
};
|
|
190
254
|
/**
|
|
191
255
|
* A function executed within a mutually exclusive lock, with
|
|
192
256
|
* a mutex releaser in its option bag.
|
|
@@ -280,4 +344,5 @@ export type DecodedBaseJWTToken = {
|
|
|
280
344
|
*/
|
|
281
345
|
sub: string;
|
|
282
346
|
};
|
|
347
|
+
export {};
|
|
283
348
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,qCAAqC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,sCAAsC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB;AAElD,OAAO,KAAK,EACV,cAAc,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B;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,qBAAqB,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ,UAAU,EAAE,MAAM,CAAC;IAEnB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IAEZ,aAAa,EAAE,MAAM,CAAC;IAEtB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
1
2
|
import type { Encryptor } from "@metamask/keyring-controller";
|
|
3
|
+
import type { Messenger } from "@metamask/messenger";
|
|
2
4
|
import type { KeyPair, NodeAuthTokens } from "@metamask/toprf-secure-backup";
|
|
3
5
|
import type { MutexInterface } from "async-mutex";
|
|
4
|
-
import type { AuthConnection, SecretMetadataVersion, SecretType } from "./constants.mjs";
|
|
6
|
+
import type { AuthConnection, controllerName, SecretMetadataVersion, SecretType, Web3AuthNetwork } from "./constants.mjs";
|
|
5
7
|
/**
|
|
6
8
|
* The backup state of the secret data.
|
|
7
9
|
* Each secret data added/restored will be stored in the state locally.
|
|
@@ -145,10 +147,17 @@ export type SeedlessOnboardingControllerState = Partial<AuthenticatedUserDetails
|
|
|
145
147
|
*/
|
|
146
148
|
isSeedlessOnboardingUserAuthenticated: boolean;
|
|
147
149
|
};
|
|
150
|
+
export type SeedlessOnboardingControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SeedlessOnboardingControllerState>;
|
|
151
|
+
export type SeedlessOnboardingControllerActions = SeedlessOnboardingControllerGetStateAction;
|
|
152
|
+
type AllowedActions = never;
|
|
153
|
+
export type SeedlessOnboardingControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SeedlessOnboardingControllerState>;
|
|
154
|
+
export type SeedlessOnboardingControllerEvents = SeedlessOnboardingControllerStateChangeEvent;
|
|
155
|
+
type AllowedEvents = never;
|
|
156
|
+
export type SeedlessOnboardingControllerMessenger = Messenger<typeof controllerName, SeedlessOnboardingControllerActions | AllowedActions, SeedlessOnboardingControllerEvents | AllowedEvents>;
|
|
148
157
|
/**
|
|
149
158
|
* Encryptor interface for encrypting and decrypting seedless onboarding vault.
|
|
150
159
|
*/
|
|
151
|
-
export type VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams> = Encryptor<EncryptionKey, SupportedKeyDerivationParams>;
|
|
160
|
+
export type VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams> = Omit<Encryptor<EncryptionKey, SupportedKeyDerivationParams>, 'encryptWithKey'>;
|
|
152
161
|
/**
|
|
153
162
|
* Additional key deriver for the TOPRF client.
|
|
154
163
|
*
|
|
@@ -187,6 +196,61 @@ export type RenewRefreshToken = (params: {
|
|
|
187
196
|
newRevokeToken: string;
|
|
188
197
|
newRefreshToken: string;
|
|
189
198
|
}>;
|
|
199
|
+
/**
|
|
200
|
+
* Seedless Onboarding Controller Options.
|
|
201
|
+
*
|
|
202
|
+
* @param messenger - The messenger to use for this controller.
|
|
203
|
+
* @param state - The initial state to set on this controller.
|
|
204
|
+
* @param encryptor - The encryptor to use for encrypting and decrypting seedless onboarding vault.
|
|
205
|
+
*/
|
|
206
|
+
export type SeedlessOnboardingControllerOptions<EncryptionKey, SupportedKeyDerivationParams> = {
|
|
207
|
+
messenger: SeedlessOnboardingControllerMessenger;
|
|
208
|
+
/**
|
|
209
|
+
* Initial state to set on this controller.
|
|
210
|
+
*/
|
|
211
|
+
state?: Partial<SeedlessOnboardingControllerState>;
|
|
212
|
+
/**
|
|
213
|
+
* Encryptor to use for encrypting and decrypting seedless onboarding vault.
|
|
214
|
+
*
|
|
215
|
+
* @default browser-passworder @link https://github.com/MetaMask/browser-passworder
|
|
216
|
+
*/
|
|
217
|
+
encryptor: VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams>;
|
|
218
|
+
/**
|
|
219
|
+
* A function to get a new jwt token using refresh token.
|
|
220
|
+
*/
|
|
221
|
+
refreshJWTToken: RefreshJWTToken;
|
|
222
|
+
/**
|
|
223
|
+
* A function to revoke the refresh token.
|
|
224
|
+
*/
|
|
225
|
+
revokeRefreshToken: RevokeRefreshToken;
|
|
226
|
+
/**
|
|
227
|
+
* A function to renew the refresh token and get new revoke token.
|
|
228
|
+
*/
|
|
229
|
+
renewRefreshToken: RenewRefreshToken;
|
|
230
|
+
/**
|
|
231
|
+
* Optional key derivation interface for the TOPRF client.
|
|
232
|
+
*
|
|
233
|
+
* If provided, it will be used as an additional step during
|
|
234
|
+
* key derivation. This can be used, for example, to inject a slow key
|
|
235
|
+
* derivation step to protect against local brute force attacks on the
|
|
236
|
+
* password.
|
|
237
|
+
*
|
|
238
|
+
* @default browser-passworder @link https://github.com/MetaMask/browser-passworder
|
|
239
|
+
*/
|
|
240
|
+
toprfKeyDeriver?: ToprfKeyDeriver;
|
|
241
|
+
/**
|
|
242
|
+
* Type of Web3Auth network to be used for the Seedless Onboarding flow.
|
|
243
|
+
*
|
|
244
|
+
* @default Web3AuthNetwork.Mainnet
|
|
245
|
+
*/
|
|
246
|
+
network?: Web3AuthNetwork;
|
|
247
|
+
/**
|
|
248
|
+
* The TTL of the password outdated cache in milliseconds.
|
|
249
|
+
*
|
|
250
|
+
* @default PASSWORD_OUTDATED_CACHE_TTL_MS
|
|
251
|
+
*/
|
|
252
|
+
passwordOutdatedCacheTTL?: number;
|
|
253
|
+
};
|
|
190
254
|
/**
|
|
191
255
|
* A function executed within a mutually exclusive lock, with
|
|
192
256
|
* a mutex releaser in its option bag.
|
|
@@ -280,4 +344,5 @@ export type DecodedBaseJWTToken = {
|
|
|
280
344
|
*/
|
|
281
345
|
sub: string;
|
|
282
346
|
};
|
|
347
|
+
export {};
|
|
283
348
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,qCAAqC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,sCAAsC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB;AAElD,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACrB,UAAU,
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,qCAAqC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,sCAAsC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB;AAElD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,UAAU,EACV,eAAe,EAChB,wBAAoB;AAErB;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC;IAEjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,wBAAw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mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Encryptor } from '@metamask/keyring-controller';\nimport type { KeyPair, NodeAuthTokens } from '@metamask/toprf-secure-backup';\nimport type { MutexInterface } from 'async-mutex';\n\nimport type {\n AuthConnection,\n SecretMetadataVersion,\n SecretType,\n} from './constants';\n\n/**\n * The backup state of the secret data.\n * Each secret data added/restored will be stored in the state locally.\n *\n * This is used to track the backup status of the secret data.\n */\nexport type SocialBackupsMetadata = {\n /**\n * The hash of the secret data.\n */\n hash: string;\n\n /**\n * The type of the secret data.\n */\n type: SecretType;\n\n /**\n * The optional keyringId to identify the keyring that the secret data belongs to.\n *\n * This is only required for `Mnemonic` secret data.\n */\n keyringId?: string;\n};\n\nexport type AuthenticatedUserDetails = {\n /**\n * Type of social login provider.\n */\n authConnection: AuthConnection;\n\n /**\n * The node auth tokens from OAuth User authentication after the Social login.\n *\n * This values are used to authenticate users when they go through the Seedless Onboarding flow.\n */\n nodeAuthTokens: NodeAuthTokens;\n\n /**\n * OAuth connection id from web3auth dashboard.\n */\n authConnectionId: string;\n\n /**\n * The optional grouped authConnectionId to authenticate the user with Web3Auth network.\n */\n groupedAuthConnectionId?: string;\n\n /**\n * The user email or ID from Social login.\n */\n userId: string;\n\n /**\n * The user email from Social login.\n */\n socialLoginEmail: string;\n\n /**\n * The refresh token used to refresh expired nodeAuthTokens.\n */\n refreshToken: string;\n};\n\nexport type SRPBackedUpUserDetails = {\n /**\n * The public key of the authentication key pair in base64 format.\n *\n * This value is used to check if the password is outdated compare to the global password and find backed up old password.\n */\n authPubKey: string;\n};\n\n/**\n * The data of the recovery error.\n */\nexport type RecoveryErrorData = {\n /**\n * The remaining time in seconds before the user can try again.\n */\n remainingTime: number;\n\n /**\n * The number of attempts made by the user.\n */\n numberOfAttempts: number;\n};\n\n// State\nexport type SeedlessOnboardingControllerState =\n Partial<AuthenticatedUserDetails> &\n Partial<SRPBackedUpUserDetails> & {\n /**\n * Encrypted array of serialized keyrings data.\n */\n vault?: string;\n\n /**\n * The hashes of the seed phrase backups.\n *\n * This is to facilitate the UI to display backup status of the seed phrases.\n */\n socialBackupsMetadata: SocialBackupsMetadata[];\n\n /**\n * The encryption key derived from the password and used to encrypt\n * the vault.\n */\n vaultEncryptionKey?: string;\n\n /**\n * The salt used to derive the encryption key from the password.\n */\n vaultEncryptionSalt?: string;\n\n /**\n * Cache for checkIsPasswordOutdated result and timestamp.\n */\n passwordOutdatedCache?: { isExpiredPwd: boolean; timestamp: number };\n\n /**\n * The refresh token used to refresh expired nodeAuthTokens.\n * This is persisted in state.\n */\n refreshToken?: string;\n\n /**\n * The revoke token used to revoke refresh token and get new refresh token and new revoke token.\n * This is temporarily stored in state during authentication and then persisted in the vault.\n */\n revokeToken?: string;\n\n /**\n * The refresh token and revoke token to be revoked.\n * This is persisted in state to revoke old refresh token when possible.\n */\n pendingToBeRevokedTokens?: {\n refreshToken: string;\n revokeToken: string;\n }[];\n\n /**\n * The encrypted seedless encryption key used to encrypt the seedless vault.\n */\n encryptedSeedlessEncryptionKey?: string;\n\n /**\n * The encrypted keyring encryption key used to encrypt the keyring vault.\n */\n encryptedKeyringEncryptionKey?: string;\n\n /**\n * The access token used for pairing with profile sync auth service and to access other services.\n */\n accessToken?: string;\n\n /**\n * The metadata access token used to access the metadata service.\n *\n * This token is used to access the metadata service before the vault is created or unlocked.\n */\n metadataAccessToken?: string;\n\n /**\n * Whether the user is authenticated with social login and TOPRF service.\n */\n isSeedlessOnboardingUserAuthenticated: boolean;\n };\n\n/**\n * Encryptor interface for encrypting and decrypting seedless onboarding vault.\n */\nexport type VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams> =\n Encryptor<EncryptionKey, SupportedKeyDerivationParams>;\n\n/**\n * Additional key deriver for the TOPRF client.\n *\n * This is a function that takes a seed and salt and returns a key in bytes (Uint8Array).\n * It is used as an additional step during key derivation. This can be used, for example, to inject a slow key\n * derivation step to protect against local brute force attacks on the password.\n *\n * @default browser-passworder @link https://github.com/MetaMask/browser-passworder\n */\nexport type ToprfKeyDeriver = {\n /**\n * Derive a key from a seed and salt.\n *\n * @param seed - The seed to derive the key from.\n * @param salt - The salt to derive the key from.\n * @returns The derived key.\n */\n deriveKey: (seed: Uint8Array, salt: Uint8Array) => Promise<Uint8Array>;\n};\n\nexport type RefreshJWTToken = (params: {\n connection: AuthConnection;\n refreshToken: string;\n}) => Promise<{\n idTokens: string[];\n accessToken: string;\n metadataAccessToken: string;\n}>;\n\nexport type RevokeRefreshToken = (params: {\n connection: AuthConnection;\n revokeToken: string;\n}) => Promise<void>;\n\nexport type RenewRefreshToken = (params: {\n connection: AuthConnection;\n revokeToken: string;\n}) => Promise<{\n newRevokeToken: string;\n newRefreshToken: string;\n}>;\n\n/**\n * A function executed within a mutually exclusive lock, with\n * a mutex releaser in its option bag.\n *\n * @param releaseLock - A function to release the lock.\n */\nexport type MutuallyExclusiveCallback<Result> = ({\n releaseLock,\n}: {\n releaseLock: MutexInterface.Releaser;\n}) => Promise<Result>;\n\n/**\n * The structure of the data which is serialized and stored in the vault.\n */\nexport type VaultData = {\n /**\n * The encryption key to encrypt the seed phrase.\n */\n toprfEncryptionKey: string;\n /**\n * The encryption key to encrypt the password.\n */\n toprfPwEncryptionKey: string;\n /**\n * The authentication key pair to authenticate the TOPRF.\n */\n toprfAuthKeyPair: string;\n /**\n * The revoke token to revoke refresh token and get new refresh token and new revoke token.\n * The revoke token may no longer be available after a large number of password changes. In this case, re-authentication is advised.\n */\n revokeToken: string;\n /**\n * The access token used for pairing with profile sync auth service and to access other services.\n */\n accessToken: string;\n};\n\nexport type DeserializedVaultData = Pick<\n VaultData,\n 'accessToken' | 'revokeToken'\n> & {\n toprfEncryptionKey: Uint8Array;\n toprfPwEncryptionKey: Uint8Array;\n toprfAuthKeyPair: KeyPair;\n};\n\nexport type SecretDataType = Uint8Array | string | number;\n\n/**\n * The constructor options for the seed phrase metadata.\n */\nexport type SecretMetadataOptions = {\n /**\n * The timestamp when the seed phrase was created.\n */\n timestamp: number;\n /**\n * The type of the seed phrase.\n */\n type: SecretType;\n /**\n * The version of the seed phrase metadata.\n */\n version: SecretMetadataVersion;\n};\n\nexport type DecodedNodeAuthToken = {\n /**\n * The expiration time of the token in seconds.\n */\n exp: number;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n temp_key_x: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n temp_key_y: string;\n aud: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n verifier_name: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n verifier_id: string;\n scope: string;\n signature: string;\n};\n\nexport type DecodedBaseJWTToken = {\n /**\n * The expiration time of the token in seconds.\n */\n exp: number;\n /**\n * The issued at time of the token in seconds.\n */\n iat: number;\n /**\n * The audience of the token.\n */\n aud: string;\n /**\n * The issuer of the token.\n */\n iss: string;\n /**\n * The subject of the token.\n */\n sub: string;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Encryptor } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { KeyPair, NodeAuthTokens } from '@metamask/toprf-secure-backup';\nimport type { MutexInterface } from 'async-mutex';\n\nimport type {\n AuthConnection,\n controllerName,\n SecretMetadataVersion,\n SecretType,\n Web3AuthNetwork,\n} from './constants';\n\n/**\n * The backup state of the secret data.\n * Each secret data added/restored will be stored in the state locally.\n *\n * This is used to track the backup status of the secret data.\n */\nexport type SocialBackupsMetadata = {\n /**\n * The hash of the secret data.\n */\n hash: string;\n\n /**\n * The type of the secret data.\n */\n type: SecretType;\n\n /**\n * The optional keyringId to identify the keyring that the secret data belongs to.\n *\n * This is only required for `Mnemonic` secret data.\n */\n keyringId?: string;\n};\n\nexport type AuthenticatedUserDetails = {\n /**\n * Type of social login provider.\n */\n authConnection: AuthConnection;\n\n /**\n * The node auth tokens from OAuth User authentication after the Social login.\n *\n * This values are used to authenticate users when they go through the Seedless Onboarding flow.\n */\n nodeAuthTokens: NodeAuthTokens;\n\n /**\n * OAuth connection id from web3auth dashboard.\n */\n authConnectionId: string;\n\n /**\n * The optional grouped authConnectionId to authenticate the user with Web3Auth network.\n */\n groupedAuthConnectionId?: string;\n\n /**\n * The user email or ID from Social login.\n */\n userId: string;\n\n /**\n * The user email from Social login.\n */\n socialLoginEmail: string;\n\n /**\n * The refresh token used to refresh expired nodeAuthTokens.\n */\n refreshToken: string;\n};\n\nexport type SRPBackedUpUserDetails = {\n /**\n * The public key of the authentication key pair in base64 format.\n *\n * This value is used to check if the password is outdated compare to the global password and find backed up old password.\n */\n authPubKey: string;\n};\n\n/**\n * The data of the recovery error.\n */\nexport type RecoveryErrorData = {\n /**\n * The remaining time in seconds before the user can try again.\n */\n remainingTime: number;\n\n /**\n * The number of attempts made by the user.\n */\n numberOfAttempts: number;\n};\n\n// State\nexport type SeedlessOnboardingControllerState =\n Partial<AuthenticatedUserDetails> &\n Partial<SRPBackedUpUserDetails> & {\n /**\n * Encrypted array of serialized keyrings data.\n */\n vault?: string;\n\n /**\n * The hashes of the seed phrase backups.\n *\n * This is to facilitate the UI to display backup status of the seed phrases.\n */\n socialBackupsMetadata: SocialBackupsMetadata[];\n\n /**\n * The encryption key derived from the password and used to encrypt\n * the vault.\n */\n vaultEncryptionKey?: string;\n\n /**\n * The salt used to derive the encryption key from the password.\n */\n vaultEncryptionSalt?: string;\n\n /**\n * Cache for checkIsPasswordOutdated result and timestamp.\n */\n passwordOutdatedCache?: { isExpiredPwd: boolean; timestamp: number };\n\n /**\n * The refresh token used to refresh expired nodeAuthTokens.\n * This is persisted in state.\n */\n refreshToken?: string;\n\n /**\n * The revoke token used to revoke refresh token and get new refresh token and new revoke token.\n * This is temporarily stored in state during authentication and then persisted in the vault.\n */\n revokeToken?: string;\n\n /**\n * The refresh token and revoke token to be revoked.\n * This is persisted in state to revoke old refresh token when possible.\n */\n pendingToBeRevokedTokens?: {\n refreshToken: string;\n revokeToken: string;\n }[];\n\n /**\n * The encrypted seedless encryption key used to encrypt the seedless vault.\n */\n encryptedSeedlessEncryptionKey?: string;\n\n /**\n * The encrypted keyring encryption key used to encrypt the keyring vault.\n */\n encryptedKeyringEncryptionKey?: string;\n\n /**\n * The access token used for pairing with profile sync auth service and to access other services.\n */\n accessToken?: string;\n\n /**\n * The metadata access token used to access the metadata service.\n *\n * This token is used to access the metadata service before the vault is created or unlocked.\n */\n metadataAccessToken?: string;\n\n /**\n * Whether the user is authenticated with social login and TOPRF service.\n */\n isSeedlessOnboardingUserAuthenticated: boolean;\n };\n\n// Actions\nexport type SeedlessOnboardingControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n SeedlessOnboardingControllerState\n >;\nexport type SeedlessOnboardingControllerActions =\n SeedlessOnboardingControllerGetStateAction;\n\ntype AllowedActions = never;\n\n// Events\nexport type SeedlessOnboardingControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n SeedlessOnboardingControllerState\n >;\nexport type SeedlessOnboardingControllerEvents =\n SeedlessOnboardingControllerStateChangeEvent;\n\ntype AllowedEvents = never;\n\n// Messenger\nexport type SeedlessOnboardingControllerMessenger = Messenger<\n typeof controllerName,\n SeedlessOnboardingControllerActions | AllowedActions,\n SeedlessOnboardingControllerEvents | AllowedEvents\n>;\n\n/**\n * Encryptor interface for encrypting and decrypting seedless onboarding vault.\n */\nexport type VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams> = Omit<\n Encryptor<EncryptionKey, SupportedKeyDerivationParams>,\n 'encryptWithKey'\n>;\n\n/**\n * Additional key deriver for the TOPRF client.\n *\n * This is a function that takes a seed and salt and returns a key in bytes (Uint8Array).\n * It is used as an additional step during key derivation. This can be used, for example, to inject a slow key\n * derivation step to protect against local brute force attacks on the password.\n *\n * @default browser-passworder @link https://github.com/MetaMask/browser-passworder\n */\nexport type ToprfKeyDeriver = {\n /**\n * Derive a key from a seed and salt.\n *\n * @param seed - The seed to derive the key from.\n * @param salt - The salt to derive the key from.\n * @returns The derived key.\n */\n deriveKey: (seed: Uint8Array, salt: Uint8Array) => Promise<Uint8Array>;\n};\n\nexport type RefreshJWTToken = (params: {\n connection: AuthConnection;\n refreshToken: string;\n}) => Promise<{\n idTokens: string[];\n accessToken: string;\n metadataAccessToken: string;\n}>;\n\nexport type RevokeRefreshToken = (params: {\n connection: AuthConnection;\n revokeToken: string;\n}) => Promise<void>;\n\nexport type RenewRefreshToken = (params: {\n connection: AuthConnection;\n revokeToken: string;\n}) => Promise<{\n newRevokeToken: string;\n newRefreshToken: string;\n}>;\n\n/**\n * Seedless Onboarding Controller Options.\n *\n * @param messenger - The messenger to use for this controller.\n * @param state - The initial state to set on this controller.\n * @param encryptor - The encryptor to use for encrypting and decrypting seedless onboarding vault.\n */\nexport type SeedlessOnboardingControllerOptions<\n EncryptionKey,\n SupportedKeyDerivationParams,\n> = {\n messenger: SeedlessOnboardingControllerMessenger;\n\n /**\n * Initial state to set on this controller.\n */\n state?: Partial<SeedlessOnboardingControllerState>;\n\n /**\n * Encryptor to use for encrypting and decrypting seedless onboarding vault.\n *\n * @default browser-passworder @link https://github.com/MetaMask/browser-passworder\n */\n encryptor: VaultEncryptor<EncryptionKey, SupportedKeyDerivationParams>;\n\n /**\n * A function to get a new jwt token using refresh token.\n */\n refreshJWTToken: RefreshJWTToken;\n\n /**\n * A function to revoke the refresh token.\n */\n revokeRefreshToken: RevokeRefreshToken;\n\n /**\n * A function to renew the refresh token and get new revoke token.\n */\n renewRefreshToken: RenewRefreshToken;\n\n /**\n * Optional key derivation interface for the TOPRF client.\n *\n * If provided, it will be used as an additional step during\n * key derivation. This can be used, for example, to inject a slow key\n * derivation step to protect against local brute force attacks on the\n * password.\n *\n * @default browser-passworder @link https://github.com/MetaMask/browser-passworder\n */\n toprfKeyDeriver?: ToprfKeyDeriver;\n\n /**\n * Type of Web3Auth network to be used for the Seedless Onboarding flow.\n *\n * @default Web3AuthNetwork.Mainnet\n */\n network?: Web3AuthNetwork;\n\n /**\n * The TTL of the password outdated cache in milliseconds.\n *\n * @default PASSWORD_OUTDATED_CACHE_TTL_MS\n */\n passwordOutdatedCacheTTL?: number;\n};\n\n/**\n * A function executed within a mutually exclusive lock, with\n * a mutex releaser in its option bag.\n *\n * @param releaseLock - A function to release the lock.\n */\nexport type MutuallyExclusiveCallback<Result> = ({\n releaseLock,\n}: {\n releaseLock: MutexInterface.Releaser;\n}) => Promise<Result>;\n\n/**\n * The structure of the data which is serialized and stored in the vault.\n */\nexport type VaultData = {\n /**\n * The encryption key to encrypt the seed phrase.\n */\n toprfEncryptionKey: string;\n /**\n * The encryption key to encrypt the password.\n */\n toprfPwEncryptionKey: string;\n /**\n * The authentication key pair to authenticate the TOPRF.\n */\n toprfAuthKeyPair: string;\n /**\n * The revoke token to revoke refresh token and get new refresh token and new revoke token.\n * The revoke token may no longer be available after a large number of password changes. In this case, re-authentication is advised.\n */\n revokeToken: string;\n /**\n * The access token used for pairing with profile sync auth service and to access other services.\n */\n accessToken: string;\n};\n\nexport type DeserializedVaultData = Pick<\n VaultData,\n 'accessToken' | 'revokeToken'\n> & {\n toprfEncryptionKey: Uint8Array;\n toprfPwEncryptionKey: Uint8Array;\n toprfAuthKeyPair: KeyPair;\n};\n\nexport type SecretDataType = Uint8Array | string | number;\n\n/**\n * The constructor options for the seed phrase metadata.\n */\nexport type SecretMetadataOptions = {\n /**\n * The timestamp when the seed phrase was created.\n */\n timestamp: number;\n /**\n * The type of the seed phrase.\n */\n type: SecretType;\n /**\n * The version of the seed phrase metadata.\n */\n version: SecretMetadataVersion;\n};\n\nexport type DecodedNodeAuthToken = {\n /**\n * The expiration time of the token in seconds.\n */\n exp: number;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n temp_key_x: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n temp_key_y: string;\n aud: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n verifier_name: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention -- to match with the actual token\n verifier_id: string;\n scope: string;\n signature: string;\n};\n\nexport type DecodedBaseJWTToken = {\n /**\n * The expiration time of the token in seconds.\n */\n exp: number;\n /**\n * The issued at time of the token in seconds.\n */\n iat: number;\n /**\n * The audience of the token.\n */\n aud: string;\n /**\n * The issuer of the token.\n */\n iss: string;\n /**\n * The subject of the token.\n */\n sub: string;\n};\n"]}
|
package/dist/utils.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.deserializeAuthKeyPair = exports.serializeToprfAuthKeyPair = exports.deserializeVaultData = exports.serializeVaultData = exports.decodeJWTToken = exports.decodeNodeAuthToken = void 0;
|
|
4
4
|
const utils_1 = require("@metamask/utils");
|
|
5
5
|
const utils_2 = require("@noble/ciphers/utils");
|
|
6
6
|
/**
|
|
@@ -98,34 +98,4 @@ function deserializeAuthKeyPair(value) {
|
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
exports.deserializeAuthKeyPair = deserializeAuthKeyPair;
|
|
101
|
-
/**
|
|
102
|
-
* Compare two JWT tokens and return the latest token.
|
|
103
|
-
*
|
|
104
|
-
* @param jwtToken1 - The first JWT token to compare.
|
|
105
|
-
* @param jwtToken2 - The second JWT token to compare.
|
|
106
|
-
* @returns The latest JWT token.
|
|
107
|
-
*/
|
|
108
|
-
function compareAndGetLatestToken(jwtToken1, jwtToken2) {
|
|
109
|
-
let decodedToken1;
|
|
110
|
-
let decodedToken2;
|
|
111
|
-
try {
|
|
112
|
-
decodedToken1 = decodeJWTToken(jwtToken1);
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
// if the first token is invalid, return the second token
|
|
116
|
-
return jwtToken2;
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
decodedToken2 = decodeJWTToken(jwtToken2);
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
// if the second token is invalid, return the first token
|
|
123
|
-
return jwtToken1;
|
|
124
|
-
}
|
|
125
|
-
if (decodedToken1.exp > decodedToken2.exp) {
|
|
126
|
-
return jwtToken1;
|
|
127
|
-
}
|
|
128
|
-
return jwtToken2;
|
|
129
|
-
}
|
|
130
|
-
exports.compareAndGetLatestToken = compareAndGetLatestToken;
|
|
131
101
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,2CAKyB;AACzB,gDAAmD;AASnD;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAAa;IAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,mBAAW,EAAC,IAAA,qBAAa,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAFD,kDAEC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAa;IAC1C,sEAAsE;IACtE,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC9C,CAAC;IAED,mCAAmC;IACnC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACzB,4CAA4C;IAC5C,MAAM,aAAa,GAAG,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAA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EH,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAPD,8DAOC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,KAAa;IAClD,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO;QACL,EAAE,EAAE,IAAA,mBAAW,EAAC,aAAa,CAAC,EAAE,CAAC;QACjC,EAAE,EAAE,IAAA,qBAAa,EAAC,aAAa,CAAC,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC;AAND,wDAMC","sourcesContent":["import type { KeyPair } from '@metamask/toprf-secure-backup';\nimport {\n base64ToBytes,\n bigIntToHex,\n bytesToBase64,\n hexToBigInt,\n} from '@metamask/utils';\nimport { bytesToUtf8 } from '@noble/ciphers/utils';\n\nimport type {\n DecodedBaseJWTToken,\n DecodedNodeAuthToken,\n DeserializedVaultData,\n VaultData,\n} from './types';\n\n/**\n * Decode the node auth token from base64 to json object.\n *\n * @param token - The node auth token to decode.\n * @returns The decoded node auth token.\n */\nexport function decodeNodeAuthToken(token: string): DecodedNodeAuthToken {\n return JSON.parse(bytesToUtf8(base64ToBytes(token)));\n}\n\n/**\n * Decode JWT token\n *\n * @param token - The JWT token to decode.\n * @returns The decoded JWT token.\n */\nexport function decodeJWTToken(token: string): DecodedBaseJWTToken {\n // JWT tokens have 3 parts separated by dots: header.payload.signature\n const parts = token.split('.');\n if (parts.length !== 3) {\n throw new Error('Invalid JWT token format');\n }\n\n // Decode the payload (second part)\n const payload = parts[1];\n // Add padding if needed for base64 decoding\n const paddedPayload = payload + '='.repeat((4 - (payload.length % 4)) % 4);\n const decoded = JSON.parse(bytesToUtf8(base64ToBytes(paddedPayload)));\n return decoded as DecodedBaseJWTToken;\n}\n\n/**\n * Serialize the vault data.\n *\n * @param data - The vault data to serialize.\n * @returns The serialized vault data.\n */\nexport function serializeVaultData(data: DeserializedVaultData): string {\n const toprfEncryptionKey = bytesToBase64(data.toprfEncryptionKey);\n const toprfPwEncryptionKey = bytesToBase64(data.toprfPwEncryptionKey);\n const toprfAuthKeyPair = serializeToprfAuthKeyPair(data.toprfAuthKeyPair);\n\n return JSON.stringify({\n toprfEncryptionKey,\n toprfPwEncryptionKey,\n toprfAuthKeyPair,\n revokeToken: data.revokeToken,\n accessToken: data.accessToken,\n });\n}\n\n/**\n * Deserialize the vault data.\n *\n * @param value - The stringified vault data.\n * @returns The deserialized vault data.\n */\nexport function deserializeVaultData(value: VaultData): DeserializedVaultData {\n const toprfEncryptionKey = base64ToBytes(value.toprfEncryptionKey);\n const toprfPwEncryptionKey = base64ToBytes(value.toprfPwEncryptionKey);\n const toprfAuthKeyPair = deserializeAuthKeyPair(value.toprfAuthKeyPair);\n\n return {\n ...value,\n toprfEncryptionKey,\n toprfPwEncryptionKey,\n toprfAuthKeyPair,\n };\n}\n\n/**\n * Serialize TOPRF authentication key pair.\n *\n * @param keyPair - The authentication key pair to serialize.\n * @returns The serialized authentication key pair.\n */\nexport function serializeToprfAuthKeyPair(keyPair: KeyPair): string {\n const b64EncodedAuthKeyPair = JSON.stringify({\n sk: bigIntToHex(keyPair.sk), // Convert BigInt to hex string\n pk: bytesToBase64(keyPair.pk),\n });\n\n return b64EncodedAuthKeyPair;\n}\n\n/**\n * Deserialize the authentication key pair.\n *\n * @param value - The stringified authentication key pair.\n * @returns The deserialized authentication key pair.\n */\nexport function deserializeAuthKeyPair(value: string): KeyPair {\n const parsedKeyPair = JSON.parse(value);\n return {\n sk: hexToBigInt(parsedKeyPair.sk),\n pk: base64ToBytes(parsedKeyPair.pk),\n };\n}\n"]}
|
package/dist/utils.d.cts
CHANGED
|
@@ -42,12 +42,4 @@ export declare function serializeToprfAuthKeyPair(keyPair: KeyPair): string;
|
|
|
42
42
|
* @returns The deserialized authentication key pair.
|
|
43
43
|
*/
|
|
44
44
|
export declare function deserializeAuthKeyPair(value: string): KeyPair;
|
|
45
|
-
/**
|
|
46
|
-
* Compare two JWT tokens and return the latest token.
|
|
47
|
-
*
|
|
48
|
-
* @param jwtToken1 - The first JWT token to compare.
|
|
49
|
-
* @param jwtToken2 - The second JWT token to compare.
|
|
50
|
-
* @returns The latest JWT token.
|
|
51
|
-
*/
|
|
52
|
-
export declare function compareAndGetLatestToken(jwtToken1: string, jwtToken2: string): string;
|
|
53
45
|
//# sourceMappingURL=utils.d.cts.map
|
package/dist/utils.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,sCAAsC;AAS7D,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACV,oBAAgB;AAEjB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,CAEvE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAajE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,CAYtE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,GAAG,qBAAqB,CAW5E;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAOlE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAM7D
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,sCAAsC;AAS7D,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACV,oBAAgB;AAEjB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,CAEvE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAajE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,CAYtE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,GAAG,qBAAqB,CAW5E;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAOlE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAM7D"}
|
package/dist/utils.d.mts
CHANGED
|
@@ -42,12 +42,4 @@ export declare function serializeToprfAuthKeyPair(keyPair: KeyPair): string;
|
|
|
42
42
|
* @returns The deserialized authentication key pair.
|
|
43
43
|
*/
|
|
44
44
|
export declare function deserializeAuthKeyPair(value: string): KeyPair;
|
|
45
|
-
/**
|
|
46
|
-
* Compare two JWT tokens and return the latest token.
|
|
47
|
-
*
|
|
48
|
-
* @param jwtToken1 - The first JWT token to compare.
|
|
49
|
-
* @param jwtToken2 - The second JWT token to compare.
|
|
50
|
-
* @returns The latest JWT token.
|
|
51
|
-
*/
|
|
52
|
-
export declare function compareAndGetLatestToken(jwtToken1: string, jwtToken2: string): string;
|
|
53
45
|
//# sourceMappingURL=utils.d.mts.map
|
package/dist/utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,sCAAsC;AAS7D,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACV,oBAAgB;AAEjB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,CAEvE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAajE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,CAYtE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,GAAG,qBAAqB,CAW5E;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAOlE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAM7D
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,sCAAsC;AAS7D,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACV,oBAAgB;AAEjB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,CAEvE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAajE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,CAYtE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,GAAG,qBAAqB,CAW5E;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAOlE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAM7D"}
|
package/dist/utils.mjs
CHANGED
|
@@ -89,33 +89,4 @@ export function deserializeAuthKeyPair(value) {
|
|
|
89
89
|
pk: base64ToBytes(parsedKeyPair.pk),
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Compare two JWT tokens and return the latest token.
|
|
94
|
-
*
|
|
95
|
-
* @param jwtToken1 - The first JWT token to compare.
|
|
96
|
-
* @param jwtToken2 - The second JWT token to compare.
|
|
97
|
-
* @returns The latest JWT token.
|
|
98
|
-
*/
|
|
99
|
-
export function compareAndGetLatestToken(jwtToken1, jwtToken2) {
|
|
100
|
-
let decodedToken1;
|
|
101
|
-
let decodedToken2;
|
|
102
|
-
try {
|
|
103
|
-
decodedToken1 = decodeJWTToken(jwtToken1);
|
|
104
|
-
}
|
|
105
|
-
catch {
|
|
106
|
-
// if the first token is invalid, return the second token
|
|
107
|
-
return jwtToken2;
|
|
108
|
-
}
|
|
109
|
-
try {
|
|
110
|
-
decodedToken2 = decodeJWTToken(jwtToken2);
|
|
111
|
-
}
|
|
112
|
-
catch {
|
|
113
|
-
// if the second token is invalid, return the first token
|
|
114
|
-
return jwtToken1;
|
|
115
|
-
}
|
|
116
|
-
if (decodedToken1.exp > decodedToken2.exp) {
|
|
117
|
-
return jwtToken1;
|
|
118
|
-
}
|
|
119
|
-
return jwtToken2;
|
|
120
|
-
}
|
|
121
92
|
//# sourceMappingURL=utils.mjs.map
|
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,EACZ,wBAAwB;AACzB,OAAO,EAAE,WAAW,EAAE,6BAA6B;AASnD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,sEAAsE;IACtE,MAAM,KAAK,GAAG,KAAK,CAAC,KA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AAM,UAAU,yBAAyB,CAAC,OAAgB;IACxD,MAAM,qBAAqB,GAAG,IAAI,CAAC,SAAS,CAAC;QAC3C,EAAE,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,+BAA+B;QAC5D,EAAE,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;KAC9B,CAAC,CAAC;IAEH,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAa;IAClD,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO;QACL,EAAE,EAAE,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC;QACjC,EAAE,EAAE,aAAa,CAAC,aAAa,CAAC,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type { KeyPair } from '@metamask/toprf-secure-backup';\nimport {\n base64ToBytes,\n bigIntToHex,\n bytesToBase64,\n hexToBigInt,\n} from '@metamask/utils';\nimport { bytesToUtf8 } from '@noble/ciphers/utils';\n\nimport type {\n DecodedBaseJWTToken,\n DecodedNodeAuthToken,\n DeserializedVaultData,\n VaultData,\n} from './types';\n\n/**\n * Decode the node auth token from base64 to json object.\n *\n * @param token - The node auth token to decode.\n * @returns The decoded node auth token.\n */\nexport function decodeNodeAuthToken(token: string): DecodedNodeAuthToken {\n return JSON.parse(bytesToUtf8(base64ToBytes(token)));\n}\n\n/**\n * Decode JWT token\n *\n * @param token - The JWT token to decode.\n * @returns The decoded JWT token.\n */\nexport function decodeJWTToken(token: string): DecodedBaseJWTToken {\n // JWT tokens have 3 parts separated by dots: header.payload.signature\n const parts = token.split('.');\n if (parts.length !== 3) {\n throw new Error('Invalid JWT token format');\n }\n\n // Decode the payload (second part)\n const payload = parts[1];\n // Add padding if needed for base64 decoding\n const paddedPayload = payload + '='.repeat((4 - (payload.length % 4)) % 4);\n const decoded = JSON.parse(bytesToUtf8(base64ToBytes(paddedPayload)));\n return decoded as DecodedBaseJWTToken;\n}\n\n/**\n * Serialize the vault data.\n *\n * @param data - The vault data to serialize.\n * @returns The serialized vault data.\n */\nexport function serializeVaultData(data: DeserializedVaultData): string {\n const toprfEncryptionKey = bytesToBase64(data.toprfEncryptionKey);\n const toprfPwEncryptionKey = bytesToBase64(data.toprfPwEncryptionKey);\n const toprfAuthKeyPair = serializeToprfAuthKeyPair(data.toprfAuthKeyPair);\n\n return JSON.stringify({\n toprfEncryptionKey,\n toprfPwEncryptionKey,\n toprfAuthKeyPair,\n revokeToken: data.revokeToken,\n accessToken: data.accessToken,\n });\n}\n\n/**\n * Deserialize the vault data.\n *\n * @param value - The stringified vault data.\n * @returns The deserialized vault data.\n */\nexport function deserializeVaultData(value: VaultData): DeserializedVaultData {\n const toprfEncryptionKey = base64ToBytes(value.toprfEncryptionKey);\n const toprfPwEncryptionKey = base64ToBytes(value.toprfPwEncryptionKey);\n const toprfAuthKeyPair = deserializeAuthKeyPair(value.toprfAuthKeyPair);\n\n return {\n ...value,\n toprfEncryptionKey,\n toprfPwEncryptionKey,\n toprfAuthKeyPair,\n };\n}\n\n/**\n * Serialize TOPRF authentication key pair.\n *\n * @param keyPair - The authentication key pair to serialize.\n * @returns The serialized authentication key pair.\n */\nexport function serializeToprfAuthKeyPair(keyPair: KeyPair): string {\n const b64EncodedAuthKeyPair = JSON.stringify({\n sk: bigIntToHex(keyPair.sk), // Convert BigInt to hex string\n pk: bytesToBase64(keyPair.pk),\n });\n\n return b64EncodedAuthKeyPair;\n}\n\n/**\n * Deserialize the authentication key pair.\n *\n * @param value - The stringified authentication key pair.\n * @returns The deserialized authentication key pair.\n */\nexport function deserializeAuthKeyPair(value: string): KeyPair {\n const parsedKeyPair = JSON.parse(value);\n return {\n sk: hexToBigInt(parsedKeyPair.sk),\n pk: base64ToBytes(parsedKeyPair.pk),\n };\n}\n"]}
|
package/package.json
CHANGED