Sign In

@metamask/toprf-secure-backup

Package Overview
Dependencies
Maintainers
9
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/toprf-secure-backup - npm Package Compare versions

Comparing version
0.7.0
to
0.7.1
+8
-1
CHANGELOG.md

@@ -10,2 +10,8 @@ # Changelog

## [0.7.1]
### Changed
- Changed `fetchAuthPubKey` response to return a object with both `authPubkey` and `KeyIndex`.([#138]https://github.com/MetaMask/toprf-secure-backup/pull/138)
## [0.7.0]

@@ -108,3 +114,4 @@

[Unreleased]: https://github.com/MetaMask/toprf-secure-backup/compare/@metamask/toprf-secure-backup@0.7.0...HEAD
[Unreleased]: https://github.com/MetaMask/toprf-secure-backup/compare/@metamask/toprf-secure-backup@0.7.1...HEAD
[0.7.1]: https://github.com/MetaMask/toprf-secure-backup/compare/@metamask/toprf-secure-backup@0.7.0...@metamask/toprf-secure-backup@0.7.1
[0.7.0]: https://github.com/MetaMask/toprf-secure-backup/compare/@metamask/toprf-secure-backup@0.6.0...@metamask/toprf-secure-backup@0.7.0

@@ -111,0 +118,0 @@ [0.6.0]: https://github.com/MetaMask/toprf-secure-backup/compare/@metamask/toprf-secure-backup@0.5.0...@metamask/toprf-secure-backup@0.6.0

+12
-4

@@ -49,7 +49,15 @@ "use strict";

}
const thresholdPubKey = (0, auth_network_utils_1.thresholdSame)(completedRequests.map((res) => res.result?.pubKey), constants_1.GET_PUB_KEY_THRESHOLD);
if (!thresholdPubKey) {
const thresholdPubKeyData = (0, auth_network_utils_1.thresholdSame)(completedRequests.map((res) => {
return {
pubKey: res.result?.pubKey,
keyIndex: res.result?.keyIndex,
};
}), constants_1.GET_PUB_KEY_THRESHOLD);
if (!thresholdPubKeyData?.pubKey || !thresholdPubKeyData?.keyIndex) {
throw errors_1.TOPRFError.couldNotDeriveThresholdAuthPubKey();
}
return (0, utils_1.hexToBytes)(thresholdPubKey);
return {
authPubKey: (0, utils_1.hexToBytes)(thresholdPubKeyData.pubKey),
keyIndex: thresholdPubKeyData.keyIndex,
};
};

@@ -67,3 +75,3 @@ exports.validatePubKey = validatePubKey;

*
* @returns - A promise that resolves with the key pair seed successfully.
* @returns - A promise that resolves with the latest auth pub key and key index successfully.
*/

@@ -70,0 +78,0 @@ const getPubKey = async (params) => {

@@ -1,1 +0,1 @@

{"version":3,"file":"getPubKeyRequest.cjs","sourceRoot":"","sources":["../src/getPubKeyRequest.ts"],"names":[],"mappings":";;;AAAA,qEAIsC;AACtC,+CAAiD;AACjD,0DAAgE;AAEhE,+CAAkE;AAClE,yCAAsC;AAOtC,uCAAwE;AAExE;;;;;;;;;GASG;AACH,MAAM,4BAA4B,GAAG,CACnC,SAAiB,EACjB,gBAAwB,EACxB,MAAc,EACd,uBAAgC,EACJ,EAAE;IAC9B,OAAO;QACL,SAAS;QACT,QAAQ,EAAE,uBAAuB,IAAI,gBAAgB;QACrD,UAAU,EAAE,MAAM;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,KAAK,EAChC,QAAgB,EAChB,MAAkC,EACF,EAAE;IAClC,MAAM,oBAAoB,GAAG,IAAA,oCAAqB,EAChD,wBAAY,CAAC,mBAAmB,EAChC,MAAM,CACiB,CAAC;IAE1B,OAAO,IAAA,uBAAe,EAAwB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;AAChF,CAAC,CAAC;AAEF;;;;;GAKG;AACI,MAAM,cAAc,GAAG,KAAK,EACjC,SAAkC,EACb,EAAE;IACvB,MAAM,iBAAiB,GACrB,IAAA,4CAAuB,EAAwB,SAAS,CAAC,CAAC;IAE5D,IAAI,iBAAiB,CAAC,MAAM,GAAG,iCAAqB,EAAE;QACpD,MAAM,mBAAU,CAAC,0BAA0B,CACzC,sDAAsD,iCAAqB,YAAY,iBAAiB,CAAC,MAAM,EAAE,CAClH,CAAC;KACH;IACD,MAAM,eAAe,GAAG,IAAA,kCAAa,EACnC,iBAAiB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAClD,iCAAqB,CACtB,CAAC;IAEF,IAAI,CAAC,eAAe,EAAE;QACpB,MAAM,mBAAU,CAAC,iCAAiC,EAAE,CAAC;KACtD;IAED,OAAO,IAAA,kBAAU,EAAC,eAAe,CAAC,CAAC;AACrC,CAAC,CAAC;AArBW,QAAA,cAAc,kBAqBzB;AAEF;;;;;;;;;;;GAWG;AACI,MAAM,SAAS,GAAG,KAAK,EAAE,MAM/B,EAAuB,EAAE;IACxB,MAAM,EACJ,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,EACN,uBAAuB,GACxB,GAAG,MAAM,CAAC;IAEX,IAAI,UAAU,CAAC,MAAM,GAAG,iCAAqB,EAAE;QAC7C,MAAM,mBAAU,CAAC,sBAAsB,CACrC,YAAY,iCAAqB,4BAA4B,CAC9D,CAAC;KACH;IAED,MAAM,uBAAuB,GAAG,IAAA,oCAA4B,EAC1D,UAAU,EACV,gBAAgB,CACjB,CAAC;IAEF,MAAM,QAAQ,GAAG,uBAAuB,CAAC,GAAG,CAC1C,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;QAChC,MAAM,aAAa,GAAG,4BAA4B,CAChD,SAAS,CAAC,SAAS,EACnB,gBAAgB,EAChB,MAAM,EACN,uBAAuB,CACxB,CAAC;QACF,OAAO,oBAAoB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IACvD,CAAC,CACF,CAAC;IAEF,OAAO,IAAA,yBAAI,EAAoC,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,CAC3E,IAAA,sBAAc,EAAC,SAAS,CAAC,CAC1B,CAAC;AACJ,CAAC,CAAC;AAzCW,QAAA,SAAS,aAyCpB","sourcesContent":["import {\n filterCompletedRequests,\n Some,\n thresholdSame,\n} from '@metamask/auth-network-utils';\nimport { hexToBytes } from '@noble/hashes/utils';\nimport { generateJsonRPCObject } from '@toruslabs/http-helpers';\n\nimport { GET_PUB_KEY_THRESHOLD, JRPC_METHODS } from './constants';\nimport { TOPRFError } from './errors';\nimport type { NodeAuthTokens } from './interfaces';\nimport type {\n GetPubKeyJRPCRequest,\n GetPubKeyJRPCRequestParams,\n GetPubKeyJRPCResponse,\n} from './jrpcInterfaces';\nimport { mergeEndpointsWithAuthTokens, postJRPCRequest } from './utils';\n\n/**\n * Creates the parameters for the get pub key request\n *\n * @param authToken - The auth issued by node to authenticate the request.\n * @param authConnectionId - The auth connection name.\n * @param userId - The user id of the user issued by authentication service.\n * @param groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n *\n * @returns The parameters for the get pub key jrpc request.\n */\nconst createGetPubKeyRequestParams = (\n authToken: string,\n authConnectionId: string,\n userId: string,\n groupedAuthConnectionId?: string,\n): GetPubKeyJRPCRequestParams => {\n return {\n authToken,\n verifier: groupedAuthConnectionId ?? authConnectionId,\n verifierId: userId,\n };\n};\n\n/**\n * Sends a get pub key request to the given endpoint.\n *\n * @param endpoint - The endpoint that the request will be sent to.\n * @param params - The request parameters.\n * @returns The pub key.\n */\nconst sendGetPubKeyRequest = async (\n endpoint: string,\n params: GetPubKeyJRPCRequestParams,\n): Promise<GetPubKeyJRPCResponse> => {\n const getPubKeyJRPCRequest = generateJsonRPCObject(\n JRPC_METHODS.GET_PUB_KEY_REQUEST,\n params,\n ) as GetPubKeyJRPCRequest;\n\n return postJRPCRequest<GetPubKeyJRPCResponse>(endpoint, getPubKeyJRPCRequest);\n};\n\n/**\n * Validates the pub key responses.\n *\n * @param resultArr - The get pub key request result\n * @returns The get pub key request result\n */\nexport const validatePubKey = async (\n resultArr: GetPubKeyJRPCResponse[],\n): Promise<Uint8Array> => {\n const completedRequests =\n filterCompletedRequests<GetPubKeyJRPCResponse>(resultArr);\n\n if (completedRequests.length < GET_PUB_KEY_THRESHOLD) {\n throw TOPRFError.insufficientValidResponses(\n `Insufficient get pub key request results, expected ${GET_PUB_KEY_THRESHOLD} but got ${completedRequests.length}`,\n );\n }\n const thresholdPubKey = thresholdSame(\n completedRequests.map((res) => res.result?.pubKey),\n GET_PUB_KEY_THRESHOLD,\n );\n\n if (!thresholdPubKey) {\n throw TOPRFError.couldNotDeriveThresholdAuthPubKey();\n }\n\n return hexToBytes(thresholdPubKey);\n};\n\n/**\n * Fetches the pub key from the nodes.\n *\n * @param params - The parameters for the get pub key request\n * @param params.authTokens - The auth tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.nodeEndpointsMap - Map of node index to endpoint to be used for the toprf eval request.\n *\n * @returns - A promise that resolves with the key pair seed successfully.\n */\nexport const getPubKey = async (params: {\n authTokens: NodeAuthTokens;\n nodeEndpointsMap: Record<number, string>;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n}): Promise<Uint8Array> => {\n const {\n authTokens,\n nodeEndpointsMap,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n } = params;\n\n if (authTokens.length < GET_PUB_KEY_THRESHOLD) {\n throw TOPRFError.insufficientAuthTokens(\n `At least ${GET_PUB_KEY_THRESHOLD} auth tokens are required.`,\n );\n }\n\n const endpointsWithAuthTokens = mergeEndpointsWithAuthTokens(\n authTokens,\n nodeEndpointsMap,\n );\n\n const promises = endpointsWithAuthTokens.map(\n async ({ endpoint, authToken }) => {\n const requestParams = createGetPubKeyRequestParams(\n authToken.authToken,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n );\n return sendGetPubKeyRequest(endpoint, requestParams);\n },\n );\n\n return Some<GetPubKeyJRPCResponse, Uint8Array>(promises, async (resultArr) =>\n validatePubKey(resultArr),\n );\n};\n"]}
{"version":3,"file":"getPubKeyRequest.cjs","sourceRoot":"","sources":["../src/getPubKeyRequest.ts"],"names":[],"mappings":";;;AA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BAAU,CAAC,iCAAiC,EAAE,CAAC;KACtD;IAED,OAAO;QACL,UAAU,EAAE,IAAA,kBAAU,EAAC,mBAAmB,CAAC,MAAM,CAAC;QAClD,QAAQ,EAAE,mBAAmB,CAAC,QAAQ;KACvC,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,cAAc,kBA6BzB;AAEF;;;;;;;;;;;GAWG;AACI,MAAM,SAAS,GAAG,KAAK,EAAE,MAM/B,EAAkC,EAAE;IACnC,MAAM,EACJ,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,EACN,uBAAuB,GACxB,GAAG,MAAM,CAAC;IAEX,IAAI,UAAU,CAAC,MAAM,GAAG,iCAAqB,EAAE;QAC7C,MAAM,mBAAU,CAAC,sBAAsB,CACrC,YAAY,iCAAqB,4BAA4B,CAC9D,CAAC;KACH;IAED,MAAM,uBAAuB,GAAG,IAAA,oCAA4B,EAC1D,UAAU,EACV,gBAAgB,CACjB,CAAC;IAEF,MAAM,QAAQ,GAAG,uBAAuB,CAAC,GAAG,CAC1C,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;QAChC,MAAM,aAAa,GAAG,4BAA4B,CAChD,SAAS,CAAC,SAAS,EACnB,gBAAgB,EAChB,MAAM,EACN,uBAAuB,CACxB,CAAC;QACF,OAAO,oBAAoB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IACvD,CAAC,CACF,CAAC;IAEF,OAAO,IAAA,yBAAI,EACT,QAAQ,EACR,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,IAAA,sBAAc,EAAC,SAAS,CAAC,CAC/C,CAAC;AACJ,CAAC,CAAC;AA1CW,QAAA,SAAS,aA0CpB","sourcesContent":["import {\n filterCompletedRequests,\n Some,\n thresholdSame,\n} from '@metamask/auth-network-utils';\nimport { hexToBytes } from '@noble/hashes/utils';\nimport { generateJsonRPCObject } from '@toruslabs/http-helpers';\n\nimport { GET_PUB_KEY_THRESHOLD, JRPC_METHODS } from './constants';\nimport { TOPRFError } from './errors';\nimport type { FetchAuthPubKeyResult, NodeAuthTokens } from './interfaces';\nimport type {\n GetPubKeyJRPCRequest,\n GetPubKeyJRPCRequestParams,\n GetPubKeyJRPCResponse,\n} from './jrpcInterfaces';\nimport { mergeEndpointsWithAuthTokens, postJRPCRequest } from './utils';\n\n/**\n * Creates the parameters for the get pub key request\n *\n * @param authToken - The auth issued by node to authenticate the request.\n * @param authConnectionId - The auth connection name.\n * @param userId - The user id of the user issued by authentication service.\n * @param groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n *\n * @returns The parameters for the get pub key jrpc request.\n */\nconst createGetPubKeyRequestParams = (\n authToken: string,\n authConnectionId: string,\n userId: string,\n groupedAuthConnectionId?: string,\n): GetPubKeyJRPCRequestParams => {\n return {\n authToken,\n verifier: groupedAuthConnectionId ?? authConnectionId,\n verifierId: userId,\n };\n};\n\n/**\n * Sends a get pub key request to the given endpoint.\n *\n * @param endpoint - The endpoint that the request will be sent to.\n * @param params - The request parameters.\n * @returns The pub key.\n */\nconst sendGetPubKeyRequest = async (\n endpoint: string,\n params: GetPubKeyJRPCRequestParams,\n): Promise<GetPubKeyJRPCResponse> => {\n const getPubKeyJRPCRequest = generateJsonRPCObject(\n JRPC_METHODS.GET_PUB_KEY_REQUEST,\n params,\n ) as GetPubKeyJRPCRequest;\n\n return postJRPCRequest<GetPubKeyJRPCResponse>(endpoint, getPubKeyJRPCRequest);\n};\n\n/**\n * Validates the pub key responses.\n *\n * @param resultArr - The get pub key request result\n * @returns The get pub key request result\n */\nexport const validatePubKey = async (\n resultArr: GetPubKeyJRPCResponse[],\n): Promise<FetchAuthPubKeyResult> => {\n const completedRequests =\n filterCompletedRequests<GetPubKeyJRPCResponse>(resultArr);\n\n if (completedRequests.length < GET_PUB_KEY_THRESHOLD) {\n throw TOPRFError.insufficientValidResponses(\n `Insufficient get pub key request results, expected ${GET_PUB_KEY_THRESHOLD} but got ${completedRequests.length}`,\n );\n }\n const thresholdPubKeyData = thresholdSame(\n completedRequests.map((res) => {\n return {\n pubKey: res.result?.pubKey,\n keyIndex: res.result?.keyIndex,\n };\n }),\n GET_PUB_KEY_THRESHOLD,\n );\n\n if (!thresholdPubKeyData?.pubKey || !thresholdPubKeyData?.keyIndex) {\n throw TOPRFError.couldNotDeriveThresholdAuthPubKey();\n }\n\n return {\n authPubKey: hexToBytes(thresholdPubKeyData.pubKey),\n keyIndex: thresholdPubKeyData.keyIndex,\n };\n};\n\n/**\n * Fetches the pub key from the nodes.\n *\n * @param params - The parameters for the get pub key request\n * @param params.authTokens - The auth tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.nodeEndpointsMap - Map of node index to endpoint to be used for the toprf eval request.\n *\n * @returns - A promise that resolves with the latest auth pub key and key index successfully.\n */\nexport const getPubKey = async (params: {\n authTokens: NodeAuthTokens;\n nodeEndpointsMap: Record<number, string>;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n}): Promise<FetchAuthPubKeyResult> => {\n const {\n authTokens,\n nodeEndpointsMap,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n } = params;\n\n if (authTokens.length < GET_PUB_KEY_THRESHOLD) {\n throw TOPRFError.insufficientAuthTokens(\n `At least ${GET_PUB_KEY_THRESHOLD} auth tokens are required.`,\n );\n }\n\n const endpointsWithAuthTokens = mergeEndpointsWithAuthTokens(\n authTokens,\n nodeEndpointsMap,\n );\n\n const promises = endpointsWithAuthTokens.map(\n async ({ endpoint, authToken }) => {\n const requestParams = createGetPubKeyRequestParams(\n authToken.authToken,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n );\n return sendGetPubKeyRequest(endpoint, requestParams);\n },\n );\n\n return Some<GetPubKeyJRPCResponse, FetchAuthPubKeyResult>(\n promises,\n async (resultArr) => validatePubKey(resultArr),\n );\n};\n"]}

@@ -1,2 +0,2 @@

import type { NodeAuthTokens } from "./interfaces.cjs";
import type { FetchAuthPubKeyResult, NodeAuthTokens } from "./interfaces.cjs";
import type { GetPubKeyJRPCResponse } from "./jrpcInterfaces.cjs";

@@ -9,3 +9,3 @@ /**

*/
export declare const validatePubKey: (resultArr: GetPubKeyJRPCResponse[]) => Promise<Uint8Array>;
export declare const validatePubKey: (resultArr: GetPubKeyJRPCResponse[]) => Promise<FetchAuthPubKeyResult>;
/**

@@ -21,3 +21,3 @@ * Fetches the pub key from the nodes.

*
* @returns - A promise that resolves with the key pair seed successfully.
* @returns - A promise that resolves with the latest auth pub key and key index successfully.
*/

@@ -30,3 +30,3 @@ export declare const getPubKey: (params: {

groupedAuthConnectionId?: string;
}) => Promise<Uint8Array>;
}) => Promise<FetchAuthPubKeyResult>;
//# sourceMappingURL=getPubKeyRequest.d.cts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"getPubKeyRequest.d.cts","sourceRoot":"","sources":["../src/getPubKeyRequest.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,yBAAqB;AACnD,OAAO,KAAK,EAGV,qBAAqB,EACtB,6BAAyB;AA6C1B;;;;;GAKG;AACH,eAAO,MAAM,cAAc,cACd,qBAAqB,EAAE,KACjC,QAAQ,UAAU,CAmBpB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,WAAkB;IACtC,UAAU,EAAE,cAAc,CAAC;IAC3B,gBAAgB,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,KAAG,QAAQ,UAAU,CAmCrB,CAAC"}
{"version":3,"file":"getPubKeyRequest.d.cts","sourceRoot":"","sources":["../src/getPubKeyRequest.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,yBAAqB;AAC1E,OAAO,KAAK,EAGV,qBAAqB,EACtB,6BAAyB;AA6C1B;;;;;GAKG;AACH,eAAO,MAAM,cAAc,cACd,qBAAqB,EAAE,KACjC,QAAQ,qBAAqB,CA2B/B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,WAAkB;IACtC,UAAU,EAAE,cAAc,CAAC;IAC3B,gBAAgB,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,KAAG,QAAQ,qBAAqB,CAoChC,CAAC"}

@@ -1,2 +0,2 @@

import type { NodeAuthTokens } from "./interfaces.mjs";
import type { FetchAuthPubKeyResult, NodeAuthTokens } from "./interfaces.mjs";
import type { GetPubKeyJRPCResponse } from "./jrpcInterfaces.mjs";

@@ -9,3 +9,3 @@ /**

*/
export declare const validatePubKey: (resultArr: GetPubKeyJRPCResponse[]) => Promise<Uint8Array>;
export declare const validatePubKey: (resultArr: GetPubKeyJRPCResponse[]) => Promise<FetchAuthPubKeyResult>;
/**

@@ -21,3 +21,3 @@ * Fetches the pub key from the nodes.

*
* @returns - A promise that resolves with the key pair seed successfully.
* @returns - A promise that resolves with the latest auth pub key and key index successfully.
*/

@@ -30,3 +30,3 @@ export declare const getPubKey: (params: {

groupedAuthConnectionId?: string;
}) => Promise<Uint8Array>;
}) => Promise<FetchAuthPubKeyResult>;
//# sourceMappingURL=getPubKeyRequest.d.mts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"getPubKeyRequest.d.mts","sourceRoot":"","sources":["../src/getPubKeyRequest.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,yBAAqB;AACnD,OAAO,KAAK,EAGV,qBAAqB,EACtB,6BAAyB;AA6C1B;;;;;GAKG;AACH,eAAO,MAAM,cAAc,cACd,qBAAqB,EAAE,KACjC,QAAQ,UAAU,CAmBpB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,WAAkB;IACtC,UAAU,EAAE,cAAc,CAAC;IAC3B,gBAAgB,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,KAAG,QAAQ,UAAU,CAmCrB,CAAC"}
{"version":3,"file":"getPubKeyRequest.d.mts","sourceRoot":"","sources":["../src/getPubKeyRequest.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,yBAAqB;AAC1E,OAAO,KAAK,EAGV,qBAAqB,EACtB,6BAAyB;AA6C1B;;;;;GAKG;AACH,eAAO,MAAM,cAAc,cACd,qBAAqB,EAAE,KACjC,QAAQ,qBAAqB,CA2B/B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,WAAkB;IACtC,UAAU,EAAE,cAAc,CAAC;IAC3B,gBAAgB,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,KAAG,QAAQ,qBAAqB,CAoChC,CAAC"}

@@ -46,7 +46,15 @@ import { filterCompletedRequests, Some, thresholdSame } from "@metamask/auth-network-utils";

}
const thresholdPubKey = thresholdSame(completedRequests.map((res) => res.result?.pubKey), GET_PUB_KEY_THRESHOLD);
if (!thresholdPubKey) {
const thresholdPubKeyData = thresholdSame(completedRequests.map((res) => {
return {
pubKey: res.result?.pubKey,
keyIndex: res.result?.keyIndex,
};
}), GET_PUB_KEY_THRESHOLD);
if (!thresholdPubKeyData?.pubKey || !thresholdPubKeyData?.keyIndex) {
throw TOPRFError.couldNotDeriveThresholdAuthPubKey();
}
return hexToBytes(thresholdPubKey);
return {
authPubKey: hexToBytes(thresholdPubKeyData.pubKey),
keyIndex: thresholdPubKeyData.keyIndex,
};
};

@@ -63,3 +71,3 @@ /**

*
* @returns - A promise that resolves with the key pair seed successfully.
* @returns - A promise that resolves with the latest auth pub key and key index successfully.
*/

@@ -66,0 +74,0 @@ export const getPubKey = async (params) => {

@@ -1,1 +0,1 @@

{"version":3,"file":"getPubKeyRequest.mjs","sourceRoot":"","sources":["../src/getPubKeyRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,IAAI,EACJ,aAAa,EACd,qCAAqC;AACtC,OAAO,EAAE,UAAU,EAAE,4BAA4B;AACjD,OAAO,EAAE,qBAAqB,EAAE,gCAAgC;AAEhE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,wBAAoB;AAClE,OAAO,EAAE,UAAU,EAAE,qBAAiB;AAOtC,OAAO,EAAE,4BAA4B,EAAE,eAAe,EAAE,oBAAgB;AAExE;;;;;;;;;GASG;AACH,MAAM,4BAA4B,GAAG,CACnC,SAAiB,EACjB,gBAAwB,EACxB,MAAc,EACd,uBAAgC,EACJ,EAAE;IAC9B,OAAO;QACL,SAAS;QACT,QAAQ,EAAE,uBAAuB,IAAI,gBAAgB;QACrD,UAAU,EAAE,MAAM;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,KAAK,EAChC,QAAgB,EAChB,MAAkC,EACF,EAAE;IAClC,MAAM,oBAAoB,GAAG,qBAAqB,CAChD,YAAY,CAAC,mBAAmB,EAChC,MAAM,CACiB,CAAC;IAE1B,OAAO,eAAe,CAAwB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;AAChF,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,SAAkC,EACb,EAAE;IACvB,M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AE,KAAK,EAAE,SAAS,EAAE,EAAE,CAC3E,cAAc,CAAC,SAAS,CAAC,CAC1B,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n filterCompletedRequests,\n Some,\n thresholdSame,\n} from '@metamask/auth-network-utils';\nimport { hexToBytes } from '@noble/hashes/utils';\nimport { generateJsonRPCObject } from '@toruslabs/http-helpers';\n\nimport { GET_PUB_KEY_THRESHOLD, JRPC_METHODS } from './constants';\nimport { TOPRFError } from './errors';\nimport type { NodeAuthTokens } from './interfaces';\nimport type {\n GetPubKeyJRPCRequest,\n GetPubKeyJRPCRequestParams,\n GetPubKeyJRPCResponse,\n} from './jrpcInterfaces';\nimport { mergeEndpointsWithAuthTokens, postJRPCRequest } from './utils';\n\n/**\n * Creates the parameters for the get pub key request\n *\n * @param authToken - The auth issued by node to authenticate the request.\n * @param authConnectionId - The auth connection name.\n * @param userId - The user id of the user issued by authentication service.\n * @param groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n *\n * @returns The parameters for the get pub key jrpc request.\n */\nconst createGetPubKeyRequestParams = (\n authToken: string,\n authConnectionId: string,\n userId: string,\n groupedAuthConnectionId?: string,\n): GetPubKeyJRPCRequestParams => {\n return {\n authToken,\n verifier: groupedAuthConnectionId ?? authConnectionId,\n verifierId: userId,\n };\n};\n\n/**\n * Sends a get pub key request to the given endpoint.\n *\n * @param endpoint - The endpoint that the request will be sent to.\n * @param params - The request parameters.\n * @returns The pub key.\n */\nconst sendGetPubKeyRequest = async (\n endpoint: string,\n params: GetPubKeyJRPCRequestParams,\n): Promise<GetPubKeyJRPCResponse> => {\n const getPubKeyJRPCRequest = generateJsonRPCObject(\n JRPC_METHODS.GET_PUB_KEY_REQUEST,\n params,\n ) as GetPubKeyJRPCRequest;\n\n return postJRPCRequest<GetPubKeyJRPCResponse>(endpoint, getPubKeyJRPCRequest);\n};\n\n/**\n * Validates the pub key responses.\n *\n * @param resultArr - The get pub key request result\n * @returns The get pub key request result\n */\nexport const validatePubKey = async (\n resultArr: GetPubKeyJRPCResponse[],\n): Promise<Uint8Array> => {\n const completedRequests =\n filterCompletedRequests<GetPubKeyJRPCResponse>(resultArr);\n\n if (completedRequests.length < GET_PUB_KEY_THRESHOLD) {\n throw TOPRFError.insufficientValidResponses(\n `Insufficient get pub key request results, expected ${GET_PUB_KEY_THRESHOLD} but got ${completedRequests.length}`,\n );\n }\n const thresholdPubKey = thresholdSame(\n completedRequests.map((res) => res.result?.pubKey),\n GET_PUB_KEY_THRESHOLD,\n );\n\n if (!thresholdPubKey) {\n throw TOPRFError.couldNotDeriveThresholdAuthPubKey();\n }\n\n return hexToBytes(thresholdPubKey);\n};\n\n/**\n * Fetches the pub key from the nodes.\n *\n * @param params - The parameters for the get pub key request\n * @param params.authTokens - The auth tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.nodeEndpointsMap - Map of node index to endpoint to be used for the toprf eval request.\n *\n * @returns - A promise that resolves with the key pair seed successfully.\n */\nexport const getPubKey = async (params: {\n authTokens: NodeAuthTokens;\n nodeEndpointsMap: Record<number, string>;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n}): Promise<Uint8Array> => {\n const {\n authTokens,\n nodeEndpointsMap,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n } = params;\n\n if (authTokens.length < GET_PUB_KEY_THRESHOLD) {\n throw TOPRFError.insufficientAuthTokens(\n `At least ${GET_PUB_KEY_THRESHOLD} auth tokens are required.`,\n );\n }\n\n const endpointsWithAuthTokens = mergeEndpointsWithAuthTokens(\n authTokens,\n nodeEndpointsMap,\n );\n\n const promises = endpointsWithAuthTokens.map(\n async ({ endpoint, authToken }) => {\n const requestParams = createGetPubKeyRequestParams(\n authToken.authToken,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n );\n return sendGetPubKeyRequest(endpoint, requestParams);\n },\n );\n\n return Some<GetPubKeyJRPCResponse, Uint8Array>(promises, async (resultArr) =>\n validatePubKey(resultArr),\n );\n};\n"]}
{"version":3,"file":"getPubKeyRequest.mjs","sourceRoot":"","sources":["../src/getPubKeyRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,IAAI,EACJ,aAAa,EACd,qCAAqC;AACtC,OAAO,EAAE,UAAU,EAAE,4BAA4B;AACjD,OAAO,EAAE,qBAAqB,EAAE,gCAAgC;AAEhE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,wBAAoB;AAClE,OAAO,EAAE,UAAU,EAAE,qBAAiB;AAOtC,OAAO,EAAE,4BAA4B,EAAE,eAAe,EAAE,oBAAgB;AAExE;;;;;;;;;GASG;AACH,MAAM,4BAA4B,GAAG,CACnC,SAAiB,EACjB,gBAAwB,EACxB,MAAc,EACd,uBAAgC,EACJ,EAAE;IAC9B,OAAO;QACL,SAAS;QACT,QAAQ,EAAE,uBAAuB,IAAI,gBAAgB;QACrD,UAAU,EAAE,MAAM;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,KAAK,EAChC,QAAgB,EAChB,MAAkC,EACF,EAAE;IAClC,MAAM,oBAAoB,GAAG,qBAAqB,CAChD,YAAY,CAAC,mBAAmB,EAChC,MAAM,CACiB,CAAC;IAE1B,OAAO,eAAe,CAAwB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;AAChF,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,SAAkC,EACF,EAAE;IAClC,MAAM,iBAAiB,GACrB,uBAAuB,CAAwB,SAAS,CAAC,CAAC;IAE5D,IAAI,iBAAiB,CAAC,MAAM,GAAG,qBAAqB,EAAE;QACpD,MAAM,UAAU,CAAC,0BAA0B,CACzC,sDAAsD,qBAAqB,YAAY,iBAAiB,CAAC,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CACF,CAAC;IAEF,OAAO,IAAI,CACT,QAAQ,EACR,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,CAC/C,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n filterCompletedRequests,\n Some,\n thresholdSame,\n} from '@metamask/auth-network-utils';\nimport { hexToBytes } from '@noble/hashes/utils';\nimport { generateJsonRPCObject } from '@toruslabs/http-helpers';\n\nimport { GET_PUB_KEY_THRESHOLD, JRPC_METHODS } from './constants';\nimport { TOPRFError } from './errors';\nimport type { FetchAuthPubKeyResult, NodeAuthTokens } from './interfaces';\nimport type {\n GetPubKeyJRPCRequest,\n GetPubKeyJRPCRequestParams,\n GetPubKeyJRPCResponse,\n} from './jrpcInterfaces';\nimport { mergeEndpointsWithAuthTokens, postJRPCRequest } from './utils';\n\n/**\n * Creates the parameters for the get pub key request\n *\n * @param authToken - The auth issued by node to authenticate the request.\n * @param authConnectionId - The auth connection name.\n * @param userId - The user id of the user issued by authentication service.\n * @param groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n *\n * @returns The parameters for the get pub key jrpc request.\n */\nconst createGetPubKeyRequestParams = (\n authToken: string,\n authConnectionId: string,\n userId: string,\n groupedAuthConnectionId?: string,\n): GetPubKeyJRPCRequestParams => {\n return {\n authToken,\n verifier: groupedAuthConnectionId ?? authConnectionId,\n verifierId: userId,\n };\n};\n\n/**\n * Sends a get pub key request to the given endpoint.\n *\n * @param endpoint - The endpoint that the request will be sent to.\n * @param params - The request parameters.\n * @returns The pub key.\n */\nconst sendGetPubKeyRequest = async (\n endpoint: string,\n params: GetPubKeyJRPCRequestParams,\n): Promise<GetPubKeyJRPCResponse> => {\n const getPubKeyJRPCRequest = generateJsonRPCObject(\n JRPC_METHODS.GET_PUB_KEY_REQUEST,\n params,\n ) as GetPubKeyJRPCRequest;\n\n return postJRPCRequest<GetPubKeyJRPCResponse>(endpoint, getPubKeyJRPCRequest);\n};\n\n/**\n * Validates the pub key responses.\n *\n * @param resultArr - The get pub key request result\n * @returns The get pub key request result\n */\nexport const validatePubKey = async (\n resultArr: GetPubKeyJRPCResponse[],\n): Promise<FetchAuthPubKeyResult> => {\n const completedRequests =\n filterCompletedRequests<GetPubKeyJRPCResponse>(resultArr);\n\n if (completedRequests.length < GET_PUB_KEY_THRESHOLD) {\n throw TOPRFError.insufficientValidResponses(\n `Insufficient get pub key request results, expected ${GET_PUB_KEY_THRESHOLD} but got ${completedRequests.length}`,\n );\n }\n const thresholdPubKeyData = thresholdSame(\n completedRequests.map((res) => {\n return {\n pubKey: res.result?.pubKey,\n keyIndex: res.result?.keyIndex,\n };\n }),\n GET_PUB_KEY_THRESHOLD,\n );\n\n if (!thresholdPubKeyData?.pubKey || !thresholdPubKeyData?.keyIndex) {\n throw TOPRFError.couldNotDeriveThresholdAuthPubKey();\n }\n\n return {\n authPubKey: hexToBytes(thresholdPubKeyData.pubKey),\n keyIndex: thresholdPubKeyData.keyIndex,\n };\n};\n\n/**\n * Fetches the pub key from the nodes.\n *\n * @param params - The parameters for the get pub key request\n * @param params.authTokens - The auth tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.nodeEndpointsMap - Map of node index to endpoint to be used for the toprf eval request.\n *\n * @returns - A promise that resolves with the latest auth pub key and key index successfully.\n */\nexport const getPubKey = async (params: {\n authTokens: NodeAuthTokens;\n nodeEndpointsMap: Record<number, string>;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n}): Promise<FetchAuthPubKeyResult> => {\n const {\n authTokens,\n nodeEndpointsMap,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n } = params;\n\n if (authTokens.length < GET_PUB_KEY_THRESHOLD) {\n throw TOPRFError.insufficientAuthTokens(\n `At least ${GET_PUB_KEY_THRESHOLD} auth tokens are required.`,\n );\n }\n\n const endpointsWithAuthTokens = mergeEndpointsWithAuthTokens(\n authTokens,\n nodeEndpointsMap,\n );\n\n const promises = endpointsWithAuthTokens.map(\n async ({ endpoint, authToken }) => {\n const requestParams = createGetPubKeyRequestParams(\n authToken.authToken,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n );\n return sendGetPubKeyRequest(endpoint, requestParams);\n },\n );\n\n return Some<GetPubKeyJRPCResponse, FetchAuthPubKeyResult>(\n promises,\n async (resultArr) => validatePubKey(resultArr),\n );\n};\n"]}

@@ -1,1 +0,1 @@

{"version":3,"file":"interfaces.cjs","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import type { INodePub } from '@toruslabs/constants';\n\n/**\n * SEC1 encoded public key\n */\nexport type SEC1EncodedPublicKey = Uint8Array;\n\n/**\n * KeyPair - The encryption/decryption private and public key pair.\n *\n * sk - The decryption private key in bigint format.\n *\n * pk - The encryption public key in SEC1 encoded format.\n */\nexport type KeyPair = {\n sk: bigint;\n pk: SEC1EncodedPublicKey;\n};\n\n/**\n * Optional override for node details.\n */\nexport type NodeDetailsOverride = {\n /**\n * Endpoint configuration. This allows for overriding the default SSS node endpoints.\n *\n * - **To use FND-resolved node URLs with a custom path:** Provide a single `string`\n * representing the path to be appended to each FND-resolved node URL.\n * For example, `'/sss-toprf'` will transform FND URLs like `https://node1.example.com`\n * into `https://node1.example.com/sss-toprf`.\n *\n * - **To use a completely custom set of node URLs (bypassing FND resolution):**\n * Provide an array of `string[]` where each string is a complete endpoint URL.\n * For example, `['https://custom-node1.com/custom-path', 'https://custom-node2.com/custom-path']`.\n *\n * If left `undefined`, the SDK will use the default FND-resolved SSS endpoints directly.\n */\n endpoints?: string | string[];\n /**\n * Array of node indexes. Must match network node count if provided.\n */\n indexes?: number[];\n /**\n * Array of node public keys. Must match network node count if provided.\n */\n pubKeys?: INodePub[];\n};\n\n/**\n * AuthenticateParams - The parameters for the authenticate request.\n *\n * idTokens - The idTokens to be used for the authenticate request.\n *\n * authConnectionId - The auth connection name to be used for the authenticate request.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * userId - The user id of the user to be used for the authenticate request.\n *\n * groupedAuthConnectionParams - Optional groupedAuthConnectionParams to be used for the authenticate request.\n * You can pass this to use aggregate verifier.\n */\nexport type AuthenticateParams = {\n // for now we only support one idToken, in future we will support multiple to remove commitment call\n // so leaving it as an array for future use\n idTokens: string[];\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * NodeAuthToken - An authentication token and the node details.\n *\n * authToken - The authentication token.\n *\n * nodeIndex - The index of the node that issued the token.\n *\n * nodePubKey - The public key of the node that issued the token.\n */\nexport type NodeAuthToken = {\n authToken: string;\n nodeIndex: number;\n nodePubKey: string;\n};\n/**\n * nodeAuthTokens - An array of authentication tokens issued by the nodes.\n */\nexport type NodeAuthTokens = NodeAuthToken[];\n\n/**\n * nodeAuthTokens - An array of authentication tokens issued by the nodes.\n *\n * isNewUser - Indicates if the user has completed the key setup process or not.\n * if `true` then the user hasn't completed the social + password setup process.\n * if `false` then the user has completed the social + password setup process.\n */\nexport type AuthenticateResult = {\n nodeAuthTokens: NodeAuthTokens;\n isNewUser: boolean;\n};\n\n/**\n * CreateLocalKeyParams - The parameters for creating an OPRF encryption key locally.\n *\n * password - The password of the user.\n *\n * oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n */\nexport type CreateLocalKeyParams = {\n password: string;\n oprfKey?: bigint;\n};\n\n/**\n * CreateLocalKeyResult - The result of creating an encryption key.\n *\n * oprfKey - The OPRF key which is used to for local OPRF evaluation.\n *\n * seed - The seed which is used to derive the authentication and encryption keys.\n *\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n *\n * encKey - The encryption key which is used to encrypt the secret data.\n */\nexport type CreateLocalKeyResult = {\n oprfKey: bigint;\n seed: Uint8Array;\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\n/**\n * PersistLocalKeyParams - The parameters for persisting an OPRF key's shares to the servers.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * oprfKey - The OPRF key which is used to for local OPRF evaluation.\n *\n * authPubKey - The authentication public key which is used to authenticate the write request to the metadata store.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * keyShareIndex - Optional key share index to be persisted.\n *\n * oldAuthKeyPair - Optional authentication key pair to be used for key change flow.\n */\nexport type PersistLocalKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n oprfKey: bigint;\n authPubKey: SEC1EncodedPublicKey;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n keyShareIndex?: number;\n oldAuthKeyPair?: KeyPair;\n};\n\n/**\n * CreateEncryptionKeyParams - The parameters for creating an encryption key.\n *\n * authConnectionId - The auth connection name of the user.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * nodeAuthTokens - The tokens issued by the nodes on verifying the idTokens.\n *\n * password - The password of the user.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n */\nexport type CreateEncryptionKeyParams = {\n authConnectionId: string;\n userId: string;\n nodeAuthTokens: NodeAuthTokens;\n password: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * CreateEncryptionKeyResult - The result of creating an encryption key.\n *\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n *\n * encKey - The encryption key which is used to encrypt the secret data.\n *\n * pwEncKey - The password encryption key which is used to encrypt the password.\n */\nexport type CreateEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\nexport type BaseAddSecretDataItemParams<\n SecretDataType,\n EncKeyType = Uint8Array,\n> = {\n /**\n * The secret data to be stored.\n */\n secretData: SecretDataType;\n\n /**\n * The encryption key to be used to encrypt the secret data.\n */\n encKey: EncKeyType;\n\n /**\n * The authentication key to be used to provide valid signature for storing the secret data.\n */\n authKeyPair: KeyPair;\n};\n\n/**\n * encKey - The encryption key to be used to encrypt the secret data before storing it.\n *\n * authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n *\n * secretData - The secret data to be stored.\n */\nexport type AddSecretDataItemParams = BaseAddSecretDataItemParams<Uint8Array>;\n\nexport type BatchAddSecretDataItemParams = BaseAddSecretDataItemParams<\n Uint8Array[],\n Uint8Array | Uint8Array[]\n>;\n\n/**\n * RecoverEncryptionKeyParams - The parameters for recovering the encryption key.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * password - The password of the user.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n */\nexport type RecoverEncryptionKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n password: string;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n * encKey - The encryption key which is used to encrypt the secret data.\n * keyShareIndex - The index of the key shares on the nodes, used for key change operations.\n * rateLimitResetResult - A promise that resolves when the rate limit is reset.\n */\nexport type RecoverEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n keyShareIndex: number;\n rateLimitResetResult: Promise<void>;\n};\n\n/**\n * Parameters for changing the encryption key.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * oldEncKey - The old encryption key of the user.\n *\n * oldAuthKeyPair - The old authentication key pair of the user.\n *\n * newKeyShareIndex - The key share index to be used for the new key.\n *\n * newPassword - Optional new password of the user, either this or pregeneratedOprfKey is required.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * pregeneratedOprfKey - Optional pregenerated OPRF key to be used for the key change, if not provided, a new key will be generated from the new password.\n */\nexport type ChangeEncryptionKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n authConnectionId: string;\n userId: string;\n oldEncKey: Uint8Array;\n oldPwEncKey: Uint8Array;\n oldAuthKeyPair: KeyPair;\n newKeyShareIndex: number;\n newPassword?: string;\n groupedAuthConnectionId?: string;\n pregeneratedOprfKey?: CreateLocalKeyResult;\n};\n\n/**\n * authKeyPair - The new authentication key pair which is used to authenticate the user.\n * encKey - The new encryption key which is used to encrypt the secret data.\n */\nexport type ChangeEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\n/**\n * keyPair - The encryption/decryption key pair which is used to decrypt the secret data.\n */\nexport type FetchAllSecretDataParams = {\n /**\n * The decryption key to be used to decrypt the secret data.\n */\n decKey: Uint8Array;\n\n /**\n * The authentication key to be used to provide valid signature for fetching the secret data.\n */\n authKeyPair: KeyPair;\n};\n\n/**\n * Proof that the user owns the old key when changing to a new password/key\n * Contains a signature created with the old private key on a timestamp and new key share data.\n */\nexport type KeyChangeProof = {\n oldKeySignature: string;\n signatureTimestamp: number;\n};\n\n/**\n * FetchAuthPubKeyParams - The parameters for fetching the authentication public key.\n *\n * nodeAuthTokens - Auth tokens issued by nodes.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * userId - The user id of the user issued by authentication service.\n */\nexport type FetchAuthPubKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n authConnectionId: string;\n groupedAuthConnectionId?: string;\n userId: string;\n};\n\nexport type FetchAuthPubKeyResult = {\n authPubKey: SEC1EncodedPublicKey;\n};\n\nexport type RecoverPwEncKeyParams = {\n targetAuthPubKey: SEC1EncodedPublicKey;\n curPwEncKey: Uint8Array;\n curAuthKeyPair: KeyPair;\n maxPwChainLength?: number;\n};\n\nexport type RecoverPwEncKeyResult = {\n pwEncKey: Uint8Array;\n};\n\nexport type IToprfSecureBackup = {\n authenticate: (params: AuthenticateParams) => Promise<AuthenticateResult>;\n\n /**\n * This function locally creates an OPRF and encryption key without storing it at the key\n * management service. It returns the OPRF key, derives the corresponding key\n * seed, authentication key pair and encryption key.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.password - New password of the user.\n * @param params.oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n *\n * @returns A promise that resolves with the encryption key.\n */\n createLocalKey: (\n params: CreateLocalKeyParams,\n ) => Promise<CreateLocalKeyResult>;\n\n /**\n * This function persists an locally created OPRF key's shares to the servers.\n *\n * @param params - The parameters for persisting an OPRF key's shares.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.oprfKey - The OPRF key to be persisted.\n * @param params.authKeyPair - The authentication key pair which is used to authenticate the write request to the metadata store.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.keyShareIndex - The key share index to be persisted. Required only during key change, defaults to FIRST_KEY_INDEX for first-time storage.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user. Required only during key change, not needed for first-time storage.\n * @returns A promise that resolves when the OPRF key's shares are persisted.\n */\n persistLocalKey: (params: PersistLocalKeyParams) => Promise<void>;\n\n createAndPersistEncKey: (\n params: CreateEncryptionKeyParams,\n ) => Promise<CreateEncryptionKeyResult>;\n\n recoverEncKey: (\n params: RecoverEncryptionKeyParams,\n ) => Promise<RecoverEncryptionKeyResult>;\n\n /**\n * This function replaces the existing encryption key with a new one and copies the secret data of existing encryption key to the new one.\n *\n * @param params - The parameters for changing the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.newPassword - The new password of the user.\n * @param params.keyPair - The current encryption key of the user.\n *\n * @returns A promise that resolves with the new encryption key.\n */\n changeEncKey: (\n params: ChangeEncryptionKeyParams,\n ) => Promise<ChangeEncryptionKeyResult>;\n\n /**\n * This function encrypts the secret data using the encryption key and stores it nodes metadata store in encrypted form.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n * @param params.secretData - The array of secret data to be registered.\n *\n * @returns A promise that resolves when the secret data is registered.\n */\n addSecretDataItem: (params: AddSecretDataItemParams) => Promise<void>;\n\n /**\n * This function encrypts the array of secret data using the encryption key and stores it in the metadata store in encrypted form as a batch.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n * @param params.secretData - The array of secret data to be stored.\n *\n * @returns A promise that resolves when the secret data is stored.\n */\n batchAddSecretDataItems: (\n params: BatchAddSecretDataItemParams,\n ) => Promise<void>;\n\n /**\n * This function fetches all secret data items associated with the given\n * auth pub key, decrypts, and returns them.\n *\n * @param params - The parameters for fetching the secret data.\n * @param params.decKey - The decryption key to be used to decrypt the secret data.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for fetching the secret data.\n *\n * @returns {Uint8Array[]} A promise that resolves with the array of decrypted secret data.\n */\n fetchAllSecretDataItems: (\n params: FetchAllSecretDataParams,\n ) => Promise<Uint8Array[]>;\n\n /**\n * This function fetches the authentication public key.\n *\n * @param params - The parameters for fetching the authentication public key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.userId - The user id of the user issued by authentication service.\n *\n * @returns A promise that resolves with the authentication public key.\n */\n fetchAuthPubKey: (\n params: FetchAuthPubKeyParams,\n ) => Promise<FetchAuthPubKeyResult>;\n\n /**\n * This function recovers the password encryption key of the user.\n *\n * @param params - The parameters for recovering the password encryption key.\n * @param params.targetAuthPubKey - The public key of the target encryption key.\n * @param params.curPwEncKey - The current password encryption key of the user.\n * @param params.curAuthKeyPair - The current authentication key pair of the user.\n *\n * @returns A promise that resolves to the password encryption key of the user.\n */\n recoverPwEncKey: (\n params: RecoverPwEncKeyParams,\n ) => Promise<RecoverPwEncKeyResult>;\n};\n\n/**\n * Base payload structure for metadata request\n */\nexport type IBaseMetadataRequestBody = {\n /**\n * The feature name related to the secret data\n */\n feature: string;\n /**\n * The public key of the user\n */\n pubKey: string;\n /**\n * The Unix timestamp when the request payload is created along with the signature.\n *\n */\n timestamp: string;\n};\n\n/**\n * The array of secret data to be stored in batch request\n */\nexport type IBatchAddData = {\n /**\n * The base64-encoded string of the secret data\n */\n data: string;\n /**\n * The version of the Metadata Store\n */\n version?: string;\n}[];\n\n/**\n * Payload structure for storing secret data\n */\nexport type IBaseAddSecretDataRequestBody<DataType> =\n IBaseMetadataRequestBody & {\n /**\n * The authentication token of the user issued by authentication service.\n * this token is also known as `metadataAccessToken`.\n */\n authToken?: string;\n /**\n * The secret data to be stored.\n *\n * For storing the single secret data, the data should be base64-encoded string.\n *\n * @example\n * ```ts\n * const data = Buffer.from('SECRET_DATA').toString('base64');\n * ```\n *\n * For storing the batch of secret data, the data should be an array of `IBatchAddData`.\n *\n * @example\n * ```ts\n * const data = [\n * { data: Buffer.from('SECRET_DATA_1').toString('base64') },\n * { data: Buffer.from('SECRET_DATA_2').toString('base64') },\n * ];\n * ```\n */\n data: DataType;\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(data, feature, authToken, timestamp))\n */\n signature: string;\n };\n\n/**\n * Payload structure for storing secret data for single secret data\n */\nexport type IAddSecretDataRequestBody =\n IBaseAddSecretDataRequestBody<string> & {\n /**\n * The version of the secret data\n */\n version?: string;\n /**\n * The item id to be used for storing the secret data.\n */\n itemId?: string;\n };\n\n/**\n * Payload structure for storing secret data in batch request\n */\nexport type IBatchAddSecretDataRequestBody =\n IBaseAddSecretDataRequestBody<IBatchAddData>;\n\n/**\n * Payload structure for fetching secret data\n */\nexport type IGetSecretDataRequestBody = IBaseMetadataRequestBody & {\n /**\n * The authentication token of the user issued by the SSS services\n */\n authToken?: string;\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(feature, authToken, timestamp))\n */\n signature: string;\n /**\n * The item id to be used for fetching the secret data.\n */\n itemId?: string;\n};\n\n/**\n * Payload structure for acquiring/releasing a lock on the metadata\n */\nexport type IMetadataLockRequestBody = {\n /**\n * The public key of the user\n */\n key: string;\n /**\n * The Unix timestamp when the request payload is created along with the signature.\n *\n */\n data: {\n timestamp: number;\n };\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(feature, authToken, timestamp))\n */\n signature: string;\n /**\n * The lock id to be released.\n */\n id?: string | undefined;\n};\n\n/**\n * FetchMetadataAccessCreds - The function to fetch the metadata access credentials.\n *\n * @returns The metadata access credentials.\n */\nexport type FetchMetadataAccessCreds = () => Promise<{\n metadataAccessToken: string;\n}>;\n"]}
{"version":3,"file":"interfaces.cjs","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import type { INodePub } from '@toruslabs/constants';\n\n/**\n * SEC1 encoded public key\n */\nexport type SEC1EncodedPublicKey = Uint8Array;\n\n/**\n * KeyPair - The encryption/decryption private and public key pair.\n *\n * sk - The decryption private key in bigint format.\n *\n * pk - The encryption public key in SEC1 encoded format.\n */\nexport type KeyPair = {\n sk: bigint;\n pk: SEC1EncodedPublicKey;\n};\n\n/**\n * Optional override for node details.\n */\nexport type NodeDetailsOverride = {\n /**\n * Endpoint configuration. This allows for overriding the default SSS node endpoints.\n *\n * - **To use FND-resolved node URLs with a custom path:** Provide a single `string`\n * representing the path to be appended to each FND-resolved node URL.\n * For example, `'/sss-toprf'` will transform FND URLs like `https://node1.example.com`\n * into `https://node1.example.com/sss-toprf`.\n *\n * - **To use a completely custom set of node URLs (bypassing FND resolution):**\n * Provide an array of `string[]` where each string is a complete endpoint URL.\n * For example, `['https://custom-node1.com/custom-path', 'https://custom-node2.com/custom-path']`.\n *\n * If left `undefined`, the SDK will use the default FND-resolved SSS endpoints directly.\n */\n endpoints?: string | string[];\n /**\n * Array of node indexes. Must match network node count if provided.\n */\n indexes?: number[];\n /**\n * Array of node public keys. Must match network node count if provided.\n */\n pubKeys?: INodePub[];\n};\n\n/**\n * AuthenticateParams - The parameters for the authenticate request.\n *\n * idTokens - The idTokens to be used for the authenticate request.\n *\n * authConnectionId - The auth connection name to be used for the authenticate request.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * userId - The user id of the user to be used for the authenticate request.\n *\n * groupedAuthConnectionParams - Optional groupedAuthConnectionParams to be used for the authenticate request.\n * You can pass this to use aggregate verifier.\n */\nexport type AuthenticateParams = {\n // for now we only support one idToken, in future we will support multiple to remove commitment call\n // so leaving it as an array for future use\n idTokens: string[];\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * NodeAuthToken - An authentication token and the node details.\n *\n * authToken - The authentication token.\n *\n * nodeIndex - The index of the node that issued the token.\n *\n * nodePubKey - The public key of the node that issued the token.\n */\nexport type NodeAuthToken = {\n authToken: string;\n nodeIndex: number;\n nodePubKey: string;\n};\n/**\n * nodeAuthTokens - An array of authentication tokens issued by the nodes.\n */\nexport type NodeAuthTokens = NodeAuthToken[];\n\n/**\n * nodeAuthTokens - An array of authentication tokens issued by the nodes.\n *\n * isNewUser - Indicates if the user has completed the key setup process or not.\n * if `true` then the user hasn't completed the social + password setup process.\n * if `false` then the user has completed the social + password setup process.\n */\nexport type AuthenticateResult = {\n nodeAuthTokens: NodeAuthTokens;\n isNewUser: boolean;\n};\n\n/**\n * CreateLocalKeyParams - The parameters for creating an OPRF encryption key locally.\n *\n * password - The password of the user.\n *\n * oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n */\nexport type CreateLocalKeyParams = {\n password: string;\n oprfKey?: bigint;\n};\n\n/**\n * CreateLocalKeyResult - The result of creating an encryption key.\n *\n * oprfKey - The OPRF key which is used to for local OPRF evaluation.\n *\n * seed - The seed which is used to derive the authentication and encryption keys.\n *\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n *\n * encKey - The encryption key which is used to encrypt the secret data.\n */\nexport type CreateLocalKeyResult = {\n oprfKey: bigint;\n seed: Uint8Array;\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\n/**\n * PersistLocalKeyParams - The parameters for persisting an OPRF key's shares to the servers.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * oprfKey - The OPRF key which is used to for local OPRF evaluation.\n *\n * authPubKey - The authentication public key which is used to authenticate the write request to the metadata store.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * keyShareIndex - Optional key share index to be persisted.\n *\n * oldAuthKeyPair - Optional authentication key pair to be used for key change flow.\n */\nexport type PersistLocalKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n oprfKey: bigint;\n authPubKey: SEC1EncodedPublicKey;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n keyShareIndex?: number;\n oldAuthKeyPair?: KeyPair;\n};\n\n/**\n * CreateEncryptionKeyParams - The parameters for creating an encryption key.\n *\n * authConnectionId - The auth connection name of the user.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * nodeAuthTokens - The tokens issued by the nodes on verifying the idTokens.\n *\n * password - The password of the user.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n */\nexport type CreateEncryptionKeyParams = {\n authConnectionId: string;\n userId: string;\n nodeAuthTokens: NodeAuthTokens;\n password: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * CreateEncryptionKeyResult - The result of creating an encryption key.\n *\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n *\n * encKey - The encryption key which is used to encrypt the secret data.\n *\n * pwEncKey - The password encryption key which is used to encrypt the password.\n */\nexport type CreateEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\nexport type BaseAddSecretDataItemParams<\n SecretDataType,\n EncKeyType = Uint8Array,\n> = {\n /**\n * The secret data to be stored.\n */\n secretData: SecretDataType;\n\n /**\n * The encryption key to be used to encrypt the secret data.\n */\n encKey: EncKeyType;\n\n /**\n * The authentication key to be used to provide valid signature for storing the secret data.\n */\n authKeyPair: KeyPair;\n};\n\n/**\n * encKey - The encryption key to be used to encrypt the secret data before storing it.\n *\n * authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n *\n * secretData - The secret data to be stored.\n */\nexport type AddSecretDataItemParams = BaseAddSecretDataItemParams<Uint8Array>;\n\nexport type BatchAddSecretDataItemParams = BaseAddSecretDataItemParams<\n Uint8Array[],\n Uint8Array | Uint8Array[]\n>;\n\n/**\n * RecoverEncryptionKeyParams - The parameters for recovering the encryption key.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * password - The password of the user.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n */\nexport type RecoverEncryptionKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n password: string;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n * encKey - The encryption key which is used to encrypt the secret data.\n * keyShareIndex - The index of the key shares on the nodes, used for key change operations.\n * rateLimitResetResult - A promise that resolves when the rate limit is reset.\n */\nexport type RecoverEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n keyShareIndex: number;\n rateLimitResetResult: Promise<void>;\n};\n\n/**\n * Parameters for changing the encryption key.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * oldEncKey - The old encryption key of the user.\n *\n * oldAuthKeyPair - The old authentication key pair of the user.\n *\n * newKeyShareIndex - The key share index to be used for the new key.\n *\n * newPassword - Optional new password of the user, either this or pregeneratedOprfKey is required.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * pregeneratedOprfKey - Optional pregenerated OPRF key to be used for the key change, if not provided, a new key will be generated from the new password.\n */\nexport type ChangeEncryptionKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n authConnectionId: string;\n userId: string;\n oldEncKey: Uint8Array;\n oldPwEncKey: Uint8Array;\n oldAuthKeyPair: KeyPair;\n newKeyShareIndex: number;\n newPassword?: string;\n groupedAuthConnectionId?: string;\n pregeneratedOprfKey?: CreateLocalKeyResult;\n};\n\n/**\n * authKeyPair - The new authentication key pair which is used to authenticate the user.\n * encKey - The new encryption key which is used to encrypt the secret data.\n */\nexport type ChangeEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\n/**\n * keyPair - The encryption/decryption key pair which is used to decrypt the secret data.\n */\nexport type FetchAllSecretDataParams = {\n /**\n * The decryption key to be used to decrypt the secret data.\n */\n decKey: Uint8Array;\n\n /**\n * The authentication key to be used to provide valid signature for fetching the secret data.\n */\n authKeyPair: KeyPair;\n};\n\n/**\n * Proof that the user owns the old key when changing to a new password/key\n * Contains a signature created with the old private key on a timestamp and new key share data.\n */\nexport type KeyChangeProof = {\n oldKeySignature: string;\n signatureTimestamp: number;\n};\n\n/**\n * FetchAuthPubKeyParams - The parameters for fetching the authentication public key.\n *\n * nodeAuthTokens - Auth tokens issued by nodes.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * userId - The user id of the user issued by authentication service.\n */\nexport type FetchAuthPubKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n authConnectionId: string;\n groupedAuthConnectionId?: string;\n userId: string;\n};\n\nexport type FetchAuthPubKeyResult = {\n authPubKey: SEC1EncodedPublicKey;\n keyIndex: number;\n};\n\nexport type RecoverPwEncKeyParams = {\n targetAuthPubKey: SEC1EncodedPublicKey;\n curPwEncKey: Uint8Array;\n curAuthKeyPair: KeyPair;\n maxPwChainLength?: number;\n};\n\nexport type RecoverPwEncKeyResult = {\n pwEncKey: Uint8Array;\n};\n\nexport type IToprfSecureBackup = {\n authenticate: (params: AuthenticateParams) => Promise<AuthenticateResult>;\n\n /**\n * This function locally creates an OPRF and encryption key without storing it at the key\n * management service. It returns the OPRF key, derives the corresponding key\n * seed, authentication key pair and encryption key.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.password - New password of the user.\n * @param params.oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n *\n * @returns A promise that resolves with the encryption key.\n */\n createLocalKey: (\n params: CreateLocalKeyParams,\n ) => Promise<CreateLocalKeyResult>;\n\n /**\n * This function persists an locally created OPRF key's shares to the servers.\n *\n * @param params - The parameters for persisting an OPRF key's shares.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.oprfKey - The OPRF key to be persisted.\n * @param params.authKeyPair - The authentication key pair which is used to authenticate the write request to the metadata store.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.keyShareIndex - The key share index to be persisted. Required only during key change, defaults to FIRST_KEY_INDEX for first-time storage.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user. Required only during key change, not needed for first-time storage.\n * @returns A promise that resolves when the OPRF key's shares are persisted.\n */\n persistLocalKey: (params: PersistLocalKeyParams) => Promise<void>;\n\n createAndPersistEncKey: (\n params: CreateEncryptionKeyParams,\n ) => Promise<CreateEncryptionKeyResult>;\n\n recoverEncKey: (\n params: RecoverEncryptionKeyParams,\n ) => Promise<RecoverEncryptionKeyResult>;\n\n /**\n * This function replaces the existing encryption key with a new one and copies the secret data of existing encryption key to the new one.\n *\n * @param params - The parameters for changing the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.newPassword - The new password of the user.\n * @param params.keyPair - The current encryption key of the user.\n *\n * @returns A promise that resolves with the new encryption key.\n */\n changeEncKey: (\n params: ChangeEncryptionKeyParams,\n ) => Promise<ChangeEncryptionKeyResult>;\n\n /**\n * This function encrypts the secret data using the encryption key and stores it nodes metadata store in encrypted form.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n * @param params.secretData - The array of secret data to be registered.\n *\n * @returns A promise that resolves when the secret data is registered.\n */\n addSecretDataItem: (params: AddSecretDataItemParams) => Promise<void>;\n\n /**\n * This function encrypts the array of secret data using the encryption key and stores it in the metadata store in encrypted form as a batch.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n * @param params.secretData - The array of secret data to be stored.\n *\n * @returns A promise that resolves when the secret data is stored.\n */\n batchAddSecretDataItems: (\n params: BatchAddSecretDataItemParams,\n ) => Promise<void>;\n\n /**\n * This function fetches all secret data items associated with the given\n * auth pub key, decrypts, and returns them.\n *\n * @param params - The parameters for fetching the secret data.\n * @param params.decKey - The decryption key to be used to decrypt the secret data.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for fetching the secret data.\n *\n * @returns {Uint8Array[]} A promise that resolves with the array of decrypted secret data.\n */\n fetchAllSecretDataItems: (\n params: FetchAllSecretDataParams,\n ) => Promise<Uint8Array[]>;\n\n /**\n * This function fetches the authentication public key.\n *\n * @param params - The parameters for fetching the authentication public key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.userId - The user id of the user issued by authentication service.\n *\n * @returns A promise that resolves with the authentication public key.\n */\n fetchAuthPubKey: (\n params: FetchAuthPubKeyParams,\n ) => Promise<FetchAuthPubKeyResult>;\n\n /**\n * This function recovers the password encryption key of the user.\n *\n * @param params - The parameters for recovering the password encryption key.\n * @param params.targetAuthPubKey - The public key of the target encryption key.\n * @param params.curPwEncKey - The current password encryption key of the user.\n * @param params.curAuthKeyPair - The current authentication key pair of the user.\n *\n * @returns A promise that resolves to the password encryption key of the user.\n */\n recoverPwEncKey: (\n params: RecoverPwEncKeyParams,\n ) => Promise<RecoverPwEncKeyResult>;\n};\n\n/**\n * Base payload structure for metadata request\n */\nexport type IBaseMetadataRequestBody = {\n /**\n * The feature name related to the secret data\n */\n feature: string;\n /**\n * The public key of the user\n */\n pubKey: string;\n /**\n * The Unix timestamp when the request payload is created along with the signature.\n *\n */\n timestamp: string;\n};\n\n/**\n * The array of secret data to be stored in batch request\n */\nexport type IBatchAddData = {\n /**\n * The base64-encoded string of the secret data\n */\n data: string;\n /**\n * The version of the Metadata Store\n */\n version?: string;\n}[];\n\n/**\n * Payload structure for storing secret data\n */\nexport type IBaseAddSecretDataRequestBody<DataType> =\n IBaseMetadataRequestBody & {\n /**\n * The authentication token of the user issued by authentication service.\n * this token is also known as `metadataAccessToken`.\n */\n authToken?: string;\n /**\n * The secret data to be stored.\n *\n * For storing the single secret data, the data should be base64-encoded string.\n *\n * @example\n * ```ts\n * const data = Buffer.from('SECRET_DATA').toString('base64');\n * ```\n *\n * For storing the batch of secret data, the data should be an array of `IBatchAddData`.\n *\n * @example\n * ```ts\n * const data = [\n * { data: Buffer.from('SECRET_DATA_1').toString('base64') },\n * { data: Buffer.from('SECRET_DATA_2').toString('base64') },\n * ];\n * ```\n */\n data: DataType;\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(data, feature, authToken, timestamp))\n */\n signature: string;\n };\n\n/**\n * Payload structure for storing secret data for single secret data\n */\nexport type IAddSecretDataRequestBody =\n IBaseAddSecretDataRequestBody<string> & {\n /**\n * The version of the secret data\n */\n version?: string;\n /**\n * The item id to be used for storing the secret data.\n */\n itemId?: string;\n };\n\n/**\n * Payload structure for storing secret data in batch request\n */\nexport type IBatchAddSecretDataRequestBody =\n IBaseAddSecretDataRequestBody<IBatchAddData>;\n\n/**\n * Payload structure for fetching secret data\n */\nexport type IGetSecretDataRequestBody = IBaseMetadataRequestBody & {\n /**\n * The authentication token of the user issued by the SSS services\n */\n authToken?: string;\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(feature, authToken, timestamp))\n */\n signature: string;\n /**\n * The item id to be used for fetching the secret data.\n */\n itemId?: string;\n};\n\n/**\n * Payload structure for acquiring/releasing a lock on the metadata\n */\nexport type IMetadataLockRequestBody = {\n /**\n * The public key of the user\n */\n key: string;\n /**\n * The Unix timestamp when the request payload is created along with the signature.\n *\n */\n data: {\n timestamp: number;\n };\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(feature, authToken, timestamp))\n */\n signature: string;\n /**\n * The lock id to be released.\n */\n id?: string | undefined;\n};\n\n/**\n * FetchMetadataAccessCreds - The function to fetch the metadata access credentials.\n *\n * @returns The metadata access credentials.\n */\nexport type FetchMetadataAccessCreds = () => Promise<{\n metadataAccessToken: string;\n}>;\n"]}

@@ -324,2 +324,3 @@ import type { INodePub } from "@toruslabs/constants";

authPubKey: SEC1EncodedPublicKey;
keyIndex: number;
};

@@ -326,0 +327,0 @@ export type RecoverPwEncKeyParams = {

@@ -1,1 +0,1 @@

{"version":3,"file":"interfaces.d.cts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,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I,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACzB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,OAAO,CAAC;IACnD,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC,CAAC"}

@@ -324,2 +324,3 @@ import type { INodePub } from "@toruslabs/constants";

authPubKey: SEC1EncodedPublicKey;
keyIndex: number;
};

@@ -326,0 +327,0 @@ export type RecoverPwEncKeyParams = {

@@ -1,1 +0,1 @@

{"version":3,"file":"interfaces.d.mts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,6BAA6B;AAErD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,oBAAoB,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;;;;;;;;;;OAaG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;OAEG;IACH,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAG/B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,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CAAC,MAAM,CAAC,GAAG;IACtC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,8BAA8B,GACxC,6BAA6B,CAAC,aAAa,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,wBAAwB,GAAG;IACjE;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACzB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,OAAO,CAAC;IACnD,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC,CAAC"}

@@ -1,1 +0,1 @@

{"version":3,"file":"interfaces.mjs","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import type { INodePub } from '@toruslabs/constants';\n\n/**\n * SEC1 encoded public key\n */\nexport type SEC1EncodedPublicKey = Uint8Array;\n\n/**\n * KeyPair - The encryption/decryption private and public key pair.\n *\n * sk - The decryption private key in bigint format.\n *\n * pk - The encryption public key in SEC1 encoded format.\n */\nexport type KeyPair = {\n sk: bigint;\n pk: SEC1EncodedPublicKey;\n};\n\n/**\n * Optional override for node details.\n */\nexport type NodeDetailsOverride = {\n /**\n * Endpoint configuration. This allows for overriding the default SSS node endpoints.\n *\n * - **To use FND-resolved node URLs with a custom path:** Provide a single `string`\n * representing the path to be appended to each FND-resolved node URL.\n * For example, `'/sss-toprf'` will transform FND URLs like `https://node1.example.com`\n * into `https://node1.example.com/sss-toprf`.\n *\n * - **To use a completely custom set of node URLs (bypassing FND resolution):**\n * Provide an array of `string[]` where each string is a complete endpoint URL.\n * For example, `['https://custom-node1.com/custom-path', 'https://custom-node2.com/custom-path']`.\n *\n * If left `undefined`, the SDK will use the default FND-resolved SSS endpoints directly.\n */\n endpoints?: string | string[];\n /**\n * Array of node indexes. Must match network node count if provided.\n */\n indexes?: number[];\n /**\n * Array of node public keys. Must match network node count if provided.\n */\n pubKeys?: INodePub[];\n};\n\n/**\n * AuthenticateParams - The parameters for the authenticate request.\n *\n * idTokens - The idTokens to be used for the authenticate request.\n *\n * authConnectionId - The auth connection name to be used for the authenticate request.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * userId - The user id of the user to be used for the authenticate request.\n *\n * groupedAuthConnectionParams - Optional groupedAuthConnectionParams to be used for the authenticate request.\n * You can pass this to use aggregate verifier.\n */\nexport type AuthenticateParams = {\n // for now we only support one idToken, in future we will support multiple to remove commitment call\n // so leaving it as an array for future use\n idTokens: string[];\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * NodeAuthToken - An authentication token and the node details.\n *\n * authToken - The authentication token.\n *\n * nodeIndex - The index of the node that issued the token.\n *\n * nodePubKey - The public key of the node that issued the token.\n */\nexport type NodeAuthToken = {\n authToken: string;\n nodeIndex: number;\n nodePubKey: string;\n};\n/**\n * nodeAuthTokens - An array of authentication tokens issued by the nodes.\n */\nexport type NodeAuthTokens = NodeAuthToken[];\n\n/**\n * nodeAuthTokens - An array of authentication tokens issued by the nodes.\n *\n * isNewUser - Indicates if the user has completed the key setup process or not.\n * if `true` then the user hasn't completed the social + password setup process.\n * if `false` then the user has completed the social + password setup process.\n */\nexport type AuthenticateResult = {\n nodeAuthTokens: NodeAuthTokens;\n isNewUser: boolean;\n};\n\n/**\n * CreateLocalKeyParams - The parameters for creating an OPRF encryption key locally.\n *\n * password - The password of the user.\n *\n * oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n */\nexport type CreateLocalKeyParams = {\n password: string;\n oprfKey?: bigint;\n};\n\n/**\n * CreateLocalKeyResult - The result of creating an encryption key.\n *\n * oprfKey - The OPRF key which is used to for local OPRF evaluation.\n *\n * seed - The seed which is used to derive the authentication and encryption keys.\n *\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n *\n * encKey - The encryption key which is used to encrypt the secret data.\n */\nexport type CreateLocalKeyResult = {\n oprfKey: bigint;\n seed: Uint8Array;\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\n/**\n * PersistLocalKeyParams - The parameters for persisting an OPRF key's shares to the servers.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * oprfKey - The OPRF key which is used to for local OPRF evaluation.\n *\n * authPubKey - The authentication public key which is used to authenticate the write request to the metadata store.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * keyShareIndex - Optional key share index to be persisted.\n *\n * oldAuthKeyPair - Optional authentication key pair to be used for key change flow.\n */\nexport type PersistLocalKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n oprfKey: bigint;\n authPubKey: SEC1EncodedPublicKey;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n keyShareIndex?: number;\n oldAuthKeyPair?: KeyPair;\n};\n\n/**\n * CreateEncryptionKeyParams - The parameters for creating an encryption key.\n *\n * authConnectionId - The auth connection name of the user.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * nodeAuthTokens - The tokens issued by the nodes on verifying the idTokens.\n *\n * password - The password of the user.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n */\nexport type CreateEncryptionKeyParams = {\n authConnectionId: string;\n userId: string;\n nodeAuthTokens: NodeAuthTokens;\n password: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * CreateEncryptionKeyResult - The result of creating an encryption key.\n *\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n *\n * encKey - The encryption key which is used to encrypt the secret data.\n *\n * pwEncKey - The password encryption key which is used to encrypt the password.\n */\nexport type CreateEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\nexport type BaseAddSecretDataItemParams<\n SecretDataType,\n EncKeyType = Uint8Array,\n> = {\n /**\n * The secret data to be stored.\n */\n secretData: SecretDataType;\n\n /**\n * The encryption key to be used to encrypt the secret data.\n */\n encKey: EncKeyType;\n\n /**\n * The authentication key to be used to provide valid signature for storing the secret data.\n */\n authKeyPair: KeyPair;\n};\n\n/**\n * encKey - The encryption key to be used to encrypt the secret data before storing it.\n *\n * authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n *\n * secretData - The secret data to be stored.\n */\nexport type AddSecretDataItemParams = BaseAddSecretDataItemParams<Uint8Array>;\n\nexport type BatchAddSecretDataItemParams = BaseAddSecretDataItemParams<\n Uint8Array[],\n Uint8Array | Uint8Array[]\n>;\n\n/**\n * RecoverEncryptionKeyParams - The parameters for recovering the encryption key.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * password - The password of the user.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n */\nexport type RecoverEncryptionKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n password: string;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n * encKey - The encryption key which is used to encrypt the secret data.\n * keyShareIndex - The index of the key shares on the nodes, used for key change operations.\n * rateLimitResetResult - A promise that resolves when the rate limit is reset.\n */\nexport type RecoverEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n keyShareIndex: number;\n rateLimitResetResult: Promise<void>;\n};\n\n/**\n * Parameters for changing the encryption key.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * oldEncKey - The old encryption key of the user.\n *\n * oldAuthKeyPair - The old authentication key pair of the user.\n *\n * newKeyShareIndex - The key share index to be used for the new key.\n *\n * newPassword - Optional new password of the user, either this or pregeneratedOprfKey is required.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * pregeneratedOprfKey - Optional pregenerated OPRF key to be used for the key change, if not provided, a new key will be generated from the new password.\n */\nexport type ChangeEncryptionKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n authConnectionId: string;\n userId: string;\n oldEncKey: Uint8Array;\n oldPwEncKey: Uint8Array;\n oldAuthKeyPair: KeyPair;\n newKeyShareIndex: number;\n newPassword?: string;\n groupedAuthConnectionId?: string;\n pregeneratedOprfKey?: CreateLocalKeyResult;\n};\n\n/**\n * authKeyPair - The new authentication key pair which is used to authenticate the user.\n * encKey - The new encryption key which is used to encrypt the secret data.\n */\nexport type ChangeEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\n/**\n * keyPair - The encryption/decryption key pair which is used to decrypt the secret data.\n */\nexport type FetchAllSecretDataParams = {\n /**\n * The decryption key to be used to decrypt the secret data.\n */\n decKey: Uint8Array;\n\n /**\n * The authentication key to be used to provide valid signature for fetching the secret data.\n */\n authKeyPair: KeyPair;\n};\n\n/**\n * Proof that the user owns the old key when changing to a new password/key\n * Contains a signature created with the old private key on a timestamp and new key share data.\n */\nexport type KeyChangeProof = {\n oldKeySignature: string;\n signatureTimestamp: number;\n};\n\n/**\n * FetchAuthPubKeyParams - The parameters for fetching the authentication public key.\n *\n * nodeAuthTokens - Auth tokens issued by nodes.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * userId - The user id of the user issued by authentication service.\n */\nexport type FetchAuthPubKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n authConnectionId: string;\n groupedAuthConnectionId?: string;\n userId: string;\n};\n\nexport type FetchAuthPubKeyResult = {\n authPubKey: SEC1EncodedPublicKey;\n};\n\nexport type RecoverPwEncKeyParams = {\n targetAuthPubKey: SEC1EncodedPublicKey;\n curPwEncKey: Uint8Array;\n curAuthKeyPair: KeyPair;\n maxPwChainLength?: number;\n};\n\nexport type RecoverPwEncKeyResult = {\n pwEncKey: Uint8Array;\n};\n\nexport type IToprfSecureBackup = {\n authenticate: (params: AuthenticateParams) => Promise<AuthenticateResult>;\n\n /**\n * This function locally creates an OPRF and encryption key without storing it at the key\n * management service. It returns the OPRF key, derives the corresponding key\n * seed, authentication key pair and encryption key.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.password - New password of the user.\n * @param params.oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n *\n * @returns A promise that resolves with the encryption key.\n */\n createLocalKey: (\n params: CreateLocalKeyParams,\n ) => Promise<CreateLocalKeyResult>;\n\n /**\n * This function persists an locally created OPRF key's shares to the servers.\n *\n * @param params - The parameters for persisting an OPRF key's shares.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.oprfKey - The OPRF key to be persisted.\n * @param params.authKeyPair - The authentication key pair which is used to authenticate the write request to the metadata store.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.keyShareIndex - The key share index to be persisted. Required only during key change, defaults to FIRST_KEY_INDEX for first-time storage.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user. Required only during key change, not needed for first-time storage.\n * @returns A promise that resolves when the OPRF key's shares are persisted.\n */\n persistLocalKey: (params: PersistLocalKeyParams) => Promise<void>;\n\n createAndPersistEncKey: (\n params: CreateEncryptionKeyParams,\n ) => Promise<CreateEncryptionKeyResult>;\n\n recoverEncKey: (\n params: RecoverEncryptionKeyParams,\n ) => Promise<RecoverEncryptionKeyResult>;\n\n /**\n * This function replaces the existing encryption key with a new one and copies the secret data of existing encryption key to the new one.\n *\n * @param params - The parameters for changing the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.newPassword - The new password of the user.\n * @param params.keyPair - The current encryption key of the user.\n *\n * @returns A promise that resolves with the new encryption key.\n */\n changeEncKey: (\n params: ChangeEncryptionKeyParams,\n ) => Promise<ChangeEncryptionKeyResult>;\n\n /**\n * This function encrypts the secret data using the encryption key and stores it nodes metadata store in encrypted form.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n * @param params.secretData - The array of secret data to be registered.\n *\n * @returns A promise that resolves when the secret data is registered.\n */\n addSecretDataItem: (params: AddSecretDataItemParams) => Promise<void>;\n\n /**\n * This function encrypts the array of secret data using the encryption key and stores it in the metadata store in encrypted form as a batch.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n * @param params.secretData - The array of secret data to be stored.\n *\n * @returns A promise that resolves when the secret data is stored.\n */\n batchAddSecretDataItems: (\n params: BatchAddSecretDataItemParams,\n ) => Promise<void>;\n\n /**\n * This function fetches all secret data items associated with the given\n * auth pub key, decrypts, and returns them.\n *\n * @param params - The parameters for fetching the secret data.\n * @param params.decKey - The decryption key to be used to decrypt the secret data.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for fetching the secret data.\n *\n * @returns {Uint8Array[]} A promise that resolves with the array of decrypted secret data.\n */\n fetchAllSecretDataItems: (\n params: FetchAllSecretDataParams,\n ) => Promise<Uint8Array[]>;\n\n /**\n * This function fetches the authentication public key.\n *\n * @param params - The parameters for fetching the authentication public key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.userId - The user id of the user issued by authentication service.\n *\n * @returns A promise that resolves with the authentication public key.\n */\n fetchAuthPubKey: (\n params: FetchAuthPubKeyParams,\n ) => Promise<FetchAuthPubKeyResult>;\n\n /**\n * This function recovers the password encryption key of the user.\n *\n * @param params - The parameters for recovering the password encryption key.\n * @param params.targetAuthPubKey - The public key of the target encryption key.\n * @param params.curPwEncKey - The current password encryption key of the user.\n * @param params.curAuthKeyPair - The current authentication key pair of the user.\n *\n * @returns A promise that resolves to the password encryption key of the user.\n */\n recoverPwEncKey: (\n params: RecoverPwEncKeyParams,\n ) => Promise<RecoverPwEncKeyResult>;\n};\n\n/**\n * Base payload structure for metadata request\n */\nexport type IBaseMetadataRequestBody = {\n /**\n * The feature name related to the secret data\n */\n feature: string;\n /**\n * The public key of the user\n */\n pubKey: string;\n /**\n * The Unix timestamp when the request payload is created along with the signature.\n *\n */\n timestamp: string;\n};\n\n/**\n * The array of secret data to be stored in batch request\n */\nexport type IBatchAddData = {\n /**\n * The base64-encoded string of the secret data\n */\n data: string;\n /**\n * The version of the Metadata Store\n */\n version?: string;\n}[];\n\n/**\n * Payload structure for storing secret data\n */\nexport type IBaseAddSecretDataRequestBody<DataType> =\n IBaseMetadataRequestBody & {\n /**\n * The authentication token of the user issued by authentication service.\n * this token is also known as `metadataAccessToken`.\n */\n authToken?: string;\n /**\n * The secret data to be stored.\n *\n * For storing the single secret data, the data should be base64-encoded string.\n *\n * @example\n * ```ts\n * const data = Buffer.from('SECRET_DATA').toString('base64');\n * ```\n *\n * For storing the batch of secret data, the data should be an array of `IBatchAddData`.\n *\n * @example\n * ```ts\n * const data = [\n * { data: Buffer.from('SECRET_DATA_1').toString('base64') },\n * { data: Buffer.from('SECRET_DATA_2').toString('base64') },\n * ];\n * ```\n */\n data: DataType;\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(data, feature, authToken, timestamp))\n */\n signature: string;\n };\n\n/**\n * Payload structure for storing secret data for single secret data\n */\nexport type IAddSecretDataRequestBody =\n IBaseAddSecretDataRequestBody<string> & {\n /**\n * The version of the secret data\n */\n version?: string;\n /**\n * The item id to be used for storing the secret data.\n */\n itemId?: string;\n };\n\n/**\n * Payload structure for storing secret data in batch request\n */\nexport type IBatchAddSecretDataRequestBody =\n IBaseAddSecretDataRequestBody<IBatchAddData>;\n\n/**\n * Payload structure for fetching secret data\n */\nexport type IGetSecretDataRequestBody = IBaseMetadataRequestBody & {\n /**\n * The authentication token of the user issued by the SSS services\n */\n authToken?: string;\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(feature, authToken, timestamp))\n */\n signature: string;\n /**\n * The item id to be used for fetching the secret data.\n */\n itemId?: string;\n};\n\n/**\n * Payload structure for acquiring/releasing a lock on the metadata\n */\nexport type IMetadataLockRequestBody = {\n /**\n * The public key of the user\n */\n key: string;\n /**\n * The Unix timestamp when the request payload is created along with the signature.\n *\n */\n data: {\n timestamp: number;\n };\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(feature, authToken, timestamp))\n */\n signature: string;\n /**\n * The lock id to be released.\n */\n id?: string | undefined;\n};\n\n/**\n * FetchMetadataAccessCreds - The function to fetch the metadata access credentials.\n *\n * @returns The metadata access credentials.\n */\nexport type FetchMetadataAccessCreds = () => Promise<{\n metadataAccessToken: string;\n}>;\n"]}
{"version":3,"file":"interfaces.mjs","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import type { INodePub } from '@toruslabs/constants';\n\n/**\n * SEC1 encoded public key\n */\nexport type SEC1EncodedPublicKey = Uint8Array;\n\n/**\n * KeyPair - The encryption/decryption private and public key pair.\n *\n * sk - The decryption private key in bigint format.\n *\n * pk - The encryption public key in SEC1 encoded format.\n */\nexport type KeyPair = {\n sk: bigint;\n pk: SEC1EncodedPublicKey;\n};\n\n/**\n * Optional override for node details.\n */\nexport type NodeDetailsOverride = {\n /**\n * Endpoint configuration. This allows for overriding the default SSS node endpoints.\n *\n * - **To use FND-resolved node URLs with a custom path:** Provide a single `string`\n * representing the path to be appended to each FND-resolved node URL.\n * For example, `'/sss-toprf'` will transform FND URLs like `https://node1.example.com`\n * into `https://node1.example.com/sss-toprf`.\n *\n * - **To use a completely custom set of node URLs (bypassing FND resolution):**\n * Provide an array of `string[]` where each string is a complete endpoint URL.\n * For example, `['https://custom-node1.com/custom-path', 'https://custom-node2.com/custom-path']`.\n *\n * If left `undefined`, the SDK will use the default FND-resolved SSS endpoints directly.\n */\n endpoints?: string | string[];\n /**\n * Array of node indexes. Must match network node count if provided.\n */\n indexes?: number[];\n /**\n * Array of node public keys. Must match network node count if provided.\n */\n pubKeys?: INodePub[];\n};\n\n/**\n * AuthenticateParams - The parameters for the authenticate request.\n *\n * idTokens - The idTokens to be used for the authenticate request.\n *\n * authConnectionId - The auth connection name to be used for the authenticate request.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * userId - The user id of the user to be used for the authenticate request.\n *\n * groupedAuthConnectionParams - Optional groupedAuthConnectionParams to be used for the authenticate request.\n * You can pass this to use aggregate verifier.\n */\nexport type AuthenticateParams = {\n // for now we only support one idToken, in future we will support multiple to remove commitment call\n // so leaving it as an array for future use\n idTokens: string[];\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * NodeAuthToken - An authentication token and the node details.\n *\n * authToken - The authentication token.\n *\n * nodeIndex - The index of the node that issued the token.\n *\n * nodePubKey - The public key of the node that issued the token.\n */\nexport type NodeAuthToken = {\n authToken: string;\n nodeIndex: number;\n nodePubKey: string;\n};\n/**\n * nodeAuthTokens - An array of authentication tokens issued by the nodes.\n */\nexport type NodeAuthTokens = NodeAuthToken[];\n\n/**\n * nodeAuthTokens - An array of authentication tokens issued by the nodes.\n *\n * isNewUser - Indicates if the user has completed the key setup process or not.\n * if `true` then the user hasn't completed the social + password setup process.\n * if `false` then the user has completed the social + password setup process.\n */\nexport type AuthenticateResult = {\n nodeAuthTokens: NodeAuthTokens;\n isNewUser: boolean;\n};\n\n/**\n * CreateLocalKeyParams - The parameters for creating an OPRF encryption key locally.\n *\n * password - The password of the user.\n *\n * oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n */\nexport type CreateLocalKeyParams = {\n password: string;\n oprfKey?: bigint;\n};\n\n/**\n * CreateLocalKeyResult - The result of creating an encryption key.\n *\n * oprfKey - The OPRF key which is used to for local OPRF evaluation.\n *\n * seed - The seed which is used to derive the authentication and encryption keys.\n *\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n *\n * encKey - The encryption key which is used to encrypt the secret data.\n */\nexport type CreateLocalKeyResult = {\n oprfKey: bigint;\n seed: Uint8Array;\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\n/**\n * PersistLocalKeyParams - The parameters for persisting an OPRF key's shares to the servers.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * oprfKey - The OPRF key which is used to for local OPRF evaluation.\n *\n * authPubKey - The authentication public key which is used to authenticate the write request to the metadata store.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * keyShareIndex - Optional key share index to be persisted.\n *\n * oldAuthKeyPair - Optional authentication key pair to be used for key change flow.\n */\nexport type PersistLocalKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n oprfKey: bigint;\n authPubKey: SEC1EncodedPublicKey;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n keyShareIndex?: number;\n oldAuthKeyPair?: KeyPair;\n};\n\n/**\n * CreateEncryptionKeyParams - The parameters for creating an encryption key.\n *\n * authConnectionId - The auth connection name of the user.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * nodeAuthTokens - The tokens issued by the nodes on verifying the idTokens.\n *\n * password - The password of the user.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n */\nexport type CreateEncryptionKeyParams = {\n authConnectionId: string;\n userId: string;\n nodeAuthTokens: NodeAuthTokens;\n password: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * CreateEncryptionKeyResult - The result of creating an encryption key.\n *\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n *\n * encKey - The encryption key which is used to encrypt the secret data.\n *\n * pwEncKey - The password encryption key which is used to encrypt the password.\n */\nexport type CreateEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\nexport type BaseAddSecretDataItemParams<\n SecretDataType,\n EncKeyType = Uint8Array,\n> = {\n /**\n * The secret data to be stored.\n */\n secretData: SecretDataType;\n\n /**\n * The encryption key to be used to encrypt the secret data.\n */\n encKey: EncKeyType;\n\n /**\n * The authentication key to be used to provide valid signature for storing the secret data.\n */\n authKeyPair: KeyPair;\n};\n\n/**\n * encKey - The encryption key to be used to encrypt the secret data before storing it.\n *\n * authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n *\n * secretData - The secret data to be stored.\n */\nexport type AddSecretDataItemParams = BaseAddSecretDataItemParams<Uint8Array>;\n\nexport type BatchAddSecretDataItemParams = BaseAddSecretDataItemParams<\n Uint8Array[],\n Uint8Array | Uint8Array[]\n>;\n\n/**\n * RecoverEncryptionKeyParams - The parameters for recovering the encryption key.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * password - The password of the user.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n */\nexport type RecoverEncryptionKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n password: string;\n authConnectionId: string;\n userId: string;\n groupedAuthConnectionId?: string;\n};\n\n/**\n * authKeyPair - The authentication key pair which is used to authenticate the user.\n * encKey - The encryption key which is used to encrypt the secret data.\n * keyShareIndex - The index of the key shares on the nodes, used for key change operations.\n * rateLimitResetResult - A promise that resolves when the rate limit is reset.\n */\nexport type RecoverEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n keyShareIndex: number;\n rateLimitResetResult: Promise<void>;\n};\n\n/**\n * Parameters for changing the encryption key.\n *\n * nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * userId - The user id of the user issued by authentication service.\n *\n * oldEncKey - The old encryption key of the user.\n *\n * oldAuthKeyPair - The old authentication key pair of the user.\n *\n * newKeyShareIndex - The key share index to be used for the new key.\n *\n * newPassword - Optional new password of the user, either this or pregeneratedOprfKey is required.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * pregeneratedOprfKey - Optional pregenerated OPRF key to be used for the key change, if not provided, a new key will be generated from the new password.\n */\nexport type ChangeEncryptionKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n authConnectionId: string;\n userId: string;\n oldEncKey: Uint8Array;\n oldPwEncKey: Uint8Array;\n oldAuthKeyPair: KeyPair;\n newKeyShareIndex: number;\n newPassword?: string;\n groupedAuthConnectionId?: string;\n pregeneratedOprfKey?: CreateLocalKeyResult;\n};\n\n/**\n * authKeyPair - The new authentication key pair which is used to authenticate the user.\n * encKey - The new encryption key which is used to encrypt the secret data.\n */\nexport type ChangeEncryptionKeyResult = {\n authKeyPair: KeyPair;\n encKey: Uint8Array;\n pwEncKey: Uint8Array;\n};\n\n/**\n * keyPair - The encryption/decryption key pair which is used to decrypt the secret data.\n */\nexport type FetchAllSecretDataParams = {\n /**\n * The decryption key to be used to decrypt the secret data.\n */\n decKey: Uint8Array;\n\n /**\n * The authentication key to be used to provide valid signature for fetching the secret data.\n */\n authKeyPair: KeyPair;\n};\n\n/**\n * Proof that the user owns the old key when changing to a new password/key\n * Contains a signature created with the old private key on a timestamp and new key share data.\n */\nexport type KeyChangeProof = {\n oldKeySignature: string;\n signatureTimestamp: number;\n};\n\n/**\n * FetchAuthPubKeyParams - The parameters for fetching the authentication public key.\n *\n * nodeAuthTokens - Auth tokens issued by nodes.\n *\n * authConnectionId - The auth connection name used for authentication.\n *\n * groupedAuthConnectionId - Optional grouped auth connection id to be used for the authenticate request with aggregate (single id) verifier.\n *\n * userId - The user id of the user issued by authentication service.\n */\nexport type FetchAuthPubKeyParams = {\n nodeAuthTokens: NodeAuthTokens;\n authConnectionId: string;\n groupedAuthConnectionId?: string;\n userId: string;\n};\n\nexport type FetchAuthPubKeyResult = {\n authPubKey: SEC1EncodedPublicKey;\n keyIndex: number;\n};\n\nexport type RecoverPwEncKeyParams = {\n targetAuthPubKey: SEC1EncodedPublicKey;\n curPwEncKey: Uint8Array;\n curAuthKeyPair: KeyPair;\n maxPwChainLength?: number;\n};\n\nexport type RecoverPwEncKeyResult = {\n pwEncKey: Uint8Array;\n};\n\nexport type IToprfSecureBackup = {\n authenticate: (params: AuthenticateParams) => Promise<AuthenticateResult>;\n\n /**\n * This function locally creates an OPRF and encryption key without storing it at the key\n * management service. It returns the OPRF key, derives the corresponding key\n * seed, authentication key pair and encryption key.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.password - New password of the user.\n * @param params.oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n *\n * @returns A promise that resolves with the encryption key.\n */\n createLocalKey: (\n params: CreateLocalKeyParams,\n ) => Promise<CreateLocalKeyResult>;\n\n /**\n * This function persists an locally created OPRF key's shares to the servers.\n *\n * @param params - The parameters for persisting an OPRF key's shares.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.oprfKey - The OPRF key to be persisted.\n * @param params.authKeyPair - The authentication key pair which is used to authenticate the write request to the metadata store.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.keyShareIndex - The key share index to be persisted. Required only during key change, defaults to FIRST_KEY_INDEX for first-time storage.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user. Required only during key change, not needed for first-time storage.\n * @returns A promise that resolves when the OPRF key's shares are persisted.\n */\n persistLocalKey: (params: PersistLocalKeyParams) => Promise<void>;\n\n createAndPersistEncKey: (\n params: CreateEncryptionKeyParams,\n ) => Promise<CreateEncryptionKeyResult>;\n\n recoverEncKey: (\n params: RecoverEncryptionKeyParams,\n ) => Promise<RecoverEncryptionKeyResult>;\n\n /**\n * This function replaces the existing encryption key with a new one and copies the secret data of existing encryption key to the new one.\n *\n * @param params - The parameters for changing the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.newPassword - The new password of the user.\n * @param params.keyPair - The current encryption key of the user.\n *\n * @returns A promise that resolves with the new encryption key.\n */\n changeEncKey: (\n params: ChangeEncryptionKeyParams,\n ) => Promise<ChangeEncryptionKeyResult>;\n\n /**\n * This function encrypts the secret data using the encryption key and stores it nodes metadata store in encrypted form.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n * @param params.secretData - The array of secret data to be registered.\n *\n * @returns A promise that resolves when the secret data is registered.\n */\n addSecretDataItem: (params: AddSecretDataItemParams) => Promise<void>;\n\n /**\n * This function encrypts the array of secret data using the encryption key and stores it in the metadata store in encrypted form as a batch.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n * @param params.secretData - The array of secret data to be stored.\n *\n * @returns A promise that resolves when the secret data is stored.\n */\n batchAddSecretDataItems: (\n params: BatchAddSecretDataItemParams,\n ) => Promise<void>;\n\n /**\n * This function fetches all secret data items associated with the given\n * auth pub key, decrypts, and returns them.\n *\n * @param params - The parameters for fetching the secret data.\n * @param params.decKey - The decryption key to be used to decrypt the secret data.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for fetching the secret data.\n *\n * @returns {Uint8Array[]} A promise that resolves with the array of decrypted secret data.\n */\n fetchAllSecretDataItems: (\n params: FetchAllSecretDataParams,\n ) => Promise<Uint8Array[]>;\n\n /**\n * This function fetches the authentication public key.\n *\n * @param params - The parameters for fetching the authentication public key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.userId - The user id of the user issued by authentication service.\n *\n * @returns A promise that resolves with the authentication public key.\n */\n fetchAuthPubKey: (\n params: FetchAuthPubKeyParams,\n ) => Promise<FetchAuthPubKeyResult>;\n\n /**\n * This function recovers the password encryption key of the user.\n *\n * @param params - The parameters for recovering the password encryption key.\n * @param params.targetAuthPubKey - The public key of the target encryption key.\n * @param params.curPwEncKey - The current password encryption key of the user.\n * @param params.curAuthKeyPair - The current authentication key pair of the user.\n *\n * @returns A promise that resolves to the password encryption key of the user.\n */\n recoverPwEncKey: (\n params: RecoverPwEncKeyParams,\n ) => Promise<RecoverPwEncKeyResult>;\n};\n\n/**\n * Base payload structure for metadata request\n */\nexport type IBaseMetadataRequestBody = {\n /**\n * The feature name related to the secret data\n */\n feature: string;\n /**\n * The public key of the user\n */\n pubKey: string;\n /**\n * The Unix timestamp when the request payload is created along with the signature.\n *\n */\n timestamp: string;\n};\n\n/**\n * The array of secret data to be stored in batch request\n */\nexport type IBatchAddData = {\n /**\n * The base64-encoded string of the secret data\n */\n data: string;\n /**\n * The version of the Metadata Store\n */\n version?: string;\n}[];\n\n/**\n * Payload structure for storing secret data\n */\nexport type IBaseAddSecretDataRequestBody<DataType> =\n IBaseMetadataRequestBody & {\n /**\n * The authentication token of the user issued by authentication service.\n * this token is also known as `metadataAccessToken`.\n */\n authToken?: string;\n /**\n * The secret data to be stored.\n *\n * For storing the single secret data, the data should be base64-encoded string.\n *\n * @example\n * ```ts\n * const data = Buffer.from('SECRET_DATA').toString('base64');\n * ```\n *\n * For storing the batch of secret data, the data should be an array of `IBatchAddData`.\n *\n * @example\n * ```ts\n * const data = [\n * { data: Buffer.from('SECRET_DATA_1').toString('base64') },\n * { data: Buffer.from('SECRET_DATA_2').toString('base64') },\n * ];\n * ```\n */\n data: DataType;\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(data, feature, authToken, timestamp))\n */\n signature: string;\n };\n\n/**\n * Payload structure for storing secret data for single secret data\n */\nexport type IAddSecretDataRequestBody =\n IBaseAddSecretDataRequestBody<string> & {\n /**\n * The version of the secret data\n */\n version?: string;\n /**\n * The item id to be used for storing the secret data.\n */\n itemId?: string;\n };\n\n/**\n * Payload structure for storing secret data in batch request\n */\nexport type IBatchAddSecretDataRequestBody =\n IBaseAddSecretDataRequestBody<IBatchAddData>;\n\n/**\n * Payload structure for fetching secret data\n */\nexport type IGetSecretDataRequestBody = IBaseMetadataRequestBody & {\n /**\n * The authentication token of the user issued by the SSS services\n */\n authToken?: string;\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(feature, authToken, timestamp))\n */\n signature: string;\n /**\n * The item id to be used for fetching the secret data.\n */\n itemId?: string;\n};\n\n/**\n * Payload structure for acquiring/releasing a lock on the metadata\n */\nexport type IMetadataLockRequestBody = {\n /**\n * The public key of the user\n */\n key: string;\n /**\n * The Unix timestamp when the request payload is created along with the signature.\n *\n */\n data: {\n timestamp: number;\n };\n /**\n * The signature produced by signing the payload (without pubKey field) using the user's private key.\n *\n * Sample signature: sign(keccak256(feature, authToken, timestamp))\n */\n signature: string;\n /**\n * The lock id to be released.\n */\n id?: string | undefined;\n};\n\n/**\n * FetchMetadataAccessCreds - The function to fetch the metadata access credentials.\n *\n * @returns The metadata access credentials.\n */\nexport type FetchMetadataAccessCreds = () => Promise<{\n metadataAccessToken: string;\n}>;\n"]}

@@ -1,1 +0,1 @@

{"version":3,"file":"jrpcInterfaces.cjs","sourceRoot":"","sources":["../src/jrpcInterfaces.ts"],"names":[],"mappings":"","sourcesContent":["import type { JRPCResponse, JRPCRequest } from '@metamask/auth-network-utils';\n\nimport type { KeyChangeProof } from './interfaces';\n\nexport type CommitmentJRPCRequestParams = {\n tokenCommitment: string;\n verifier: string;\n tempPubKeyX: string;\n tempPubKeyY: string;\n};\n\nexport type CommitmentJRPCRequest = JRPCRequest<CommitmentJRPCRequestParams>;\n\nexport type CommitmentRequestResult = {\n signature: string;\n data: string;\n nodePubX: string;\n nodePubY: string;\n nodeIndex: number;\n};\n\nexport type CommitmentJRPCResponse = JRPCResponse<\n CommitmentRequestResult | undefined\n>;\n\nexport type SingleIdVerifierJrpcParams = {\n subVerifierAuthParams: {\n subVerifierIdToken: string;\n subVerifier: string;\n }[];\n};\n\nexport type AuthJRPCRequestParams = {\n authData: {\n authenticationContext: {\n idToken: string;\n verifier: string;\n verifierId: string;\n };\n singleIdVerifierParams?: SingleIdVerifierJrpcParams;\n extraOauthParams?: Record<string, string | number | boolean>;\n };\n commitmentSignatures: CommitmentRequestResult[];\n clientTime: string;\n};\n\nexport type AuthJRPCRequest = JRPCRequest<AuthJRPCRequestParams>;\n\nexport type AuthRequestResult = {\n authToken: string;\n nodeIndex: number;\n nodePubKey: string;\n pubKey: string;\n keyIndex: number;\n};\n\nexport type AuthJRPCResponse = JRPCResponse<AuthRequestResult>;\n\nexport type BaseShareImportItem = {\n encryptedAuthToken: string;\n encryptedShare: string;\n keyShareIndex: number;\n nodeIndex: number;\n sssEndpoint: string;\n};\n\nexport type NewUserShareImportItem = BaseShareImportItem;\n\nexport type KeyChangeShareImportItem = BaseShareImportItem & KeyChangeProof;\n\nexport type ShareImportItem<\n ShareType extends 'standard' | 'keyChange' = 'standard',\n> = ShareType extends 'standard'\n ? NewUserShareImportItem\n : KeyChangeShareImportItem;\n\nexport type StoreKeySharesJRPCRequestParams = {\n verifier: string;\n verifierId: string;\n pubKey: string;\n shareImportItems: ShareImportItem[];\n};\n\nexport type StoreKeySharesJRPCRequest =\n JRPCRequest<StoreKeySharesJRPCRequestParams>;\n\nexport type StoreKeySharesJRPCResponse = JRPCResponse<null>;\n\nexport type ResetRateLimitJRPCRequestParams = {\n authToken: string;\n signature: string;\n signedData: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type ResetRateLimitJRPCRequest =\n JRPCRequest<ResetRateLimitJRPCRequestParams>;\n\nexport type ResetRateLimitJRPCResponse = JRPCResponse<boolean>;\n\nexport type ToprfEvalJRPCRequestParams = {\n authToken: string;\n shareCoefficient: string;\n blindedInputX: string;\n blindedInputY: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type ToprfEvalJRPCRequest = JRPCRequest<ToprfEvalJRPCRequestParams>;\n\nexport type ToprfEvalResult = {\n blindedOutputX: string;\n blindedOutputY: string;\n nodeIndex: number;\n pubKey: string;\n keyShareIndex: number;\n\n /**\n * Number of eval requests made for this server.\n *\n * Upon successful encryption key derivation,\n * the reset request will be made to the server and the count will be reset to 0.\n */\n guessCount: number;\n\n /**\n * Time in seconds before the next guess is allowed to the server.\n *\n * Upon successful encryption key derivation,\n * the reset request will be made to the server and the time will be reset to 0.\n */\n lockTimeSeconds: number;\n};\n\nexport type ToprfEvalJRPCResponse = JRPCResponse<ToprfEvalResult>;\n\nexport type GetPubKeyJRPCRequestParams = {\n authToken: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type GetPubKeyJRPCRequest = JRPCRequest<GetPubKeyJRPCRequestParams>;\n\nexport type GetPubKeyResult = {\n pubKey: string;\n};\n\nexport type GetPubKeyJRPCResponse = JRPCResponse<GetPubKeyResult>;\n"]}
{"version":3,"file":"jrpcInterfaces.cjs","sourceRoot":"","sources":["../src/jrpcInterfaces.ts"],"names":[],"mappings":"","sourcesContent":["import type { JRPCResponse, JRPCRequest } from '@metamask/auth-network-utils';\n\nimport type { KeyChangeProof } from './interfaces';\n\nexport type CommitmentJRPCRequestParams = {\n tokenCommitment: string;\n verifier: string;\n tempPubKeyX: string;\n tempPubKeyY: string;\n};\n\nexport type CommitmentJRPCRequest = JRPCRequest<CommitmentJRPCRequestParams>;\n\nexport type CommitmentRequestResult = {\n signature: string;\n data: string;\n nodePubX: string;\n nodePubY: string;\n nodeIndex: number;\n};\n\nexport type CommitmentJRPCResponse = JRPCResponse<\n CommitmentRequestResult | undefined\n>;\n\nexport type SingleIdVerifierJrpcParams = {\n subVerifierAuthParams: {\n subVerifierIdToken: string;\n subVerifier: string;\n }[];\n};\n\nexport type AuthJRPCRequestParams = {\n authData: {\n authenticationContext: {\n idToken: string;\n verifier: string;\n verifierId: string;\n };\n singleIdVerifierParams?: SingleIdVerifierJrpcParams;\n extraOauthParams?: Record<string, string | number | boolean>;\n };\n commitmentSignatures: CommitmentRequestResult[];\n clientTime: string;\n};\n\nexport type AuthJRPCRequest = JRPCRequest<AuthJRPCRequestParams>;\n\nexport type AuthRequestResult = {\n authToken: string;\n nodeIndex: number;\n nodePubKey: string;\n pubKey: string;\n keyIndex: number;\n};\n\nexport type AuthJRPCResponse = JRPCResponse<AuthRequestResult>;\n\nexport type BaseShareImportItem = {\n encryptedAuthToken: string;\n encryptedShare: string;\n keyShareIndex: number;\n nodeIndex: number;\n sssEndpoint: string;\n};\n\nexport type NewUserShareImportItem = BaseShareImportItem;\n\nexport type KeyChangeShareImportItem = BaseShareImportItem & KeyChangeProof;\n\nexport type ShareImportItem<\n ShareType extends 'standard' | 'keyChange' = 'standard',\n> = ShareType extends 'standard'\n ? NewUserShareImportItem\n : KeyChangeShareImportItem;\n\nexport type StoreKeySharesJRPCRequestParams = {\n verifier: string;\n verifierId: string;\n pubKey: string;\n shareImportItems: ShareImportItem[];\n};\n\nexport type StoreKeySharesJRPCRequest =\n JRPCRequest<StoreKeySharesJRPCRequestParams>;\n\nexport type StoreKeySharesJRPCResponse = JRPCResponse<null>;\n\nexport type ResetRateLimitJRPCRequestParams = {\n authToken: string;\n signature: string;\n signedData: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type ResetRateLimitJRPCRequest =\n JRPCRequest<ResetRateLimitJRPCRequestParams>;\n\nexport type ResetRateLimitJRPCResponse = JRPCResponse<boolean>;\n\nexport type ToprfEvalJRPCRequestParams = {\n authToken: string;\n shareCoefficient: string;\n blindedInputX: string;\n blindedInputY: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type ToprfEvalJRPCRequest = JRPCRequest<ToprfEvalJRPCRequestParams>;\n\nexport type ToprfEvalResult = {\n blindedOutputX: string;\n blindedOutputY: string;\n nodeIndex: number;\n pubKey: string;\n keyShareIndex: number;\n\n /**\n * Number of eval requests made for this server.\n *\n * Upon successful encryption key derivation,\n * the reset request will be made to the server and the count will be reset to 0.\n */\n guessCount: number;\n\n /**\n * Time in seconds before the next guess is allowed to the server.\n *\n * Upon successful encryption key derivation,\n * the reset request will be made to the server and the time will be reset to 0.\n */\n lockTimeSeconds: number;\n};\n\nexport type ToprfEvalJRPCResponse = JRPCResponse<ToprfEvalResult>;\n\nexport type GetPubKeyJRPCRequestParams = {\n authToken: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type GetPubKeyJRPCRequest = JRPCRequest<GetPubKeyJRPCRequestParams>;\n\nexport type GetPubKeyResult = {\n pubKey: string;\n keyIndex: number;\n};\n\nexport type GetPubKeyJRPCResponse = JRPCResponse<GetPubKeyResult>;\n"]}

@@ -112,4 +112,5 @@ import type { JRPCResponse, JRPCRequest } from "@metamask/auth-network-utils";

pubKey: string;
keyIndex: number;
};
export type GetPubKeyJRPCResponse = JRPCResponse<GetPubKeyResult>;
//# sourceMapp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;
};
export type GetPubKeyJRPCResponse = JRPCResponse<GetPubKeyResult>;
//# sourceMappingURL=jrpcInterfaces.d.mts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"jrpcInterfaces.d.mts","sourceRoot":"","sources":["../src/jrpcInterfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,qCAAqC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,yBAAqB;AAEnD,MAAM,MAAM,2BAA2B,GAAG;IACxC,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,WAAW,CAAC,2BAA2B,CAAC,CAAC;AAE7E,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,YAAY,CAC/C,uBAAuB,GAAG,SAAS,CACpC,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,qBAAqB,EAAE;QACrB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,WAAW,EAAE,MAAM,CAAC;KACrB,EAAE,CAAC;CACL,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,EAAE;QACR,qBAAqB,EAAE;YACrB,OAAO,EAAE,MAAM,CAAC;YAChB,QAAQ,EAAE,MAAM,CAAC;YACjB,UAAU,EAAE,MAAM,CAAC;SACpB,CAAC;QACF,sBAAsB,CAAC,EAAE,0BAA0B,CAAC;QACpD,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,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version":3,"file":"jrpcInterfaces.mjs","sourceRoot":"","sources":["../src/jrpcInterfaces.ts"],"names":[],"mappings":"","sourcesContent":["import type { JRPCResponse, JRPCRequest } from '@metamask/auth-network-utils';\n\nimport type { KeyChangeProof } from './interfaces';\n\nexport type CommitmentJRPCRequestParams = {\n tokenCommitment: string;\n verifier: string;\n tempPubKeyX: string;\n tempPubKeyY: string;\n};\n\nexport type CommitmentJRPCRequest = JRPCRequest<CommitmentJRPCRequestParams>;\n\nexport type CommitmentRequestResult = {\n signature: string;\n data: string;\n nodePubX: string;\n nodePubY: string;\n nodeIndex: number;\n};\n\nexport type CommitmentJRPCResponse = JRPCResponse<\n CommitmentRequestResult | undefined\n>;\n\nexport type SingleIdVerifierJrpcParams = {\n subVerifierAuthParams: {\n subVerifierIdToken: string;\n subVerifier: string;\n }[];\n};\n\nexport type AuthJRPCRequestParams = {\n authData: {\n authenticationContext: {\n idToken: string;\n verifier: string;\n verifierId: string;\n };\n singleIdVerifierParams?: SingleIdVerifierJrpcParams;\n extraOauthParams?: Record<string, string | number | boolean>;\n };\n commitmentSignatures: CommitmentRequestResult[];\n clientTime: string;\n};\n\nexport type AuthJRPCRequest = JRPCRequest<AuthJRPCRequestParams>;\n\nexport type AuthRequestResult = {\n authToken: string;\n nodeIndex: number;\n nodePubKey: string;\n pubKey: string;\n keyIndex: number;\n};\n\nexport type AuthJRPCResponse = JRPCResponse<AuthRequestResult>;\n\nexport type BaseShareImportItem = {\n encryptedAuthToken: string;\n encryptedShare: string;\n keyShareIndex: number;\n nodeIndex: number;\n sssEndpoint: string;\n};\n\nexport type NewUserShareImportItem = BaseShareImportItem;\n\nexport type KeyChangeShareImportItem = BaseShareImportItem & KeyChangeProof;\n\nexport type ShareImportItem<\n ShareType extends 'standard' | 'keyChange' = 'standard',\n> = ShareType extends 'standard'\n ? NewUserShareImportItem\n : KeyChangeShareImportItem;\n\nexport type StoreKeySharesJRPCRequestParams = {\n verifier: string;\n verifierId: string;\n pubKey: string;\n shareImportItems: ShareImportItem[];\n};\n\nexport type StoreKeySharesJRPCRequest =\n JRPCRequest<StoreKeySharesJRPCRequestParams>;\n\nexport type StoreKeySharesJRPCResponse = JRPCResponse<null>;\n\nexport type ResetRateLimitJRPCRequestParams = {\n authToken: string;\n signature: string;\n signedData: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type ResetRateLimitJRPCRequest =\n JRPCRequest<ResetRateLimitJRPCRequestParams>;\n\nexport type ResetRateLimitJRPCResponse = JRPCResponse<boolean>;\n\nexport type ToprfEvalJRPCRequestParams = {\n authToken: string;\n shareCoefficient: string;\n blindedInputX: string;\n blindedInputY: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type ToprfEvalJRPCRequest = JRPCRequest<ToprfEvalJRPCRequestParams>;\n\nexport type ToprfEvalResult = {\n blindedOutputX: string;\n blindedOutputY: string;\n nodeIndex: number;\n pubKey: string;\n keyShareIndex: number;\n\n /**\n * Number of eval requests made for this server.\n *\n * Upon successful encryption key derivation,\n * the reset request will be made to the server and the count will be reset to 0.\n */\n guessCount: number;\n\n /**\n * Time in seconds before the next guess is allowed to the server.\n *\n * Upon successful encryption key derivation,\n * the reset request will be made to the server and the time will be reset to 0.\n */\n lockTimeSeconds: number;\n};\n\nexport type ToprfEvalJRPCResponse = JRPCResponse<ToprfEvalResult>;\n\nexport type GetPubKeyJRPCRequestParams = {\n authToken: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type GetPubKeyJRPCRequest = JRPCRequest<GetPubKeyJRPCRequestParams>;\n\nexport type GetPubKeyResult = {\n pubKey: string;\n};\n\nexport type GetPubKeyJRPCResponse = JRPCResponse<GetPubKeyResult>;\n"]}
{"version":3,"file":"jrpcInterfaces.mjs","sourceRoot":"","sources":["../src/jrpcInterfaces.ts"],"names":[],"mappings":"","sourcesContent":["import type { JRPCResponse, JRPCRequest } from '@metamask/auth-network-utils';\n\nimport type { KeyChangeProof } from './interfaces';\n\nexport type CommitmentJRPCRequestParams = {\n tokenCommitment: string;\n verifier: string;\n tempPubKeyX: string;\n tempPubKeyY: string;\n};\n\nexport type CommitmentJRPCRequest = JRPCRequest<CommitmentJRPCRequestParams>;\n\nexport type CommitmentRequestResult = {\n signature: string;\n data: string;\n nodePubX: string;\n nodePubY: string;\n nodeIndex: number;\n};\n\nexport type CommitmentJRPCResponse = JRPCResponse<\n CommitmentRequestResult | undefined\n>;\n\nexport type SingleIdVerifierJrpcParams = {\n subVerifierAuthParams: {\n subVerifierIdToken: string;\n subVerifier: string;\n }[];\n};\n\nexport type AuthJRPCRequestParams = {\n authData: {\n authenticationContext: {\n idToken: string;\n verifier: string;\n verifierId: string;\n };\n singleIdVerifierParams?: SingleIdVerifierJrpcParams;\n extraOauthParams?: Record<string, string | number | boolean>;\n };\n commitmentSignatures: CommitmentRequestResult[];\n clientTime: string;\n};\n\nexport type AuthJRPCRequest = JRPCRequest<AuthJRPCRequestParams>;\n\nexport type AuthRequestResult = {\n authToken: string;\n nodeIndex: number;\n nodePubKey: string;\n pubKey: string;\n keyIndex: number;\n};\n\nexport type AuthJRPCResponse = JRPCResponse<AuthRequestResult>;\n\nexport type BaseShareImportItem = {\n encryptedAuthToken: string;\n encryptedShare: string;\n keyShareIndex: number;\n nodeIndex: number;\n sssEndpoint: string;\n};\n\nexport type NewUserShareImportItem = BaseShareImportItem;\n\nexport type KeyChangeShareImportItem = BaseShareImportItem & KeyChangeProof;\n\nexport type ShareImportItem<\n ShareType extends 'standard' | 'keyChange' = 'standard',\n> = ShareType extends 'standard'\n ? NewUserShareImportItem\n : KeyChangeShareImportItem;\n\nexport type StoreKeySharesJRPCRequestParams = {\n verifier: string;\n verifierId: string;\n pubKey: string;\n shareImportItems: ShareImportItem[];\n};\n\nexport type StoreKeySharesJRPCRequest =\n JRPCRequest<StoreKeySharesJRPCRequestParams>;\n\nexport type StoreKeySharesJRPCResponse = JRPCResponse<null>;\n\nexport type ResetRateLimitJRPCRequestParams = {\n authToken: string;\n signature: string;\n signedData: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type ResetRateLimitJRPCRequest =\n JRPCRequest<ResetRateLimitJRPCRequestParams>;\n\nexport type ResetRateLimitJRPCResponse = JRPCResponse<boolean>;\n\nexport type ToprfEvalJRPCRequestParams = {\n authToken: string;\n shareCoefficient: string;\n blindedInputX: string;\n blindedInputY: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type ToprfEvalJRPCRequest = JRPCRequest<ToprfEvalJRPCRequestParams>;\n\nexport type ToprfEvalResult = {\n blindedOutputX: string;\n blindedOutputY: string;\n nodeIndex: number;\n pubKey: string;\n keyShareIndex: number;\n\n /**\n * Number of eval requests made for this server.\n *\n * Upon successful encryption key derivation,\n * the reset request will be made to the server and the count will be reset to 0.\n */\n guessCount: number;\n\n /**\n * Time in seconds before the next guess is allowed to the server.\n *\n * Upon successful encryption key derivation,\n * the reset request will be made to the server and the time will be reset to 0.\n */\n lockTimeSeconds: number;\n};\n\nexport type ToprfEvalJRPCResponse = JRPCResponse<ToprfEvalResult>;\n\nexport type GetPubKeyJRPCRequestParams = {\n authToken: string;\n verifier: string;\n verifierId: string;\n};\n\nexport type GetPubKeyJRPCRequest = JRPCRequest<GetPubKeyJRPCRequestParams>;\n\nexport type GetPubKeyResult = {\n pubKey: string;\n keyIndex: number;\n};\n\nexport type GetPubKeyJRPCResponse = JRPCResponse<GetPubKeyResult>;\n"]}

@@ -71,4 +71,4 @@ "use strict";

// fnd package internally caches results so preloading will speed up subsequent calls.
__classPrivateFieldGet(this, _ToprfSecureBackup_instances, "m", _ToprfSecureBackup_getNodeDetails).call(this).catch((error) => {
console.error('Error fetching node details', error);
__classPrivateFieldGet(this, _ToprfSecureBackup_instances, "m", _ToprfSecureBackup_getNodeDetails).call(this).catch(() => {
// ignore error
});

@@ -487,3 +487,3 @@ }

const { nodeEndpointsMap } = await __classPrivateFieldGet(this, _ToprfSecureBackup_instances, "m", _ToprfSecureBackup_getNodeDetails).call(this);
const authPubKey = await (0, getPubKeyRequest_1.getPubKey)({
return (0, getPubKeyRequest_1.getPubKey)({
authTokens: nodeAuthTokens,

@@ -495,3 +495,2 @@ nodeEndpointsMap,

});
return { authPubKey };
}

@@ -498,0 +497,0 @@ /**

@@ -1,1 +0,1 @@

{"version":3,"file":"toprfSecureBackup.cjs","sourceRoot":"","sources":["../src/toprfSecureBackup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qEAA4E;AAC5E,gDAA+D;AAC/D,wDAA2D;AAC3D,uDAAoD;AACpD,+CAA6D;AAK7D,sEAAkE;AAElE,mEAAyD;AACzD,uDAAgD;AAChD,+CAIqB;AACrB,yCAAsC;AACtC,6DAA+C;AAyB/C,uDAIyB;AAEzB,6CAA2C;AAE3C,qCAAoD;AACpD,2DAAoD;AACpD,iEAAuE;AACvE,6DAAsD;AACtD,uCAAiD;AAEjD;;;GAGG;AACH,MAAa,iBAAiB;IAW5B;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,MAKX;;QAhCQ,uDAAsC;QAEtC,yDAA2C;QAE3C,gDAAyB;QAEzB,8DAAoD;QAE7D,wDAA+C;QAyB7C,uBAAA,IAAI,wCAAsB,IAAI,sCAAiB,CAAC;YAC9C,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC,MAAA,CAAC;QACH,uBAAA,IAAI,0CAAwB,MAAM,CAAC,mBAAmB,MAAA,CAAC;QACvD,uBAAA,IAAI,iCAAe,MAAM,CAAC,UAAU,MAAA,CAAC;QACrC,uBAAA,IAAI,+CAA6B,MAAM,CAAC,wBAAwB,MAAA,CAAC;QACjE,oEAAoE;QACpE,sFAAsF;QACtF,uBAAA,IAAI,uEAAgB,MAApB,IAAI,CAAkB,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACrC,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,YAAY,CAAC,MAA0B;QA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,EAAE,CAAC,QAAQ,EAAE;YAC7B,EAAE,EAAE,IAAA,kBAAU,EAAC,WAAW,CAAC,EAAE,CAAC;SAC/B;KACF,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,IAAgB;IAK3C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,mBAAW,EAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,MAAM,EAAE,IAAA,kBAAU,EAAC,IAAI,CAAC,MAAM,CAAC;QAC/B,WAAW,EAAE;YACX,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,EAAE,EAAE,IAAA,kBAAU,EAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;SACpC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { keccak256AndHexify, remove0x } from '@metamask/auth-network-utils';\nimport { bytesToUtf8, equalBytes } from '@noble/ciphers/utils';\nimport { utf8ToBytes } from '@noble/curves/abstract/utils';\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { bytesToHex, hexToBytes } from '@noble/hashes/utils';\nimport type {\n INodePub,\n TORUS_SAPPHIRE_NETWORK_TYPE,\n} from '@toruslabs/constants';\nimport { NodeDetailManager } from '@toruslabs/fetch-node-details';\n\nimport { authenticateUser } from './authenticateRequest';\nimport { commitIdToken } from './commitRequest';\nimport {\n FIRST_KEY_INDEX,\n MAX_PASSWORD_CHAIN_LENGTH,\n PW_BACKUP_ITEM_ID,\n} from './constants';\nimport { TOPRFError } from './errors';\nimport { getPubKey } from './getPubKeyRequest';\nimport type {\n AuthenticateParams,\n AuthenticateResult,\n CreateEncryptionKeyParams,\n CreateEncryptionKeyResult,\n FetchAllSecretDataParams,\n IToprfSecureBackup,\n RecoverEncryptionKeyParams,\n RecoverEncryptionKeyResult,\n AddSecretDataItemParams,\n ChangeEncryptionKeyParams,\n ChangeEncryptionKeyResult,\n FetchAuthPubKeyParams,\n FetchAuthPubKeyResult,\n PersistLocalKeyParams,\n CreateLocalKeyParams,\n CreateLocalKeyResult,\n BatchAddSecretDataItemParams,\n RecoverPwEncKeyParams,\n KeyPair,\n RecoverPwEncKeyResult,\n NodeDetailsOverride,\n FetchMetadataAccessCreds,\n} from './interfaces';\nimport {\n deriveAuthenticationKeyPair,\n deriveEncryptionKey,\n derivePwEncKey,\n} from './keyDerivation';\nimport type { SecretDataItem } from './metadata';\nimport { MetadataStore } from './metadata';\nimport type { KeyDeriver } from './oprf';\nimport { OPRF, generateRandomScalar } from './oprf';\nimport { resetRateLimits } from './resetRateLimits';\nimport { storeKeyShares, changeKeyShares } from './storeSharesRequest';\nimport { recoverTOPRFSeed } from './toprfEvalRequest';\nimport { createNodeEndpointsMap } from './utils';\n\n/**\n * ToprfSecureBackup - The main class for the tOPRF Secure Backup service.\n *\n */\nexport class ToprfSecureBackup implements IToprfSecureBackup {\n readonly #nodeDetailManager: NodeDetailManager;\n\n readonly #nodeDetailsOverride?: NodeDetailsOverride;\n\n readonly #keyDeriver?: KeyDeriver;\n\n readonly #fetchMetadataAccessCreds: FetchMetadataAccessCreds;\n\n #metadataStoreCache: MetadataStore | undefined;\n\n /**\n * The constructor for the ToprfSecureBackup class.\n *\n * If `keyDeriver` is 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 * @param params - The parameters for the constructor.\n * @param params.network - The web3auth network to be used for key management\n * and authentication.\n * @param params.nodeDetailsOverride - Optional overrides for node details\n * like SSS endpoints, indexes, and public keys.\n * @param params.keyDeriver - Optional key deriver to be used for an\n * additional layer of security.\n * @param params.fetchMetadataAccessCreds - Function to fetch metadata access credentials.\n */\n constructor(params: {\n network: TORUS_SAPPHIRE_NETWORK_TYPE;\n fetchMetadataAccessCreds: FetchMetadataAccessCreds;\n nodeDetailsOverride?: NodeDetailsOverride;\n keyDeriver?: KeyDeriver;\n }) {\n this.#nodeDetailManager = new NodeDetailManager({\n network: params.network,\n });\n this.#nodeDetailsOverride = params.nodeDetailsOverride;\n this.#keyDeriver = params.keyDeriver;\n this.#fetchMetadataAccessCreds = params.fetchMetadataAccessCreds;\n // pre-fetch node details to speed up the first call to authenticate\n // fnd package internally caches results so preloading will speed up subsequent calls.\n this.#getNodeDetails().catch((error) => {\n console.error('Error fetching node details', error);\n });\n }\n\n /**\n * This function is used to authenticate the user by sending the oauth idToken to the nodes and\n * getting the authentication tokens from the nodes in return.\n *\n * @param params - The authentication parameters.\n * @param params.idTokens - An array of id tokens for authentication.\n * @param params.authConnectionId - The auth connection name to be used for the authenticate request\n * @param params.userId - The user id of the user issued by authentication service\n * @param params.groupedAuthConnectionParams - Optional groupedAuthConnectionParams to be used for the authenticate request.\n * You can pass this to use aggregate verifier.\n *\n * @returns - The authentication result containing the authentication tokens and a boolean indicating if the user is new or not.\n * isNewUser - Indicates if the user has completed the key setup process or not.\n * if `true` then the user hasn't completed the social + password setup process.\n * if `false` then the user has completed the social + password setup process.\n * @throws {Error} If idToken is older than 6 minutes.\n */\n async authenticate(params: AuthenticateParams): Promise<AuthenticateResult> {\n const { nodeEndpoints, nodeEndpointsMap } = await this.#getNodeDetails();\n let sessionPrivKey: Uint8Array | null = secp256k1.utils.randomPrivateKey();\n\n try {\n const sessionPubKey =\n secp256k1.ProjectivePoint.fromPrivateKey(sessionPrivKey);\n const sessionPubKeyX = sessionPubKey.x.toString(16);\n const sessionPubKeyY = sessionPubKey.y.toString(16);\n\n let hashedIdToken: string | undefined;\n if (params.groupedAuthConnectionId) {\n // if groupedAuthConnectionId is provided, we'll compute the hashedIdToken for the aggregate (single id) verifier login\n hashedIdToken = remove0x(\n keccak256AndHexify(Buffer.from(params.idTokens[0], 'utf8')),\n );\n }\n\n // commit idToken to nodes\n const commitmentResults = await commitIdToken({\n idToken: hashedIdToken ?? params.idTokens[0],\n authConnectionId:\n params.groupedAuthConnectionId ?? params.authConnectionId,\n sessionPubKeyX,\n sessionPubKeyY,\n endpoints: nodeEndpoints,\n });\n\n // use only the node indexes that returned valid commitment responses\n const selectedEndpointsMap = commitmentResults.reduce<\n Record<number, string>\n >((acc, result) => {\n acc[result.nodeIndex] = nodeEndpointsMap[result.nodeIndex];\n return acc;\n }, {});\n\n // get auth tokens from nodes\n const { authTokensData, isNewUser } = await authenticateUser({\n idToken: params.idTokens[0],\n authConnectionId: params.authConnectionId,\n userId: params.userId,\n sessionPrivateKey: sessionPrivKey,\n nodeEndpointsMap: selectedEndpointsMap,\n commitmentSignatures: commitmentResults,\n groupedAuthConnectionId: params.groupedAuthConnectionId,\n hashedIdToken,\n });\n\n return {\n nodeAuthTokens: authTokensData.map((tokenData) => ({\n authToken: tokenData.authToken,\n nodeIndex: tokenData.nodeIndex,\n nodePubKey: tokenData.nodePubKey,\n })),\n isNewUser,\n };\n } finally {\n // Clean up session private key\n sessionPrivKey.fill(0);\n sessionPrivKey = null;\n }\n }\n\n /**\n * This function locally creates an OPRF and encryption keys without storing them at the\n * key management service. It returns the OPRF key, derives the corresponding key seed,\n * authentication key pair and encryption key.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.password - New password of the user.\n * @param params.oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n *\n * @returns The OPRF key, seed, and derived keys.\n */\n async createLocalKey(\n params: CreateLocalKeyParams,\n ): Promise<CreateLocalKeyResult> {\n const { password, oprfKey = generateRandomScalar() } = params;\n let pwBytes: Uint8Array | null = null;\n\n try {\n pwBytes = utf8ToBytes(password);\n const seed = await OPRF.localEval(oprfKey, pwBytes, this.#keyDeriver);\n\n const authKeyPair = deriveAuthenticationKeyPair(seed);\n const encKey = deriveEncryptionKey(seed);\n const pwEncKey = derivePwEncKey(seed);\n\n return {\n oprfKey,\n seed,\n authKeyPair,\n encKey,\n pwEncKey,\n };\n } finally {\n // Clean up sensitive intermediate data\n if (pwBytes) {\n pwBytes.fill(0);\n pwBytes = null;\n }\n }\n }\n\n /**\n * This function persists the OPRF key's shares at the servers.\n *\n * @param params - The parameters for persisting the OPRF key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.oprfKey - The OPRF key to be persisted.\n * @param params.authPubKey - The authentication public key.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.keyShareIndex - The key share index to be persisted. Required only during key change, defaults to FIRST_KEY_INDEX for first-time storage.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user. Required only during key change, not needed for first-time storage.\n */\n async persistLocalKey(params: PersistLocalKeyParams): Promise<void> {\n const {\n nodeAuthTokens,\n oprfKey,\n authPubKey,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n keyShareIndex = FIRST_KEY_INDEX,\n oldAuthKeyPair,\n } = params;\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n\n const selectedEndpointsMap = nodeAuthTokens.reduce<Record<number, string>>(\n (acc, tokenData) => {\n acc[tokenData.nodeIndex] = nodeEndpointsMap[tokenData.nodeIndex];\n return acc;\n },\n {},\n );\n\n if (oldAuthKeyPair) {\n await changeKeyShares({\n nodeEndpointsMap: selectedEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authTokens: nodeAuthTokens,\n keyShareIndex,\n newOprfKey: oprfKey,\n newAuthPubKey: authPubKey,\n oldAuthPrivKey: oldAuthKeyPair.sk,\n });\n } else {\n await storeKeyShares({\n nodeEndpointsMap: selectedEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authTokens: nodeAuthTokens,\n keyShareIndex,\n oprfKey,\n authPubKey,\n });\n }\n }\n\n /**\n * This function creates the encryption key which is used to encrypt/decrypt the secret data.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.password - New password of the user.\n *\n * @returns The encryption key.\n */\n async createAndPersistEncKey(\n params: CreateEncryptionKeyParams,\n ): Promise<CreateEncryptionKeyResult> {\n const { nodeAuthTokens, password, authConnectionId, userId } = params;\n const { oprfKey, authKeyPair, encKey, pwEncKey } =\n await this.createLocalKey({\n password,\n });\n\n await this.persistLocalKey({\n nodeAuthTokens,\n oprfKey,\n authPubKey: authKeyPair.pk,\n authConnectionId,\n userId,\n });\n\n return {\n authKeyPair: {\n sk: authKeyPair.sk,\n pk: authKeyPair.pk,\n },\n encKey,\n pwEncKey,\n };\n }\n\n /**\n * This function recovers the encryption key which is used to decrypt the secret data.\n *\n * @param params - The parameters for recovering the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.password - The password of the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n *\n * @returns The encryption key result with auth key pair, encryption key and key share index.\n */\n async recoverEncKey(\n params: RecoverEncryptionKeyParams,\n ): Promise<RecoverEncryptionKeyResult> {\n const {\n nodeAuthTokens,\n password,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n } = params;\n\n let pwBytes: Uint8Array | null = null;\n let seed: Uint8Array | null = null;\n\n try {\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n pwBytes = utf8ToBytes(password);\n\n const { seed: seedValue, keyShareIndex } = await recoverTOPRFSeed({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n userInput: pwBytes,\n keyDeriver: this.#keyDeriver,\n });\n\n seed = seedValue;\n\n const authKeyPair = deriveAuthenticationKeyPair(seed);\n const encKey = deriveEncryptionKey(seed);\n const pwEncKey = derivePwEncKey(seed);\n\n const rateLimitResetResult = new Promise<void>((resolve, reject) => {\n resetRateLimits({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authPrivKey: authKeyPair.sk,\n })\n .then(() => {\n return resolve();\n })\n .catch((error) => {\n reject(error as Error);\n });\n });\n\n return {\n authKeyPair,\n encKey,\n pwEncKey,\n keyShareIndex,\n rateLimitResetResult,\n };\n } finally {\n // Clean up sensitive intermediate data\n if (pwBytes) {\n pwBytes.fill(0);\n pwBytes = null;\n }\n\n if (seed) {\n seed.fill(0);\n seed = null;\n }\n }\n }\n\n /**\n * This function replaces the existing encryption key with a new one by generating a new key from\n * the new password, copying all existing secret data encrypted with the old key to be encrypted\n * with the new key, and updating the key shares on the nodes.\n *\n * @param params - The parameters for changing the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n * @param params.oldEncKey - The old encryption key of the user.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user.\n * @param params.newKeyShareIndex - The key share index to be used for the new key.\n * @param params.newPassword - Optional new password of the user, either this or pregeneratedOprfKey is required.\n * @param params.pregeneratedOprfKey - Optional pregenerated OPRF key to be used for the key change, if not provided, a new key will be generated from the new password.\n *\n * @returns The new key pair and encryption key.\n * @throws {Error} If both newPassword and pregeneratedOprfKey are provided.\n * @throws {Error} If neither newPassword nor pregeneratedOprfKey is provided.\n */\n async changeEncKey(\n params: ChangeEncryptionKeyParams,\n ): Promise<ChangeEncryptionKeyResult> {\n const {\n nodeAuthTokens,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n oldEncKey,\n oldPwEncKey,\n oldAuthKeyPair,\n newPassword,\n newKeyShareIndex,\n pregeneratedOprfKey,\n } = params;\n\n if (!pregeneratedOprfKey && !newPassword) {\n throw new Error('Either newPassword or pregeneratedOprfKey is required');\n }\n\n if (pregeneratedOprfKey && newPassword) {\n throw new Error(\n 'Only one of newPassword or pregeneratedOprfKey is allowed',\n );\n }\n\n // if newPassword is provided, create a new key from the password\n // else use the pregeneratedOprfKey, both can't be undefined as per check above.\n const { oprfKey, authKeyPair, encKey, pwEncKey } = newPassword\n ? await this.createLocalKey({ password: newPassword })\n : (pregeneratedOprfKey as CreateLocalKeyResult);\n\n let metadataStore: MetadataStore | undefined;\n let oldMetadataLockId: string | undefined;\n let newMetadataLockId: string | undefined;\n\n try {\n metadataStore = await this.#createMetadataStore();\n\n [oldMetadataLockId, newMetadataLockId] = await Promise.all([\n metadataStore.acquireMetadataLock(oldAuthKeyPair),\n metadataStore.acquireMetadataLock(authKeyPair),\n ]);\n\n const existingData = (\n await metadataStore.fetchAllSecretDataItems(oldEncKey, oldAuthKeyPair)\n ).map((dataItem) => ({ data: dataItem.data }));\n\n // Validate that this is actually a key change scenario\n if (!existingData || existingData.length === 0) {\n throw new Error('No existing data found to change key');\n }\n\n const pwBackup: SecretDataItem = {\n data: serializePwBackup('', oldPwEncKey, oldAuthKeyPair),\n itemId: PW_BACKUP_ITEM_ID,\n };\n\n const secretDataItems = [pwBackup, ...existingData];\n const encKeys = [pwEncKey, ...existingData.map(() => encKey)];\n await metadataStore.batchAddSecretData({\n secretData: secretDataItems,\n encKey: encKeys,\n authKeyPair,\n });\n\n await this.persistLocalKey({\n nodeAuthTokens,\n oprfKey,\n authPubKey: authKeyPair.pk,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n keyShareIndex: newKeyShareIndex,\n oldAuthKeyPair,\n });\n\n return { authKeyPair, encKey, pwEncKey };\n } finally {\n if (metadataStore && oldMetadataLockId && newMetadataLockId) {\n try {\n await Promise.all([\n metadataStore.releaseMetadataLock(\n oldAuthKeyPair,\n oldMetadataLockId,\n ),\n metadataStore.releaseMetadataLock(authKeyPair, newMetadataLockId),\n ]);\n } catch (error) {\n console.error('Failed to release metadata lock:', error);\n }\n }\n }\n }\n\n /**\n * This function encrypts the secret data using the encryption key and stores it nodes metadata store in encrypted form.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key which is used to encrypt the secret data before storing it.\n * @param params.secretData - The array of secret data to be registered.\n * @param params.authKeyPair - The authentication key pair which is used to authenticate the user to the storage service.\n */\n async addSecretDataItem(params: AddSecretDataItemParams): Promise<void> {\n const metadataStore = await this.#createMetadataStore();\n await metadataStore.addSecretDataItem({\n ...params,\n secretData: {\n data: params.secretData,\n },\n });\n }\n\n /**\n * This function encrypts the array of secret data using the encryption key and stores in the metadata store in encrypted form as a batch.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.secretData - The array of secret data to be stored.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n */\n async batchAddSecretDataItems(\n params: BatchAddSecretDataItemParams,\n ): Promise<void> {\n const metadataStore = await this.#createMetadataStore();\n\n let metadataLockId: string | undefined;\n\n try {\n // acquire metadata lock\n metadataLockId = await metadataStore.acquireMetadataLock(\n params.authKeyPair,\n );\n\n await metadataStore.batchAddSecretData({\n ...params,\n secretData: params.secretData.map((data) => ({\n data,\n })),\n });\n } finally {\n // release metadata lock\n if (metadataLockId) {\n try {\n await metadataStore.releaseMetadataLock(\n params.authKeyPair,\n metadataLockId,\n );\n } catch (error) {\n console.error('Failed to release metadata lock:', error);\n }\n }\n }\n }\n\n /**\n * This function fetches all secret data items associated with the given\n * auth pub key, decrypts, and returns them.\n *\n * @param params - The parameters for fetching the secret data.\n * @param params.decKey - The decryption key to be used to decrypt the secret data.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for fetching the secret data.\n *\n * @returns The decrypted secret data. Returns an empty array if no secret data is found.\n */\n async fetchAllSecretDataItems(\n params: FetchAllSecretDataParams,\n ): Promise<Uint8Array[]> {\n const metadataStore = await this.#createMetadataStore();\n const dataItems = await metadataStore.fetchAllSecretDataItems(\n params.decKey,\n params.authKeyPair,\n );\n return dataItems.map((dataItem: SecretDataItem) => dataItem.data);\n }\n\n /**\n * This function fetches the authentication public key.\n *\n * @param params - The parameters for getting the authentication public key.\n * @param params.authTokens - The auth tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n *\n * @returns The authentication public key.\n */\n async fetchAuthPubKey(\n params: FetchAuthPubKeyParams,\n ): Promise<FetchAuthPubKeyResult> {\n const {\n nodeAuthTokens,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n } = params;\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n const authPubKey = await getPubKey({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n });\n return { authPubKey };\n }\n\n /**\n * This function looks up a password encryption key from the password\n * encryption key history.\n *\n * @param params - The parameters for getting the password encryption key.\n * @param params.targetPwPubKey - The target password public key.\n * @param params.curPwEncKey - The current password encryption key.\n * @param params.curAuthKeyPair - The current authentication key pair.\n * @param params.maxPwChainLength - Optional maximum password chain length\n * allowed to be traversed.\n *\n * @returns The password encryption key.\n */\n async recoverPwEncKey(\n params: RecoverPwEncKeyParams,\n ): Promise<RecoverPwEncKeyResult> {\n const {\n targetAuthPubKey: targetPwPubKey,\n curPwEncKey,\n curAuthKeyPair,\n maxPwChainLength = MAX_PASSWORD_CHAIN_LENGTH,\n } = params;\n\n let pwAndKeys = {\n password: '',\n encKey: curPwEncKey,\n authKeyPair: curAuthKeyPair,\n };\n\n for (let i = 0; i < maxPwChainLength; i++) {\n try {\n pwAndKeys = await this.#getPrevPasswordAndKeys({\n encKey: pwAndKeys.encKey,\n authKeyPair: pwAndKeys.authKeyPair,\n });\n if (equalBytes(pwAndKeys.authKeyPair.pk, targetPwPubKey)) {\n return { pwEncKey: pwAndKeys.encKey };\n }\n } catch (error) {\n throw TOPRFError.couldNotFetchPassword((error as Error).message);\n }\n }\n\n throw TOPRFError.maxKeyChainLengthExceeded();\n }\n\n /**\n * Gets the node details.\n *\n * @returns The node details containing the node endpoints, indexes and pubkeys.\n */\n async #getNodeDetails(): Promise<{\n nodeEndpoints: string[];\n nodeEndpointsMap: Record<number, string>;\n nodeIndexes: number[];\n nodePubkeys: INodePub[];\n }> {\n let finalIndexes = this.#nodeDetailsOverride?.indexes;\n let finalPubKeys = this.#nodeDetailsOverride?.pubKeys;\n let finalEndpoints = this.#nodeDetailsOverride?.endpoints;\n\n if (finalIndexes && finalPubKeys && Array.isArray(finalEndpoints)) {\n ToprfSecureBackup.#validateNodeDetailsLengths(\n finalIndexes,\n finalPubKeys,\n finalEndpoints,\n );\n return {\n nodeEndpoints: finalEndpoints,\n nodeEndpointsMap: createNodeEndpointsMap(finalEndpoints, finalIndexes),\n nodeIndexes: finalIndexes,\n nodePubkeys: finalPubKeys,\n };\n }\n\n const { torusNodeSSSEndpoints, torusIndexes, torusNodePub } =\n await this.#nodeDetailManager.getNodeDetails({\n verifier: 'auth-connection-id',\n verifierId: 'user-id',\n });\n\n finalIndexes ??= torusIndexes;\n finalPubKeys ??= torusNodePub;\n\n if (!Array.isArray(finalEndpoints)) {\n if (!torusNodeSSSEndpoints) {\n const message = 'Failed to get node details';\n throw new Error(message);\n }\n\n finalEndpoints = finalEndpoints\n ? torusNodeSSSEndpoints.map((endpoint) => {\n const url = new URL(endpoint);\n url.pathname = finalEndpoints as string;\n return url.href;\n })\n : torusNodeSSSEndpoints;\n }\n\n ToprfSecureBackup.#validateNodeDetailsLengths(\n finalIndexes,\n finalPubKeys,\n finalEndpoints,\n );\n\n return {\n nodeEndpoints: finalEndpoints,\n nodeEndpointsMap: createNodeEndpointsMap(finalEndpoints, finalIndexes),\n nodeIndexes: finalIndexes,\n nodePubkeys: finalPubKeys,\n };\n }\n\n /**\n * Creates and caches the metadata store instance.\n *\n * @returns The metadata store.\n */\n async #createMetadataStore(): Promise<MetadataStore> {\n if (this.#metadataStoreCache) {\n return this.#metadataStoreCache;\n }\n\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n const metadataEndpointsMap =\n await this.#getMetadataEndpointsMap(nodeEndpointsMap);\n const node1MetadataEndpoint = metadataEndpointsMap['1'];\n\n const metadataStore = new MetadataStore({\n metadataEndpoint: node1MetadataEndpoint,\n fetchMetadataAccessCreds: this.#fetchMetadataAccessCreds,\n });\n\n this.#metadataStoreCache = metadataStore;\n\n return metadataStore;\n }\n\n /**\n * Gets the metadata endpoints.\n *\n * @param nodeEndpointsMap - The node endpoints map.\n *\n * @returns The metadata endpoints map with node index as key and metadata endpoint as value.\n */\n async #getMetadataEndpointsMap(\n nodeEndpointsMap: Record<number, string>,\n ): Promise<{ [nodeIndex: string]: string }> {\n const metadataEndpointsMap: { [nodeIndex: string]: string } = {};\n Object.entries(nodeEndpointsMap).forEach(([key, value]) => {\n const url = new URL(value);\n metadataEndpointsMap[key] = `${url.origin}/metadata`;\n });\n return metadataEndpointsMap;\n }\n\n /**\n * Gets the previous password and keys.\n *\n * @param params - The parameters for getting the previous password and keys.\n * @param params.encKey - The encryption key to be used for decrypting the secret data.\n * @param params.authKeyPair - The authentication key pair to be used for authenticating the secret data.\n *\n * @returns The previous password and keys.\n */\n async #getPrevPasswordAndKeys(params: {\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n }): Promise<{\n password: string;\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n }> {\n const metadataStore = await this.#createMetadataStore();\n\n const pwBackupData = await metadataStore.fetchAllSecretDataItems(\n params.encKey,\n params.authKeyPair,\n PW_BACKUP_ITEM_ID,\n );\n\n if (pwBackupData.length === 0) {\n throw new Error('Failed to get previous password and keys');\n }\n\n // Parse JSON object.\n const pwBackupDataJson = deserializePwBackup(pwBackupData[0].data);\n\n return {\n password: pwBackupDataJson.pw,\n encKey: pwBackupDataJson.encKey,\n authKeyPair: pwBackupDataJson.authKeyPair,\n };\n }\n\n /**\n * Validates that the lengths of node detail arrays are consistent.\n *\n * @param indexes - Array of node indexes.\n * @param pubKeys - Array of node public keys.\n * @param endpoints - Array of SSS endpoint URLs.\n * @throws If lengths are inconsistent.\n */\n static #validateNodeDetailsLengths(\n indexes: unknown[],\n pubKeys: unknown[],\n endpoints: unknown[],\n ): void {\n if (\n indexes.length !== pubKeys.length ||\n indexes.length !== endpoints.length\n ) {\n const message =\n 'Node details arrays (indexes, pubKeys, endpoints) must have equal lengths';\n throw new Error(message);\n }\n }\n}\n\n/**\n * Serializes the password, encryption key, and authentication key pair into a JSON string.\n *\n * @param pw - The password.\n * @param encKey - The encryption key.\n * @param authKeyPair - The authentication key pair.\n * @returns The serialized JSON string.\n */\nfunction serializePwBackup(\n pw: string,\n encKey: Uint8Array,\n authKeyPair: KeyPair,\n): Uint8Array {\n return utf8ToBytes(\n JSON.stringify({\n pw,\n encKey: bytesToHex(encKey),\n authKeyPair: {\n sk: authKeyPair.sk.toString(),\n pk: bytesToHex(authKeyPair.pk),\n },\n }),\n );\n}\n\n/**\n * Deserializes the password, encryption key, and authentication key pair from a JSON string.\n *\n * @param data - The serialized JSON string.\n * @returns The password, encryption key, and authentication key pair.\n */\nfunction deserializePwBackup(data: Uint8Array): {\n pw: string;\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n} {\n const json = JSON.parse(bytesToUtf8(data));\n return {\n pw: json.pw,\n encKey: hexToBytes(json.encKey),\n authKeyPair: {\n sk: BigInt(json.authKeyPair.sk),\n pk: hexToBytes(json.authKeyPair.pk),\n },\n };\n}\n"]}
{"version":3,"file":"toprfSecureBackup.cjs","sourceRoot":"","sources":["../src/toprfSecureBackup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qEAA4E;AAC5E,gDAA+D;AAC/D,wDAA2D;AAC3D,uDAAoD;AACpD,+CAA6D;AAK7D,sEAAkE;AAElE,mEAAyD;AACzD,uDAAgD;AAChD,+CAIqB;AACrB,yCAAsC;AACtC,6DAA+C;AAyB/C,uDAIyB;AAEzB,6CAA2C;AAE3C,qCAAoD;AACpD,2DAAoD;AACpD,iEAAuE;AACvE,6DAAsD;AACtD,uCAAiD;AAEjD;;;GAGG;AACH,MAAa,i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@noble/ciphers/utils';\nimport { utf8ToBytes } from '@noble/curves/abstract/utils';\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { bytesToHex, hexToBytes } from '@noble/hashes/utils';\nimport type {\n INodePub,\n TORUS_SAPPHIRE_NETWORK_TYPE,\n} from '@toruslabs/constants';\nimport { NodeDetailManager } from '@toruslabs/fetch-node-details';\n\nimport { authenticateUser } from './authenticateRequest';\nimport { commitIdToken } from './commitRequest';\nimport {\n FIRST_KEY_INDEX,\n MAX_PASSWORD_CHAIN_LENGTH,\n PW_BACKUP_ITEM_ID,\n} from './constants';\nimport { TOPRFError } from './errors';\nimport { getPubKey } from './getPubKeyRequest';\nimport type {\n AuthenticateParams,\n AuthenticateResult,\n CreateEncryptionKeyParams,\n CreateEncryptionKeyResult,\n FetchAllSecretDataParams,\n IToprfSecureBackup,\n RecoverEncryptionKeyParams,\n RecoverEncryptionKeyResult,\n AddSecretDataItemParams,\n ChangeEncryptionKeyParams,\n ChangeEncryptionKeyResult,\n FetchAuthPubKeyParams,\n FetchAuthPubKeyResult,\n PersistLocalKeyParams,\n CreateLocalKeyParams,\n CreateLocalKeyResult,\n BatchAddSecretDataItemParams,\n RecoverPwEncKeyParams,\n KeyPair,\n RecoverPwEncKeyResult,\n NodeDetailsOverride,\n FetchMetadataAccessCreds,\n} from './interfaces';\nimport {\n deriveAuthenticationKeyPair,\n deriveEncryptionKey,\n derivePwEncKey,\n} from './keyDerivation';\nimport type { SecretDataItem } from './metadata';\nimport { MetadataStore } from './metadata';\nimport type { KeyDeriver } from './oprf';\nimport { OPRF, generateRandomScalar } from './oprf';\nimport { resetRateLimits } from './resetRateLimits';\nimport { storeKeyShares, changeKeyShares } from './storeSharesRequest';\nimport { recoverTOPRFSeed } from './toprfEvalRequest';\nimport { createNodeEndpointsMap } from './utils';\n\n/**\n * ToprfSecureBackup - The main class for the tOPRF Secure Backup service.\n *\n */\nexport class ToprfSecureBackup implements IToprfSecureBackup {\n readonly #nodeDetailManager: NodeDetailManager;\n\n readonly #nodeDetailsOverride?: NodeDetailsOverride;\n\n readonly #keyDeriver?: KeyDeriver;\n\n readonly #fetchMetadataAccessCreds: FetchMetadataAccessCreds;\n\n #metadataStoreCache: MetadataStore | undefined;\n\n /**\n * The constructor for the ToprfSecureBackup class.\n *\n * If `keyDeriver` is 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 * @param params - The parameters for the constructor.\n * @param params.network - The web3auth network to be used for key management\n * and authentication.\n * @param params.nodeDetailsOverride - Optional overrides for node details\n * like SSS endpoints, indexes, and public keys.\n * @param params.keyDeriver - Optional key deriver to be used for an\n * additional layer of security.\n * @param params.fetchMetadataAccessCreds - Function to fetch metadata access credentials.\n */\n constructor(params: {\n network: TORUS_SAPPHIRE_NETWORK_TYPE;\n fetchMetadataAccessCreds: FetchMetadataAccessCreds;\n nodeDetailsOverride?: NodeDetailsOverride;\n keyDeriver?: KeyDeriver;\n }) {\n this.#nodeDetailManager = new NodeDetailManager({\n network: params.network,\n });\n this.#nodeDetailsOverride = params.nodeDetailsOverride;\n this.#keyDeriver = params.keyDeriver;\n this.#fetchMetadataAccessCreds = params.fetchMetadataAccessCreds;\n // pre-fetch node details to speed up the first call to authenticate\n // fnd package internally caches results so preloading will speed up subsequent calls.\n this.#getNodeDetails().catch(() => {\n // ignore error\n });\n }\n\n /**\n * This function is used to authenticate the user by sending the oauth idToken to the nodes and\n * getting the authentication tokens from the nodes in return.\n *\n * @param params - The authentication parameters.\n * @param params.idTokens - An array of id tokens for authentication.\n * @param params.authConnectionId - The auth connection name to be used for the authenticate request\n * @param params.userId - The user id of the user issued by authentication service\n * @param params.groupedAuthConnectionParams - Optional groupedAuthConnectionParams to be used for the authenticate request.\n * You can pass this to use aggregate verifier.\n *\n * @returns - The authentication result containing the authentication tokens and a boolean indicating if the user is new or not.\n * isNewUser - Indicates if the user has completed the key setup process or not.\n * if `true` then the user hasn't completed the social + password setup process.\n * if `false` then the user has completed the social + password setup process.\n * @throws {Error} If idToken is older than 6 minutes.\n */\n async authenticate(params: AuthenticateParams): Promise<AuthenticateResult> {\n const { nodeEndpoints, nodeEndpointsMap } = await this.#getNodeDetails();\n let sessionPrivKey: Uint8Array | null = secp256k1.utils.randomPrivateKey();\n\n try {\n const sessionPubKey =\n secp256k1.ProjectivePoint.fromPrivateKey(sessionPrivKey);\n const sessionPubKeyX = sessionPubKey.x.toString(16);\n const sessionPubKeyY = sessionPubKey.y.toString(16);\n\n let hashedIdToken: string | undefined;\n if (params.groupedAuthConnectionId) {\n // if groupedAuthConnectionId is provided, we'll compute the hashedIdToken for the aggregate (single id) verifier login\n hashedIdToken = remove0x(\n keccak256AndHexify(Buffer.from(params.idTokens[0], 'utf8')),\n );\n }\n\n // commit idToken to nodes\n const commitmentResults = await commitIdToken({\n idToken: hashedIdToken ?? params.idTokens[0],\n authConnectionId:\n params.groupedAuthConnectionId ?? params.authConnectionId,\n sessionPubKeyX,\n sessionPubKeyY,\n endpoints: nodeEndpoints,\n });\n\n // use only the node indexes that returned valid commitment responses\n const selectedEndpointsMap = commitmentResults.reduce<\n Record<number, string>\n >((acc, result) => {\n acc[result.nodeIndex] = nodeEndpointsMap[result.nodeIndex];\n return acc;\n }, {});\n\n // get auth tokens from nodes\n const { authTokensData, isNewUser } = await authenticateUser({\n idToken: params.idTokens[0],\n authConnectionId: params.authConnectionId,\n userId: params.userId,\n sessionPrivateKey: sessionPrivKey,\n nodeEndpointsMap: selectedEndpointsMap,\n commitmentSignatures: commitmentResults,\n groupedAuthConnectionId: params.groupedAuthConnectionId,\n hashedIdToken,\n });\n\n return {\n nodeAuthTokens: authTokensData.map((tokenData) => ({\n authToken: tokenData.authToken,\n nodeIndex: tokenData.nodeIndex,\n nodePubKey: tokenData.nodePubKey,\n })),\n isNewUser,\n };\n } finally {\n // Clean up session private key\n sessionPrivKey.fill(0);\n sessionPrivKey = null;\n }\n }\n\n /**\n * This function locally creates an OPRF and encryption keys without storing them at the\n * key management service. It returns the OPRF key, derives the corresponding key seed,\n * authentication key pair and encryption key.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.password - New password of the user.\n * @param params.oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n *\n * @returns The OPRF key, seed, and derived keys.\n */\n async createLocalKey(\n params: CreateLocalKeyParams,\n ): Promise<CreateLocalKeyResult> {\n const { password, oprfKey = generateRandomScalar() } = params;\n let pwBytes: Uint8Array | null = null;\n\n try {\n pwBytes = utf8ToBytes(password);\n const seed = await OPRF.localEval(oprfKey, pwBytes, this.#keyDeriver);\n\n const authKeyPair = deriveAuthenticationKeyPair(seed);\n const encKey = deriveEncryptionKey(seed);\n const pwEncKey = derivePwEncKey(seed);\n\n return {\n oprfKey,\n seed,\n authKeyPair,\n encKey,\n pwEncKey,\n };\n } finally {\n // Clean up sensitive intermediate data\n if (pwBytes) {\n pwBytes.fill(0);\n pwBytes = null;\n }\n }\n }\n\n /**\n * This function persists the OPRF key's shares at the servers.\n *\n * @param params - The parameters for persisting the OPRF key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.oprfKey - The OPRF key to be persisted.\n * @param params.authPubKey - The authentication public key.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.keyShareIndex - The key share index to be persisted. Required only during key change, defaults to FIRST_KEY_INDEX for first-time storage.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user. Required only during key change, not needed for first-time storage.\n */\n async persistLocalKey(params: PersistLocalKeyParams): Promise<void> {\n const {\n nodeAuthTokens,\n oprfKey,\n authPubKey,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n keyShareIndex = FIRST_KEY_INDEX,\n oldAuthKeyPair,\n } = params;\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n\n const selectedEndpointsMap = nodeAuthTokens.reduce<Record<number, string>>(\n (acc, tokenData) => {\n acc[tokenData.nodeIndex] = nodeEndpointsMap[tokenData.nodeIndex];\n return acc;\n },\n {},\n );\n\n if (oldAuthKeyPair) {\n await changeKeyShares({\n nodeEndpointsMap: selectedEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authTokens: nodeAuthTokens,\n keyShareIndex,\n newOprfKey: oprfKey,\n newAuthPubKey: authPubKey,\n oldAuthPrivKey: oldAuthKeyPair.sk,\n });\n } else {\n await storeKeyShares({\n nodeEndpointsMap: selectedEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authTokens: nodeAuthTokens,\n keyShareIndex,\n oprfKey,\n authPubKey,\n });\n }\n }\n\n /**\n * This function creates the encryption key which is used to encrypt/decrypt the secret data.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.password - New password of the user.\n *\n * @returns The encryption key.\n */\n async createAndPersistEncKey(\n params: CreateEncryptionKeyParams,\n ): Promise<CreateEncryptionKeyResult> {\n const { nodeAuthTokens, password, authConnectionId, userId } = params;\n const { oprfKey, authKeyPair, encKey, pwEncKey } =\n await this.createLocalKey({\n password,\n });\n\n await this.persistLocalKey({\n nodeAuthTokens,\n oprfKey,\n authPubKey: authKeyPair.pk,\n authConnectionId,\n userId,\n });\n\n return {\n authKeyPair: {\n sk: authKeyPair.sk,\n pk: authKeyPair.pk,\n },\n encKey,\n pwEncKey,\n };\n }\n\n /**\n * This function recovers the encryption key which is used to decrypt the secret data.\n *\n * @param params - The parameters for recovering the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.password - The password of the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n *\n * @returns The encryption key result with auth key pair, encryption key and key share index.\n */\n async recoverEncKey(\n params: RecoverEncryptionKeyParams,\n ): Promise<RecoverEncryptionKeyResult> {\n const {\n nodeAuthTokens,\n password,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n } = params;\n\n let pwBytes: Uint8Array | null = null;\n let seed: Uint8Array | null = null;\n\n try {\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n pwBytes = utf8ToBytes(password);\n\n const { seed: seedValue, keyShareIndex } = await recoverTOPRFSeed({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n userInput: pwBytes,\n keyDeriver: this.#keyDeriver,\n });\n\n seed = seedValue;\n\n const authKeyPair = deriveAuthenticationKeyPair(seed);\n const encKey = deriveEncryptionKey(seed);\n const pwEncKey = derivePwEncKey(seed);\n\n const rateLimitResetResult = new Promise<void>((resolve, reject) => {\n resetRateLimits({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authPrivKey: authKeyPair.sk,\n })\n .then(() => {\n return resolve();\n })\n .catch((error) => {\n reject(error as Error);\n });\n });\n\n return {\n authKeyPair,\n encKey,\n pwEncKey,\n keyShareIndex,\n rateLimitResetResult,\n };\n } finally {\n // Clean up sensitive intermediate data\n if (pwBytes) {\n pwBytes.fill(0);\n pwBytes = null;\n }\n\n if (seed) {\n seed.fill(0);\n seed = null;\n }\n }\n }\n\n /**\n * This function replaces the existing encryption key with a new one by generating a new key from\n * the new password, copying all existing secret data encrypted with the old key to be encrypted\n * with the new key, and updating the key shares on the nodes.\n *\n * @param params - The parameters for changing the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n * @param params.oldEncKey - The old encryption key of the user.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user.\n * @param params.newKeyShareIndex - The key share index to be used for the new key.\n * @param params.newPassword - Optional new password of the user, either this or pregeneratedOprfKey is required.\n * @param params.pregeneratedOprfKey - Optional pregenerated OPRF key to be used for the key change, if not provided, a new key will be generated from the new password.\n *\n * @returns The new key pair and encryption key.\n * @throws {Error} If both newPassword and pregeneratedOprfKey are provided.\n * @throws {Error} If neither newPassword nor pregeneratedOprfKey is provided.\n */\n async changeEncKey(\n params: ChangeEncryptionKeyParams,\n ): Promise<ChangeEncryptionKeyResult> {\n const {\n nodeAuthTokens,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n oldEncKey,\n oldPwEncKey,\n oldAuthKeyPair,\n newPassword,\n newKeyShareIndex,\n pregeneratedOprfKey,\n } = params;\n\n if (!pregeneratedOprfKey && !newPassword) {\n throw new Error('Either newPassword or pregeneratedOprfKey is required');\n }\n\n if (pregeneratedOprfKey && newPassword) {\n throw new Error(\n 'Only one of newPassword or pregeneratedOprfKey is allowed',\n );\n }\n\n // if newPassword is provided, create a new key from the password\n // else use the pregeneratedOprfKey, both can't be undefined as per check above.\n const { oprfKey, authKeyPair, encKey, pwEncKey } = newPassword\n ? await this.createLocalKey({ password: newPassword })\n : (pregeneratedOprfKey as CreateLocalKeyResult);\n\n let metadataStore: MetadataStore | undefined;\n let oldMetadataLockId: string | undefined;\n let newMetadataLockId: string | undefined;\n\n try {\n metadataStore = await this.#createMetadataStore();\n\n [oldMetadataLockId, newMetadataLockId] = await Promise.all([\n metadataStore.acquireMetadataLock(oldAuthKeyPair),\n metadataStore.acquireMetadataLock(authKeyPair),\n ]);\n\n const existingData = (\n await metadataStore.fetchAllSecretDataItems(oldEncKey, oldAuthKeyPair)\n ).map((dataItem) => ({ data: dataItem.data }));\n\n // Validate that this is actually a key change scenario\n if (!existingData || existingData.length === 0) {\n throw new Error('No existing data found to change key');\n }\n\n const pwBackup: SecretDataItem = {\n data: serializePwBackup('', oldPwEncKey, oldAuthKeyPair),\n itemId: PW_BACKUP_ITEM_ID,\n };\n\n const secretDataItems = [pwBackup, ...existingData];\n const encKeys = [pwEncKey, ...existingData.map(() => encKey)];\n await metadataStore.batchAddSecretData({\n secretData: secretDataItems,\n encKey: encKeys,\n authKeyPair,\n });\n\n await this.persistLocalKey({\n nodeAuthTokens,\n oprfKey,\n authPubKey: authKeyPair.pk,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n keyShareIndex: newKeyShareIndex,\n oldAuthKeyPair,\n });\n\n return { authKeyPair, encKey, pwEncKey };\n } finally {\n if (metadataStore && oldMetadataLockId && newMetadataLockId) {\n try {\n await Promise.all([\n metadataStore.releaseMetadataLock(\n oldAuthKeyPair,\n oldMetadataLockId,\n ),\n metadataStore.releaseMetadataLock(authKeyPair, newMetadataLockId),\n ]);\n } catch (error) {\n console.error('Failed to release metadata lock:', error);\n }\n }\n }\n }\n\n /**\n * This function encrypts the secret data using the encryption key and stores it nodes metadata store in encrypted form.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key which is used to encrypt the secret data before storing it.\n * @param params.secretData - The array of secret data to be registered.\n * @param params.authKeyPair - The authentication key pair which is used to authenticate the user to the storage service.\n */\n async addSecretDataItem(params: AddSecretDataItemParams): Promise<void> {\n const metadataStore = await this.#createMetadataStore();\n await metadataStore.addSecretDataItem({\n ...params,\n secretData: {\n data: params.secretData,\n },\n });\n }\n\n /**\n * This function encrypts the array of secret data using the encryption key and stores in the metadata store in encrypted form as a batch.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.secretData - The array of secret data to be stored.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n */\n async batchAddSecretDataItems(\n params: BatchAddSecretDataItemParams,\n ): Promise<void> {\n const metadataStore = await this.#createMetadataStore();\n\n let metadataLockId: string | undefined;\n\n try {\n // acquire metadata lock\n metadataLockId = await metadataStore.acquireMetadataLock(\n params.authKeyPair,\n );\n\n await metadataStore.batchAddSecretData({\n ...params,\n secretData: params.secretData.map((data) => ({\n data,\n })),\n });\n } finally {\n // release metadata lock\n if (metadataLockId) {\n try {\n await metadataStore.releaseMetadataLock(\n params.authKeyPair,\n metadataLockId,\n );\n } catch (error) {\n console.error('Failed to release metadata lock:', error);\n }\n }\n }\n }\n\n /**\n * This function fetches all secret data items associated with the given\n * auth pub key, decrypts, and returns them.\n *\n * @param params - The parameters for fetching the secret data.\n * @param params.decKey - The decryption key to be used to decrypt the secret data.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for fetching the secret data.\n *\n * @returns The decrypted secret data. Returns an empty array if no secret data is found.\n */\n async fetchAllSecretDataItems(\n params: FetchAllSecretDataParams,\n ): Promise<Uint8Array[]> {\n const metadataStore = await this.#createMetadataStore();\n const dataItems = await metadataStore.fetchAllSecretDataItems(\n params.decKey,\n params.authKeyPair,\n );\n return dataItems.map((dataItem: SecretDataItem) => dataItem.data);\n }\n\n /**\n * This function fetches the authentication public key.\n *\n * @param params - The parameters for getting the authentication public key.\n * @param params.authTokens - The auth tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n *\n * @returns The authentication public key.\n */\n async fetchAuthPubKey(\n params: FetchAuthPubKeyParams,\n ): Promise<FetchAuthPubKeyResult> {\n const {\n nodeAuthTokens,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n } = params;\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n return getPubKey({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n });\n }\n\n /**\n * This function looks up a password encryption key from the password\n * encryption key history.\n *\n * @param params - The parameters for getting the password encryption key.\n * @param params.targetPwPubKey - The target password public key.\n * @param params.curPwEncKey - The current password encryption key.\n * @param params.curAuthKeyPair - The current authentication key pair.\n * @param params.maxPwChainLength - Optional maximum password chain length\n * allowed to be traversed.\n *\n * @returns The password encryption key.\n */\n async recoverPwEncKey(\n params: RecoverPwEncKeyParams,\n ): Promise<RecoverPwEncKeyResult> {\n const {\n targetAuthPubKey: targetPwPubKey,\n curPwEncKey,\n curAuthKeyPair,\n maxPwChainLength = MAX_PASSWORD_CHAIN_LENGTH,\n } = params;\n\n let pwAndKeys = {\n password: '',\n encKey: curPwEncKey,\n authKeyPair: curAuthKeyPair,\n };\n\n for (let i = 0; i < maxPwChainLength; i++) {\n try {\n pwAndKeys = await this.#getPrevPasswordAndKeys({\n encKey: pwAndKeys.encKey,\n authKeyPair: pwAndKeys.authKeyPair,\n });\n if (equalBytes(pwAndKeys.authKeyPair.pk, targetPwPubKey)) {\n return { pwEncKey: pwAndKeys.encKey };\n }\n } catch (error) {\n throw TOPRFError.couldNotFetchPassword((error as Error).message);\n }\n }\n\n throw TOPRFError.maxKeyChainLengthExceeded();\n }\n\n /**\n * Gets the node details.\n *\n * @returns The node details containing the node endpoints, indexes and pubkeys.\n */\n async #getNodeDetails(): Promise<{\n nodeEndpoints: string[];\n nodeEndpointsMap: Record<number, string>;\n nodeIndexes: number[];\n nodePubkeys: INodePub[];\n }> {\n let finalIndexes = this.#nodeDetailsOverride?.indexes;\n let finalPubKeys = this.#nodeDetailsOverride?.pubKeys;\n let finalEndpoints = this.#nodeDetailsOverride?.endpoints;\n\n if (finalIndexes && finalPubKeys && Array.isArray(finalEndpoints)) {\n ToprfSecureBackup.#validateNodeDetailsLengths(\n finalIndexes,\n finalPubKeys,\n finalEndpoints,\n );\n return {\n nodeEndpoints: finalEndpoints,\n nodeEndpointsMap: createNodeEndpointsMap(finalEndpoints, finalIndexes),\n nodeIndexes: finalIndexes,\n nodePubkeys: finalPubKeys,\n };\n }\n\n const { torusNodeSSSEndpoints, torusIndexes, torusNodePub } =\n await this.#nodeDetailManager.getNodeDetails({\n verifier: 'auth-connection-id',\n verifierId: 'user-id',\n });\n\n finalIndexes ??= torusIndexes;\n finalPubKeys ??= torusNodePub;\n\n if (!Array.isArray(finalEndpoints)) {\n if (!torusNodeSSSEndpoints) {\n const message = 'Failed to get node details';\n throw new Error(message);\n }\n\n finalEndpoints = finalEndpoints\n ? torusNodeSSSEndpoints.map((endpoint) => {\n const url = new URL(endpoint);\n url.pathname = finalEndpoints as string;\n return url.href;\n })\n : torusNodeSSSEndpoints;\n }\n\n ToprfSecureBackup.#validateNodeDetailsLengths(\n finalIndexes,\n finalPubKeys,\n finalEndpoints,\n );\n\n return {\n nodeEndpoints: finalEndpoints,\n nodeEndpointsMap: createNodeEndpointsMap(finalEndpoints, finalIndexes),\n nodeIndexes: finalIndexes,\n nodePubkeys: finalPubKeys,\n };\n }\n\n /**\n * Creates and caches the metadata store instance.\n *\n * @returns The metadata store.\n */\n async #createMetadataStore(): Promise<MetadataStore> {\n if (this.#metadataStoreCache) {\n return this.#metadataStoreCache;\n }\n\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n const metadataEndpointsMap =\n await this.#getMetadataEndpointsMap(nodeEndpointsMap);\n const node1MetadataEndpoint = metadataEndpointsMap['1'];\n\n const metadataStore = new MetadataStore({\n metadataEndpoint: node1MetadataEndpoint,\n fetchMetadataAccessCreds: this.#fetchMetadataAccessCreds,\n });\n\n this.#metadataStoreCache = metadataStore;\n\n return metadataStore;\n }\n\n /**\n * Gets the metadata endpoints.\n *\n * @param nodeEndpointsMap - The node endpoints map.\n *\n * @returns The metadata endpoints map with node index as key and metadata endpoint as value.\n */\n async #getMetadataEndpointsMap(\n nodeEndpointsMap: Record<number, string>,\n ): Promise<{ [nodeIndex: string]: string }> {\n const metadataEndpointsMap: { [nodeIndex: string]: string } = {};\n Object.entries(nodeEndpointsMap).forEach(([key, value]) => {\n const url = new URL(value);\n metadataEndpointsMap[key] = `${url.origin}/metadata`;\n });\n return metadataEndpointsMap;\n }\n\n /**\n * Gets the previous password and keys.\n *\n * @param params - The parameters for getting the previous password and keys.\n * @param params.encKey - The encryption key to be used for decrypting the secret data.\n * @param params.authKeyPair - The authentication key pair to be used for authenticating the secret data.\n *\n * @returns The previous password and keys.\n */\n async #getPrevPasswordAndKeys(params: {\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n }): Promise<{\n password: string;\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n }> {\n const metadataStore = await this.#createMetadataStore();\n\n const pwBackupData = await metadataStore.fetchAllSecretDataItems(\n params.encKey,\n params.authKeyPair,\n PW_BACKUP_ITEM_ID,\n );\n\n if (pwBackupData.length === 0) {\n throw new Error('Failed to get previous password and keys');\n }\n\n // Parse JSON object.\n const pwBackupDataJson = deserializePwBackup(pwBackupData[0].data);\n\n return {\n password: pwBackupDataJson.pw,\n encKey: pwBackupDataJson.encKey,\n authKeyPair: pwBackupDataJson.authKeyPair,\n };\n }\n\n /**\n * Validates that the lengths of node detail arrays are consistent.\n *\n * @param indexes - Array of node indexes.\n * @param pubKeys - Array of node public keys.\n * @param endpoints - Array of SSS endpoint URLs.\n * @throws If lengths are inconsistent.\n */\n static #validateNodeDetailsLengths(\n indexes: unknown[],\n pubKeys: unknown[],\n endpoints: unknown[],\n ): void {\n if (\n indexes.length !== pubKeys.length ||\n indexes.length !== endpoints.length\n ) {\n const message =\n 'Node details arrays (indexes, pubKeys, endpoints) must have equal lengths';\n throw new Error(message);\n }\n }\n}\n\n/**\n * Serializes the password, encryption key, and authentication key pair into a JSON string.\n *\n * @param pw - The password.\n * @param encKey - The encryption key.\n * @param authKeyPair - The authentication key pair.\n * @returns The serialized JSON string.\n */\nfunction serializePwBackup(\n pw: string,\n encKey: Uint8Array,\n authKeyPair: KeyPair,\n): Uint8Array {\n return utf8ToBytes(\n JSON.stringify({\n pw,\n encKey: bytesToHex(encKey),\n authKeyPair: {\n sk: authKeyPair.sk.toString(),\n pk: bytesToHex(authKeyPair.pk),\n },\n }),\n );\n}\n\n/**\n * Deserializes the password, encryption key, and authentication key pair from a JSON string.\n *\n * @param data - The serialized JSON string.\n * @returns The password, encryption key, and authentication key pair.\n */\nfunction deserializePwBackup(data: Uint8Array): {\n pw: string;\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n} {\n const json = JSON.parse(bytesToUtf8(data));\n return {\n pw: json.pw,\n encKey: hexToBytes(json.encKey),\n authKeyPair: {\n sk: BigInt(json.authKeyPair.sk),\n pk: hexToBytes(json.authKeyPair.pk),\n },\n };\n}\n"]}

@@ -1,1 +0,1 @@

{"version":3,"file":"toprfSecureBackup.d.cts","sourceRoot":"","sources":["../src/toprfSecureBackup.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,2BAA2B,EAC5B,6BAA6B;AAY9B,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,kBAAkB,EAClB,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,qBAAqB,EAErB,qBAAqB,EACrB,mBAAmB,EACnB,wBAAwB,EACzB,yBAAqB;AAQtB,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAe;AAOzC;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,kBAAkB;;IAW1D;;;;;;;;;;;;;;;;OAgBG;gBACS,MAAM,EAAE;QAClB,OAAO,EAAE,2BAA2B,CAAC;QACrC,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;QAC1C,UAAU,CAAC,EAAE,UAAU,CAAC;KACzB;IAcD;;;;;;;;;;;;;;;;OAgBG;IACG,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA+D3E;;;;;;;;;;OAUG;IACG,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC;IA4BhC;;;;;;;;;;;;OAYG;IACG,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,I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AUG;IACG,eAAe,CACnB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAiBjC;;;;;;;;;;;;OAYG;IACG,eAAe,CACnB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;CA0MlC"}

@@ -68,4 +68,4 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

// fnd package internally caches results so preloading will speed up subsequent calls.
__classPrivateFieldGet(this, _ToprfSecureBackup_instances, "m", _ToprfSecureBackup_getNodeDetails).call(this).catch((error) => {
console.error('Error fetching node details', error);
__classPrivateFieldGet(this, _ToprfSecureBackup_instances, "m", _ToprfSecureBackup_getNodeDetails).call(this).catch(() => {
// ignore error
});

@@ -484,3 +484,3 @@ }

const { nodeEndpointsMap } = await __classPrivateFieldGet(this, _ToprfSecureBackup_instances, "m", _ToprfSecureBackup_getNodeDetails).call(this);
const authPubKey = await getPubKey({
return getPubKey({
authTokens: nodeAuthTokens,

@@ -492,3 +492,2 @@ nodeEndpointsMap,

});
return { authPubKey };
}

@@ -495,0 +494,0 @@ /**

@@ -1,1 +0,1 @@

{"version":3,"file":"toprfSecureBackup.mjs","sourceRoot":"","sources":["../src/toprfSecureBackup.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,qCAAqC;AAC5E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,6BAA6B;AAC/D,OAAO,EAAE,WAAW,EAAE,qCAAqC;AAC3D,OAAO,EAAE,SAAS,EAAE,gCAAgC;AACpD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,4BAA4B;AAK7D,OAAO,EAAE,iBAAiB,EAAE,sCAAsC;AAElE,OAAO,EAAE,gBAAgB,EAAE,kCAA8B;AACzD,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAChD,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,iBAAiB,EAClB,wBAAo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AC3C,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;QAC/B,WAAW,EAAE;YACX,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,EAAE,EAAE,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;SACpC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { keccak256AndHexify, remove0x } from '@metamask/auth-network-utils';\nimport { bytesToUtf8, equalBytes } from '@noble/ciphers/utils';\nimport { utf8ToBytes } from '@noble/curves/abstract/utils';\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { bytesToHex, hexToBytes } from '@noble/hashes/utils';\nimport type {\n INodePub,\n TORUS_SAPPHIRE_NETWORK_TYPE,\n} from '@toruslabs/constants';\nimport { NodeDetailManager } from '@toruslabs/fetch-node-details';\n\nimport { authenticateUser } from './authenticateRequest';\nimport { commitIdToken } from './commitRequest';\nimport {\n FIRST_KEY_INDEX,\n MAX_PASSWORD_CHAIN_LENGTH,\n PW_BACKUP_ITEM_ID,\n} from './constants';\nimport { TOPRFError } from './errors';\nimport { getPubKey } from './getPubKeyRequest';\nimport type {\n AuthenticateParams,\n AuthenticateResult,\n CreateEncryptionKeyParams,\n CreateEncryptionKeyResult,\n FetchAllSecretDataParams,\n IToprfSecureBackup,\n RecoverEncryptionKeyParams,\n RecoverEncryptionKeyResult,\n AddSecretDataItemParams,\n ChangeEncryptionKeyParams,\n ChangeEncryptionKeyResult,\n FetchAuthPubKeyParams,\n FetchAuthPubKeyResult,\n PersistLocalKeyParams,\n CreateLocalKeyParams,\n CreateLocalKeyResult,\n BatchAddSecretDataItemParams,\n RecoverPwEncKeyParams,\n KeyPair,\n RecoverPwEncKeyResult,\n NodeDetailsOverride,\n FetchMetadataAccessCreds,\n} from './interfaces';\nimport {\n deriveAuthenticationKeyPair,\n deriveEncryptionKey,\n derivePwEncKey,\n} from './keyDerivation';\nimport type { SecretDataItem } from './metadata';\nimport { MetadataStore } from './metadata';\nimport type { KeyDeriver } from './oprf';\nimport { OPRF, generateRandomScalar } from './oprf';\nimport { resetRateLimits } from './resetRateLimits';\nimport { storeKeyShares, changeKeyShares } from './storeSharesRequest';\nimport { recoverTOPRFSeed } from './toprfEvalRequest';\nimport { createNodeEndpointsMap } from './utils';\n\n/**\n * ToprfSecureBackup - The main class for the tOPRF Secure Backup service.\n *\n */\nexport class ToprfSecureBackup implements IToprfSecureBackup {\n readonly #nodeDetailManager: NodeDetailManager;\n\n readonly #nodeDetailsOverride?: NodeDetailsOverride;\n\n readonly #keyDeriver?: KeyDeriver;\n\n readonly #fetchMetadataAccessCreds: FetchMetadataAccessCreds;\n\n #metadataStoreCache: MetadataStore | undefined;\n\n /**\n * The constructor for the ToprfSecureBackup class.\n *\n * If `keyDeriver` is 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 * @param params - The parameters for the constructor.\n * @param params.network - The web3auth network to be used for key management\n * and authentication.\n * @param params.nodeDetailsOverride - Optional overrides for node details\n * like SSS endpoints, indexes, and public keys.\n * @param params.keyDeriver - Optional key deriver to be used for an\n * additional layer of security.\n * @param params.fetchMetadataAccessCreds - Function to fetch metadata access credentials.\n */\n constructor(params: {\n network: TORUS_SAPPHIRE_NETWORK_TYPE;\n fetchMetadataAccessCreds: FetchMetadataAccessCreds;\n nodeDetailsOverride?: NodeDetailsOverride;\n keyDeriver?: KeyDeriver;\n }) {\n this.#nodeDetailManager = new NodeDetailManager({\n network: params.network,\n });\n this.#nodeDetailsOverride = params.nodeDetailsOverride;\n this.#keyDeriver = params.keyDeriver;\n this.#fetchMetadataAccessCreds = params.fetchMetadataAccessCreds;\n // pre-fetch node details to speed up the first call to authenticate\n // fnd package internally caches results so preloading will speed up subsequent calls.\n this.#getNodeDetails().catch((error) => {\n console.error('Error fetching node details', error);\n });\n }\n\n /**\n * This function is used to authenticate the user by sending the oauth idToken to the nodes and\n * getting the authentication tokens from the nodes in return.\n *\n * @param params - The authentication parameters.\n * @param params.idTokens - An array of id tokens for authentication.\n * @param params.authConnectionId - The auth connection name to be used for the authenticate request\n * @param params.userId - The user id of the user issued by authentication service\n * @param params.groupedAuthConnectionParams - Optional groupedAuthConnectionParams to be used for the authenticate request.\n * You can pass this to use aggregate verifier.\n *\n * @returns - The authentication result containing the authentication tokens and a boolean indicating if the user is new or not.\n * isNewUser - Indicates if the user has completed the key setup process or not.\n * if `true` then the user hasn't completed the social + password setup process.\n * if `false` then the user has completed the social + password setup process.\n * @throws {Error} If idToken is older than 6 minutes.\n */\n async authenticate(params: AuthenticateParams): Promise<AuthenticateResult> {\n const { nodeEndpoints, nodeEndpointsMap } = await this.#getNodeDetails();\n let sessionPrivKey: Uint8Array | null = secp256k1.utils.randomPrivateKey();\n\n try {\n const sessionPubKey =\n secp256k1.ProjectivePoint.fromPrivateKey(sessionPrivKey);\n const sessionPubKeyX = sessionPubKey.x.toString(16);\n const sessionPubKeyY = sessionPubKey.y.toString(16);\n\n let hashedIdToken: string | undefined;\n if (params.groupedAuthConnectionId) {\n // if groupedAuthConnectionId is provided, we'll compute the hashedIdToken for the aggregate (single id) verifier login\n hashedIdToken = remove0x(\n keccak256AndHexify(Buffer.from(params.idTokens[0], 'utf8')),\n );\n }\n\n // commit idToken to nodes\n const commitmentResults = await commitIdToken({\n idToken: hashedIdToken ?? params.idTokens[0],\n authConnectionId:\n params.groupedAuthConnectionId ?? params.authConnectionId,\n sessionPubKeyX,\n sessionPubKeyY,\n endpoints: nodeEndpoints,\n });\n\n // use only the node indexes that returned valid commitment responses\n const selectedEndpointsMap = commitmentResults.reduce<\n Record<number, string>\n >((acc, result) => {\n acc[result.nodeIndex] = nodeEndpointsMap[result.nodeIndex];\n return acc;\n }, {});\n\n // get auth tokens from nodes\n const { authTokensData, isNewUser } = await authenticateUser({\n idToken: params.idTokens[0],\n authConnectionId: params.authConnectionId,\n userId: params.userId,\n sessionPrivateKey: sessionPrivKey,\n nodeEndpointsMap: selectedEndpointsMap,\n commitmentSignatures: commitmentResults,\n groupedAuthConnectionId: params.groupedAuthConnectionId,\n hashedIdToken,\n });\n\n return {\n nodeAuthTokens: authTokensData.map((tokenData) => ({\n authToken: tokenData.authToken,\n nodeIndex: tokenData.nodeIndex,\n nodePubKey: tokenData.nodePubKey,\n })),\n isNewUser,\n };\n } finally {\n // Clean up session private key\n sessionPrivKey.fill(0);\n sessionPrivKey = null;\n }\n }\n\n /**\n * This function locally creates an OPRF and encryption keys without storing them at the\n * key management service. It returns the OPRF key, derives the corresponding key seed,\n * authentication key pair and encryption key.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.password - New password of the user.\n * @param params.oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n *\n * @returns The OPRF key, seed, and derived keys.\n */\n async createLocalKey(\n params: CreateLocalKeyParams,\n ): Promise<CreateLocalKeyResult> {\n const { password, oprfKey = generateRandomScalar() } = params;\n let pwBytes: Uint8Array | null = null;\n\n try {\n pwBytes = utf8ToBytes(password);\n const seed = await OPRF.localEval(oprfKey, pwBytes, this.#keyDeriver);\n\n const authKeyPair = deriveAuthenticationKeyPair(seed);\n const encKey = deriveEncryptionKey(seed);\n const pwEncKey = derivePwEncKey(seed);\n\n return {\n oprfKey,\n seed,\n authKeyPair,\n encKey,\n pwEncKey,\n };\n } finally {\n // Clean up sensitive intermediate data\n if (pwBytes) {\n pwBytes.fill(0);\n pwBytes = null;\n }\n }\n }\n\n /**\n * This function persists the OPRF key's shares at the servers.\n *\n * @param params - The parameters for persisting the OPRF key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.oprfKey - The OPRF key to be persisted.\n * @param params.authPubKey - The authentication public key.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.keyShareIndex - The key share index to be persisted. Required only during key change, defaults to FIRST_KEY_INDEX for first-time storage.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user. Required only during key change, not needed for first-time storage.\n */\n async persistLocalKey(params: PersistLocalKeyParams): Promise<void> {\n const {\n nodeAuthTokens,\n oprfKey,\n authPubKey,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n keyShareIndex = FIRST_KEY_INDEX,\n oldAuthKeyPair,\n } = params;\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n\n const selectedEndpointsMap = nodeAuthTokens.reduce<Record<number, string>>(\n (acc, tokenData) => {\n acc[tokenData.nodeIndex] = nodeEndpointsMap[tokenData.nodeIndex];\n return acc;\n },\n {},\n );\n\n if (oldAuthKeyPair) {\n await changeKeyShares({\n nodeEndpointsMap: selectedEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authTokens: nodeAuthTokens,\n keyShareIndex,\n newOprfKey: oprfKey,\n newAuthPubKey: authPubKey,\n oldAuthPrivKey: oldAuthKeyPair.sk,\n });\n } else {\n await storeKeyShares({\n nodeEndpointsMap: selectedEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authTokens: nodeAuthTokens,\n keyShareIndex,\n oprfKey,\n authPubKey,\n });\n }\n }\n\n /**\n * This function creates the encryption key which is used to encrypt/decrypt the secret data.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.password - New password of the user.\n *\n * @returns The encryption key.\n */\n async createAndPersistEncKey(\n params: CreateEncryptionKeyParams,\n ): Promise<CreateEncryptionKeyResult> {\n const { nodeAuthTokens, password, authConnectionId, userId } = params;\n const { oprfKey, authKeyPair, encKey, pwEncKey } =\n await this.createLocalKey({\n password,\n });\n\n await this.persistLocalKey({\n nodeAuthTokens,\n oprfKey,\n authPubKey: authKeyPair.pk,\n authConnectionId,\n userId,\n });\n\n return {\n authKeyPair: {\n sk: authKeyPair.sk,\n pk: authKeyPair.pk,\n },\n encKey,\n pwEncKey,\n };\n }\n\n /**\n * This function recovers the encryption key which is used to decrypt the secret data.\n *\n * @param params - The parameters for recovering the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.password - The password of the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n *\n * @returns The encryption key result with auth key pair, encryption key and key share index.\n */\n async recoverEncKey(\n params: RecoverEncryptionKeyParams,\n ): Promise<RecoverEncryptionKeyResult> {\n const {\n nodeAuthTokens,\n password,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n } = params;\n\n let pwBytes: Uint8Array | null = null;\n let seed: Uint8Array | null = null;\n\n try {\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n pwBytes = utf8ToBytes(password);\n\n const { seed: seedValue, keyShareIndex } = await recoverTOPRFSeed({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n userInput: pwBytes,\n keyDeriver: this.#keyDeriver,\n });\n\n seed = seedValue;\n\n const authKeyPair = deriveAuthenticationKeyPair(seed);\n const encKey = deriveEncryptionKey(seed);\n const pwEncKey = derivePwEncKey(seed);\n\n const rateLimitResetResult = new Promise<void>((resolve, reject) => {\n resetRateLimits({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authPrivKey: authKeyPair.sk,\n })\n .then(() => {\n return resolve();\n })\n .catch((error) => {\n reject(error as Error);\n });\n });\n\n return {\n authKeyPair,\n encKey,\n pwEncKey,\n keyShareIndex,\n rateLimitResetResult,\n };\n } finally {\n // Clean up sensitive intermediate data\n if (pwBytes) {\n pwBytes.fill(0);\n pwBytes = null;\n }\n\n if (seed) {\n seed.fill(0);\n seed = null;\n }\n }\n }\n\n /**\n * This function replaces the existing encryption key with a new one by generating a new key from\n * the new password, copying all existing secret data encrypted with the old key to be encrypted\n * with the new key, and updating the key shares on the nodes.\n *\n * @param params - The parameters for changing the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n * @param params.oldEncKey - The old encryption key of the user.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user.\n * @param params.newKeyShareIndex - The key share index to be used for the new key.\n * @param params.newPassword - Optional new password of the user, either this or pregeneratedOprfKey is required.\n * @param params.pregeneratedOprfKey - Optional pregenerated OPRF key to be used for the key change, if not provided, a new key will be generated from the new password.\n *\n * @returns The new key pair and encryption key.\n * @throws {Error} If both newPassword and pregeneratedOprfKey are provided.\n * @throws {Error} If neither newPassword nor pregeneratedOprfKey is provided.\n */\n async changeEncKey(\n params: ChangeEncryptionKeyParams,\n ): Promise<ChangeEncryptionKeyResult> {\n const {\n nodeAuthTokens,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n oldEncKey,\n oldPwEncKey,\n oldAuthKeyPair,\n newPassword,\n newKeyShareIndex,\n pregeneratedOprfKey,\n } = params;\n\n if (!pregeneratedOprfKey && !newPassword) {\n throw new Error('Either newPassword or pregeneratedOprfKey is required');\n }\n\n if (pregeneratedOprfKey && newPassword) {\n throw new Error(\n 'Only one of newPassword or pregeneratedOprfKey is allowed',\n );\n }\n\n // if newPassword is provided, create a new key from the password\n // else use the pregeneratedOprfKey, both can't be undefined as per check above.\n const { oprfKey, authKeyPair, encKey, pwEncKey } = newPassword\n ? await this.createLocalKey({ password: newPassword })\n : (pregeneratedOprfKey as CreateLocalKeyResult);\n\n let metadataStore: MetadataStore | undefined;\n let oldMetadataLockId: string | undefined;\n let newMetadataLockId: string | undefined;\n\n try {\n metadataStore = await this.#createMetadataStore();\n\n [oldMetadataLockId, newMetadataLockId] = await Promise.all([\n metadataStore.acquireMetadataLock(oldAuthKeyPair),\n metadataStore.acquireMetadataLock(authKeyPair),\n ]);\n\n const existingData = (\n await metadataStore.fetchAllSecretDataItems(oldEncKey, oldAuthKeyPair)\n ).map((dataItem) => ({ data: dataItem.data }));\n\n // Validate that this is actually a key change scenario\n if (!existingData || existingData.length === 0) {\n throw new Error('No existing data found to change key');\n }\n\n const pwBackup: SecretDataItem = {\n data: serializePwBackup('', oldPwEncKey, oldAuthKeyPair),\n itemId: PW_BACKUP_ITEM_ID,\n };\n\n const secretDataItems = [pwBackup, ...existingData];\n const encKeys = [pwEncKey, ...existingData.map(() => encKey)];\n await metadataStore.batchAddSecretData({\n secretData: secretDataItems,\n encKey: encKeys,\n authKeyPair,\n });\n\n await this.persistLocalKey({\n nodeAuthTokens,\n oprfKey,\n authPubKey: authKeyPair.pk,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n keyShareIndex: newKeyShareIndex,\n oldAuthKeyPair,\n });\n\n return { authKeyPair, encKey, pwEncKey };\n } finally {\n if (metadataStore && oldMetadataLockId && newMetadataLockId) {\n try {\n await Promise.all([\n metadataStore.releaseMetadataLock(\n oldAuthKeyPair,\n oldMetadataLockId,\n ),\n metadataStore.releaseMetadataLock(authKeyPair, newMetadataLockId),\n ]);\n } catch (error) {\n console.error('Failed to release metadata lock:', error);\n }\n }\n }\n }\n\n /**\n * This function encrypts the secret data using the encryption key and stores it nodes metadata store in encrypted form.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key which is used to encrypt the secret data before storing it.\n * @param params.secretData - The array of secret data to be registered.\n * @param params.authKeyPair - The authentication key pair which is used to authenticate the user to the storage service.\n */\n async addSecretDataItem(params: AddSecretDataItemParams): Promise<void> {\n const metadataStore = await this.#createMetadataStore();\n await metadataStore.addSecretDataItem({\n ...params,\n secretData: {\n data: params.secretData,\n },\n });\n }\n\n /**\n * This function encrypts the array of secret data using the encryption key and stores in the metadata store in encrypted form as a batch.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.secretData - The array of secret data to be stored.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n */\n async batchAddSecretDataItems(\n params: BatchAddSecretDataItemParams,\n ): Promise<void> {\n const metadataStore = await this.#createMetadataStore();\n\n let metadataLockId: string | undefined;\n\n try {\n // acquire metadata lock\n metadataLockId = await metadataStore.acquireMetadataLock(\n params.authKeyPair,\n );\n\n await metadataStore.batchAddSecretData({\n ...params,\n secretData: params.secretData.map((data) => ({\n data,\n })),\n });\n } finally {\n // release metadata lock\n if (metadataLockId) {\n try {\n await metadataStore.releaseMetadataLock(\n params.authKeyPair,\n metadataLockId,\n );\n } catch (error) {\n console.error('Failed to release metadata lock:', error);\n }\n }\n }\n }\n\n /**\n * This function fetches all secret data items associated with the given\n * auth pub key, decrypts, and returns them.\n *\n * @param params - The parameters for fetching the secret data.\n * @param params.decKey - The decryption key to be used to decrypt the secret data.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for fetching the secret data.\n *\n * @returns The decrypted secret data. Returns an empty array if no secret data is found.\n */\n async fetchAllSecretDataItems(\n params: FetchAllSecretDataParams,\n ): Promise<Uint8Array[]> {\n const metadataStore = await this.#createMetadataStore();\n const dataItems = await metadataStore.fetchAllSecretDataItems(\n params.decKey,\n params.authKeyPair,\n );\n return dataItems.map((dataItem: SecretDataItem) => dataItem.data);\n }\n\n /**\n * This function fetches the authentication public key.\n *\n * @param params - The parameters for getting the authentication public key.\n * @param params.authTokens - The auth tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n *\n * @returns The authentication public key.\n */\n async fetchAuthPubKey(\n params: FetchAuthPubKeyParams,\n ): Promise<FetchAuthPubKeyResult> {\n const {\n nodeAuthTokens,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n } = params;\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n const authPubKey = await getPubKey({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n });\n return { authPubKey };\n }\n\n /**\n * This function looks up a password encryption key from the password\n * encryption key history.\n *\n * @param params - The parameters for getting the password encryption key.\n * @param params.targetPwPubKey - The target password public key.\n * @param params.curPwEncKey - The current password encryption key.\n * @param params.curAuthKeyPair - The current authentication key pair.\n * @param params.maxPwChainLength - Optional maximum password chain length\n * allowed to be traversed.\n *\n * @returns The password encryption key.\n */\n async recoverPwEncKey(\n params: RecoverPwEncKeyParams,\n ): Promise<RecoverPwEncKeyResult> {\n const {\n targetAuthPubKey: targetPwPubKey,\n curPwEncKey,\n curAuthKeyPair,\n maxPwChainLength = MAX_PASSWORD_CHAIN_LENGTH,\n } = params;\n\n let pwAndKeys = {\n password: '',\n encKey: curPwEncKey,\n authKeyPair: curAuthKeyPair,\n };\n\n for (let i = 0; i < maxPwChainLength; i++) {\n try {\n pwAndKeys = await this.#getPrevPasswordAndKeys({\n encKey: pwAndKeys.encKey,\n authKeyPair: pwAndKeys.authKeyPair,\n });\n if (equalBytes(pwAndKeys.authKeyPair.pk, targetPwPubKey)) {\n return { pwEncKey: pwAndKeys.encKey };\n }\n } catch (error) {\n throw TOPRFError.couldNotFetchPassword((error as Error).message);\n }\n }\n\n throw TOPRFError.maxKeyChainLengthExceeded();\n }\n\n /**\n * Gets the node details.\n *\n * @returns The node details containing the node endpoints, indexes and pubkeys.\n */\n async #getNodeDetails(): Promise<{\n nodeEndpoints: string[];\n nodeEndpointsMap: Record<number, string>;\n nodeIndexes: number[];\n nodePubkeys: INodePub[];\n }> {\n let finalIndexes = this.#nodeDetailsOverride?.indexes;\n let finalPubKeys = this.#nodeDetailsOverride?.pubKeys;\n let finalEndpoints = this.#nodeDetailsOverride?.endpoints;\n\n if (finalIndexes && finalPubKeys && Array.isArray(finalEndpoints)) {\n ToprfSecureBackup.#validateNodeDetailsLengths(\n finalIndexes,\n finalPubKeys,\n finalEndpoints,\n );\n return {\n nodeEndpoints: finalEndpoints,\n nodeEndpointsMap: createNodeEndpointsMap(finalEndpoints, finalIndexes),\n nodeIndexes: finalIndexes,\n nodePubkeys: finalPubKeys,\n };\n }\n\n const { torusNodeSSSEndpoints, torusIndexes, torusNodePub } =\n await this.#nodeDetailManager.getNodeDetails({\n verifier: 'auth-connection-id',\n verifierId: 'user-id',\n });\n\n finalIndexes ??= torusIndexes;\n finalPubKeys ??= torusNodePub;\n\n if (!Array.isArray(finalEndpoints)) {\n if (!torusNodeSSSEndpoints) {\n const message = 'Failed to get node details';\n throw new Error(message);\n }\n\n finalEndpoints = finalEndpoints\n ? torusNodeSSSEndpoints.map((endpoint) => {\n const url = new URL(endpoint);\n url.pathname = finalEndpoints as string;\n return url.href;\n })\n : torusNodeSSSEndpoints;\n }\n\n ToprfSecureBackup.#validateNodeDetailsLengths(\n finalIndexes,\n finalPubKeys,\n finalEndpoints,\n );\n\n return {\n nodeEndpoints: finalEndpoints,\n nodeEndpointsMap: createNodeEndpointsMap(finalEndpoints, finalIndexes),\n nodeIndexes: finalIndexes,\n nodePubkeys: finalPubKeys,\n };\n }\n\n /**\n * Creates and caches the metadata store instance.\n *\n * @returns The metadata store.\n */\n async #createMetadataStore(): Promise<MetadataStore> {\n if (this.#metadataStoreCache) {\n return this.#metadataStoreCache;\n }\n\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n const metadataEndpointsMap =\n await this.#getMetadataEndpointsMap(nodeEndpointsMap);\n const node1MetadataEndpoint = metadataEndpointsMap['1'];\n\n const metadataStore = new MetadataStore({\n metadataEndpoint: node1MetadataEndpoint,\n fetchMetadataAccessCreds: this.#fetchMetadataAccessCreds,\n });\n\n this.#metadataStoreCache = metadataStore;\n\n return metadataStore;\n }\n\n /**\n * Gets the metadata endpoints.\n *\n * @param nodeEndpointsMap - The node endpoints map.\n *\n * @returns The metadata endpoints map with node index as key and metadata endpoint as value.\n */\n async #getMetadataEndpointsMap(\n nodeEndpointsMap: Record<number, string>,\n ): Promise<{ [nodeIndex: string]: string }> {\n const metadataEndpointsMap: { [nodeIndex: string]: string } = {};\n Object.entries(nodeEndpointsMap).forEach(([key, value]) => {\n const url = new URL(value);\n metadataEndpointsMap[key] = `${url.origin}/metadata`;\n });\n return metadataEndpointsMap;\n }\n\n /**\n * Gets the previous password and keys.\n *\n * @param params - The parameters for getting the previous password and keys.\n * @param params.encKey - The encryption key to be used for decrypting the secret data.\n * @param params.authKeyPair - The authentication key pair to be used for authenticating the secret data.\n *\n * @returns The previous password and keys.\n */\n async #getPrevPasswordAndKeys(params: {\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n }): Promise<{\n password: string;\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n }> {\n const metadataStore = await this.#createMetadataStore();\n\n const pwBackupData = await metadataStore.fetchAllSecretDataItems(\n params.encKey,\n params.authKeyPair,\n PW_BACKUP_ITEM_ID,\n );\n\n if (pwBackupData.length === 0) {\n throw new Error('Failed to get previous password and keys');\n }\n\n // Parse JSON object.\n const pwBackupDataJson = deserializePwBackup(pwBackupData[0].data);\n\n return {\n password: pwBackupDataJson.pw,\n encKey: pwBackupDataJson.encKey,\n authKeyPair: pwBackupDataJson.authKeyPair,\n };\n }\n\n /**\n * Validates that the lengths of node detail arrays are consistent.\n *\n * @param indexes - Array of node indexes.\n * @param pubKeys - Array of node public keys.\n * @param endpoints - Array of SSS endpoint URLs.\n * @throws If lengths are inconsistent.\n */\n static #validateNodeDetailsLengths(\n indexes: unknown[],\n pubKeys: unknown[],\n endpoints: unknown[],\n ): void {\n if (\n indexes.length !== pubKeys.length ||\n indexes.length !== endpoints.length\n ) {\n const message =\n 'Node details arrays (indexes, pubKeys, endpoints) must have equal lengths';\n throw new Error(message);\n }\n }\n}\n\n/**\n * Serializes the password, encryption key, and authentication key pair into a JSON string.\n *\n * @param pw - The password.\n * @param encKey - The encryption key.\n * @param authKeyPair - The authentication key pair.\n * @returns The serialized JSON string.\n */\nfunction serializePwBackup(\n pw: string,\n encKey: Uint8Array,\n authKeyPair: KeyPair,\n): Uint8Array {\n return utf8ToBytes(\n JSON.stringify({\n pw,\n encKey: bytesToHex(encKey),\n authKeyPair: {\n sk: authKeyPair.sk.toString(),\n pk: bytesToHex(authKeyPair.pk),\n },\n }),\n );\n}\n\n/**\n * Deserializes the password, encryption key, and authentication key pair from a JSON string.\n *\n * @param data - The serialized JSON string.\n * @returns The password, encryption key, and authentication key pair.\n */\nfunction deserializePwBackup(data: Uint8Array): {\n pw: string;\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n} {\n const json = JSON.parse(bytesToUtf8(data));\n return {\n pw: json.pw,\n encKey: hexToBytes(json.encKey),\n authKeyPair: {\n sk: BigInt(json.authKeyPair.sk),\n pk: hexToBytes(json.authKeyPair.pk),\n },\n };\n}\n"]}
{"version":3,"file":"toprfSecureBackup.mjs","sourceRoot":"","sources":["../src/toprfSecureBackup.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,qCAAqC;AAC5E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,6BAA6B;AAC/D,OAAO,EAAE,WAAW,EAAE,qCAAqC;AAC3D,OAAO,EAAE,SAAS,EAAE,gCAAgC;AACpD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,4BAA4B;AAK7D,OAAO,EAAE,iBAAiB,EAAE,sCAAsC;AAElE,OAAO,EAAE,gBAAgB,EAAE,kCAA8B;AACzD,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAChD,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,iBAAiB,EAClB,wBAAoB;AACrB,OAAO,EAAE,UAAU,EAAE,qBAAiB;AACtC,OAAO,EAAE,SAAS,EAAE,+BAA2B;AAyB/C,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,cAAc,EACf,4BAAwB;AAEzB,OAAO,EAAE,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Content":["import { keccak256AndHexify, remove0x } from '@metamask/auth-network-utils';\nimport { bytesToUtf8, equalBytes } from '@noble/ciphers/utils';\nimport { utf8ToBytes } from '@noble/curves/abstract/utils';\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { bytesToHex, hexToBytes } from '@noble/hashes/utils';\nimport type {\n INodePub,\n TORUS_SAPPHIRE_NETWORK_TYPE,\n} from '@toruslabs/constants';\nimport { NodeDetailManager } from '@toruslabs/fetch-node-details';\n\nimport { authenticateUser } from './authenticateRequest';\nimport { commitIdToken } from './commitRequest';\nimport {\n FIRST_KEY_INDEX,\n MAX_PASSWORD_CHAIN_LENGTH,\n PW_BACKUP_ITEM_ID,\n} from './constants';\nimport { TOPRFError } from './errors';\nimport { getPubKey } from './getPubKeyRequest';\nimport type {\n AuthenticateParams,\n AuthenticateResult,\n CreateEncryptionKeyParams,\n CreateEncryptionKeyResult,\n FetchAllSecretDataParams,\n IToprfSecureBackup,\n RecoverEncryptionKeyParams,\n RecoverEncryptionKeyResult,\n AddSecretDataItemParams,\n ChangeEncryptionKeyParams,\n ChangeEncryptionKeyResult,\n FetchAuthPubKeyParams,\n FetchAuthPubKeyResult,\n PersistLocalKeyParams,\n CreateLocalKeyParams,\n CreateLocalKeyResult,\n BatchAddSecretDataItemParams,\n RecoverPwEncKeyParams,\n KeyPair,\n RecoverPwEncKeyResult,\n NodeDetailsOverride,\n FetchMetadataAccessCreds,\n} from './interfaces';\nimport {\n deriveAuthenticationKeyPair,\n deriveEncryptionKey,\n derivePwEncKey,\n} from './keyDerivation';\nimport type { SecretDataItem } from './metadata';\nimport { MetadataStore } from './metadata';\nimport type { KeyDeriver } from './oprf';\nimport { OPRF, generateRandomScalar } from './oprf';\nimport { resetRateLimits } from './resetRateLimits';\nimport { storeKeyShares, changeKeyShares } from './storeSharesRequest';\nimport { recoverTOPRFSeed } from './toprfEvalRequest';\nimport { createNodeEndpointsMap } from './utils';\n\n/**\n * ToprfSecureBackup - The main class for the tOPRF Secure Backup service.\n *\n */\nexport class ToprfSecureBackup implements IToprfSecureBackup {\n readonly #nodeDetailManager: NodeDetailManager;\n\n readonly #nodeDetailsOverride?: NodeDetailsOverride;\n\n readonly #keyDeriver?: KeyDeriver;\n\n readonly #fetchMetadataAccessCreds: FetchMetadataAccessCreds;\n\n #metadataStoreCache: MetadataStore | undefined;\n\n /**\n * The constructor for the ToprfSecureBackup class.\n *\n * If `keyDeriver` is 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 * @param params - The parameters for the constructor.\n * @param params.network - The web3auth network to be used for key management\n * and authentication.\n * @param params.nodeDetailsOverride - Optional overrides for node details\n * like SSS endpoints, indexes, and public keys.\n * @param params.keyDeriver - Optional key deriver to be used for an\n * additional layer of security.\n * @param params.fetchMetadataAccessCreds - Function to fetch metadata access credentials.\n */\n constructor(params: {\n network: TORUS_SAPPHIRE_NETWORK_TYPE;\n fetchMetadataAccessCreds: FetchMetadataAccessCreds;\n nodeDetailsOverride?: NodeDetailsOverride;\n keyDeriver?: KeyDeriver;\n }) {\n this.#nodeDetailManager = new NodeDetailManager({\n network: params.network,\n });\n this.#nodeDetailsOverride = params.nodeDetailsOverride;\n this.#keyDeriver = params.keyDeriver;\n this.#fetchMetadataAccessCreds = params.fetchMetadataAccessCreds;\n // pre-fetch node details to speed up the first call to authenticate\n // fnd package internally caches results so preloading will speed up subsequent calls.\n this.#getNodeDetails().catch(() => {\n // ignore error\n });\n }\n\n /**\n * This function is used to authenticate the user by sending the oauth idToken to the nodes and\n * getting the authentication tokens from the nodes in return.\n *\n * @param params - The authentication parameters.\n * @param params.idTokens - An array of id tokens for authentication.\n * @param params.authConnectionId - The auth connection name to be used for the authenticate request\n * @param params.userId - The user id of the user issued by authentication service\n * @param params.groupedAuthConnectionParams - Optional groupedAuthConnectionParams to be used for the authenticate request.\n * You can pass this to use aggregate verifier.\n *\n * @returns - The authentication result containing the authentication tokens and a boolean indicating if the user is new or not.\n * isNewUser - Indicates if the user has completed the key setup process or not.\n * if `true` then the user hasn't completed the social + password setup process.\n * if `false` then the user has completed the social + password setup process.\n * @throws {Error} If idToken is older than 6 minutes.\n */\n async authenticate(params: AuthenticateParams): Promise<AuthenticateResult> {\n const { nodeEndpoints, nodeEndpointsMap } = await this.#getNodeDetails();\n let sessionPrivKey: Uint8Array | null = secp256k1.utils.randomPrivateKey();\n\n try {\n const sessionPubKey =\n secp256k1.ProjectivePoint.fromPrivateKey(sessionPrivKey);\n const sessionPubKeyX = sessionPubKey.x.toString(16);\n const sessionPubKeyY = sessionPubKey.y.toString(16);\n\n let hashedIdToken: string | undefined;\n if (params.groupedAuthConnectionId) {\n // if groupedAuthConnectionId is provided, we'll compute the hashedIdToken for the aggregate (single id) verifier login\n hashedIdToken = remove0x(\n keccak256AndHexify(Buffer.from(params.idTokens[0], 'utf8')),\n );\n }\n\n // commit idToken to nodes\n const commitmentResults = await commitIdToken({\n idToken: hashedIdToken ?? params.idTokens[0],\n authConnectionId:\n params.groupedAuthConnectionId ?? params.authConnectionId,\n sessionPubKeyX,\n sessionPubKeyY,\n endpoints: nodeEndpoints,\n });\n\n // use only the node indexes that returned valid commitment responses\n const selectedEndpointsMap = commitmentResults.reduce<\n Record<number, string>\n >((acc, result) => {\n acc[result.nodeIndex] = nodeEndpointsMap[result.nodeIndex];\n return acc;\n }, {});\n\n // get auth tokens from nodes\n const { authTokensData, isNewUser } = await authenticateUser({\n idToken: params.idTokens[0],\n authConnectionId: params.authConnectionId,\n userId: params.userId,\n sessionPrivateKey: sessionPrivKey,\n nodeEndpointsMap: selectedEndpointsMap,\n commitmentSignatures: commitmentResults,\n groupedAuthConnectionId: params.groupedAuthConnectionId,\n hashedIdToken,\n });\n\n return {\n nodeAuthTokens: authTokensData.map((tokenData) => ({\n authToken: tokenData.authToken,\n nodeIndex: tokenData.nodeIndex,\n nodePubKey: tokenData.nodePubKey,\n })),\n isNewUser,\n };\n } finally {\n // Clean up session private key\n sessionPrivKey.fill(0);\n sessionPrivKey = null;\n }\n }\n\n /**\n * This function locally creates an OPRF and encryption keys without storing them at the\n * key management service. It returns the OPRF key, derives the corresponding key seed,\n * authentication key pair and encryption key.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.password - New password of the user.\n * @param params.oprfKey - Optional OPRF key to be used for the OPRF evaluation.\n *\n * @returns The OPRF key, seed, and derived keys.\n */\n async createLocalKey(\n params: CreateLocalKeyParams,\n ): Promise<CreateLocalKeyResult> {\n const { password, oprfKey = generateRandomScalar() } = params;\n let pwBytes: Uint8Array | null = null;\n\n try {\n pwBytes = utf8ToBytes(password);\n const seed = await OPRF.localEval(oprfKey, pwBytes, this.#keyDeriver);\n\n const authKeyPair = deriveAuthenticationKeyPair(seed);\n const encKey = deriveEncryptionKey(seed);\n const pwEncKey = derivePwEncKey(seed);\n\n return {\n oprfKey,\n seed,\n authKeyPair,\n encKey,\n pwEncKey,\n };\n } finally {\n // Clean up sensitive intermediate data\n if (pwBytes) {\n pwBytes.fill(0);\n pwBytes = null;\n }\n }\n }\n\n /**\n * This function persists the OPRF key's shares at the servers.\n *\n * @param params - The parameters for persisting the OPRF key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.oprfKey - The OPRF key to be persisted.\n * @param params.authPubKey - The authentication public key.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user issued by authentication service.\n * @param params.keyShareIndex - The key share index to be persisted. Required only during key change, defaults to FIRST_KEY_INDEX for first-time storage.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user. Required only during key change, not needed for first-time storage.\n */\n async persistLocalKey(params: PersistLocalKeyParams): Promise<void> {\n const {\n nodeAuthTokens,\n oprfKey,\n authPubKey,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n keyShareIndex = FIRST_KEY_INDEX,\n oldAuthKeyPair,\n } = params;\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n\n const selectedEndpointsMap = nodeAuthTokens.reduce<Record<number, string>>(\n (acc, tokenData) => {\n acc[tokenData.nodeIndex] = nodeEndpointsMap[tokenData.nodeIndex];\n return acc;\n },\n {},\n );\n\n if (oldAuthKeyPair) {\n await changeKeyShares({\n nodeEndpointsMap: selectedEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authTokens: nodeAuthTokens,\n keyShareIndex,\n newOprfKey: oprfKey,\n newAuthPubKey: authPubKey,\n oldAuthPrivKey: oldAuthKeyPair.sk,\n });\n } else {\n await storeKeyShares({\n nodeEndpointsMap: selectedEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authTokens: nodeAuthTokens,\n keyShareIndex,\n oprfKey,\n authPubKey,\n });\n }\n }\n\n /**\n * This function creates the encryption key which is used to encrypt/decrypt the secret data.\n *\n * @param params - The parameters for creating the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.password - New password of the user.\n *\n * @returns The encryption key.\n */\n async createAndPersistEncKey(\n params: CreateEncryptionKeyParams,\n ): Promise<CreateEncryptionKeyResult> {\n const { nodeAuthTokens, password, authConnectionId, userId } = params;\n const { oprfKey, authKeyPair, encKey, pwEncKey } =\n await this.createLocalKey({\n password,\n });\n\n await this.persistLocalKey({\n nodeAuthTokens,\n oprfKey,\n authPubKey: authKeyPair.pk,\n authConnectionId,\n userId,\n });\n\n return {\n authKeyPair: {\n sk: authKeyPair.sk,\n pk: authKeyPair.pk,\n },\n encKey,\n pwEncKey,\n };\n }\n\n /**\n * This function recovers the encryption key which is used to decrypt the secret data.\n *\n * @param params - The parameters for recovering the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.password - The password of the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n *\n * @returns The encryption key result with auth key pair, encryption key and key share index.\n */\n async recoverEncKey(\n params: RecoverEncryptionKeyParams,\n ): Promise<RecoverEncryptionKeyResult> {\n const {\n nodeAuthTokens,\n password,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n } = params;\n\n let pwBytes: Uint8Array | null = null;\n let seed: Uint8Array | null = null;\n\n try {\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n pwBytes = utf8ToBytes(password);\n\n const { seed: seedValue, keyShareIndex } = await recoverTOPRFSeed({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n userInput: pwBytes,\n keyDeriver: this.#keyDeriver,\n });\n\n seed = seedValue;\n\n const authKeyPair = deriveAuthenticationKeyPair(seed);\n const encKey = deriveEncryptionKey(seed);\n const pwEncKey = derivePwEncKey(seed);\n\n const rateLimitResetResult = new Promise<void>((resolve, reject) => {\n resetRateLimits({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n authPrivKey: authKeyPair.sk,\n })\n .then(() => {\n return resolve();\n })\n .catch((error) => {\n reject(error as Error);\n });\n });\n\n return {\n authKeyPair,\n encKey,\n pwEncKey,\n keyShareIndex,\n rateLimitResetResult,\n };\n } finally {\n // Clean up sensitive intermediate data\n if (pwBytes) {\n pwBytes.fill(0);\n pwBytes = null;\n }\n\n if (seed) {\n seed.fill(0);\n seed = null;\n }\n }\n }\n\n /**\n * This function replaces the existing encryption key with a new one by generating a new key from\n * the new password, copying all existing secret data encrypted with the old key to be encrypted\n * with the new key, and updating the key shares on the nodes.\n *\n * @param params - The parameters for changing the encryption key.\n * @param params.nodeAuthTokens - The tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n * @param params.oldEncKey - The old encryption key of the user.\n * @param params.oldAuthKeyPair - The old authentication key pair of the user.\n * @param params.newKeyShareIndex - The key share index to be used for the new key.\n * @param params.newPassword - Optional new password of the user, either this or pregeneratedOprfKey is required.\n * @param params.pregeneratedOprfKey - Optional pregenerated OPRF key to be used for the key change, if not provided, a new key will be generated from the new password.\n *\n * @returns The new key pair and encryption key.\n * @throws {Error} If both newPassword and pregeneratedOprfKey are provided.\n * @throws {Error} If neither newPassword nor pregeneratedOprfKey is provided.\n */\n async changeEncKey(\n params: ChangeEncryptionKeyParams,\n ): Promise<ChangeEncryptionKeyResult> {\n const {\n nodeAuthTokens,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n oldEncKey,\n oldPwEncKey,\n oldAuthKeyPair,\n newPassword,\n newKeyShareIndex,\n pregeneratedOprfKey,\n } = params;\n\n if (!pregeneratedOprfKey && !newPassword) {\n throw new Error('Either newPassword or pregeneratedOprfKey is required');\n }\n\n if (pregeneratedOprfKey && newPassword) {\n throw new Error(\n 'Only one of newPassword or pregeneratedOprfKey is allowed',\n );\n }\n\n // if newPassword is provided, create a new key from the password\n // else use the pregeneratedOprfKey, both can't be undefined as per check above.\n const { oprfKey, authKeyPair, encKey, pwEncKey } = newPassword\n ? await this.createLocalKey({ password: newPassword })\n : (pregeneratedOprfKey as CreateLocalKeyResult);\n\n let metadataStore: MetadataStore | undefined;\n let oldMetadataLockId: string | undefined;\n let newMetadataLockId: string | undefined;\n\n try {\n metadataStore = await this.#createMetadataStore();\n\n [oldMetadataLockId, newMetadataLockId] = await Promise.all([\n metadataStore.acquireMetadataLock(oldAuthKeyPair),\n metadataStore.acquireMetadataLock(authKeyPair),\n ]);\n\n const existingData = (\n await metadataStore.fetchAllSecretDataItems(oldEncKey, oldAuthKeyPair)\n ).map((dataItem) => ({ data: dataItem.data }));\n\n // Validate that this is actually a key change scenario\n if (!existingData || existingData.length === 0) {\n throw new Error('No existing data found to change key');\n }\n\n const pwBackup: SecretDataItem = {\n data: serializePwBackup('', oldPwEncKey, oldAuthKeyPair),\n itemId: PW_BACKUP_ITEM_ID,\n };\n\n const secretDataItems = [pwBackup, ...existingData];\n const encKeys = [pwEncKey, ...existingData.map(() => encKey)];\n await metadataStore.batchAddSecretData({\n secretData: secretDataItems,\n encKey: encKeys,\n authKeyPair,\n });\n\n await this.persistLocalKey({\n nodeAuthTokens,\n oprfKey,\n authPubKey: authKeyPair.pk,\n authConnectionId,\n groupedAuthConnectionId,\n userId,\n keyShareIndex: newKeyShareIndex,\n oldAuthKeyPair,\n });\n\n return { authKeyPair, encKey, pwEncKey };\n } finally {\n if (metadataStore && oldMetadataLockId && newMetadataLockId) {\n try {\n await Promise.all([\n metadataStore.releaseMetadataLock(\n oldAuthKeyPair,\n oldMetadataLockId,\n ),\n metadataStore.releaseMetadataLock(authKeyPair, newMetadataLockId),\n ]);\n } catch (error) {\n console.error('Failed to release metadata lock:', error);\n }\n }\n }\n }\n\n /**\n * This function encrypts the secret data using the encryption key and stores it nodes metadata store in encrypted form.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key which is used to encrypt the secret data before storing it.\n * @param params.secretData - The array of secret data to be registered.\n * @param params.authKeyPair - The authentication key pair which is used to authenticate the user to the storage service.\n */\n async addSecretDataItem(params: AddSecretDataItemParams): Promise<void> {\n const metadataStore = await this.#createMetadataStore();\n await metadataStore.addSecretDataItem({\n ...params,\n secretData: {\n data: params.secretData,\n },\n });\n }\n\n /**\n * This function encrypts the array of secret data using the encryption key and stores in the metadata store in encrypted form as a batch.\n *\n * @param params - The parameters for registering new secret data.\n * @param params.encKey - The encryption key to be used to encrypt the secret data before storing it.\n * @param params.secretData - The array of secret data to be stored.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for storing the secret data.\n */\n async batchAddSecretDataItems(\n params: BatchAddSecretDataItemParams,\n ): Promise<void> {\n const metadataStore = await this.#createMetadataStore();\n\n let metadataLockId: string | undefined;\n\n try {\n // acquire metadata lock\n metadataLockId = await metadataStore.acquireMetadataLock(\n params.authKeyPair,\n );\n\n await metadataStore.batchAddSecretData({\n ...params,\n secretData: params.secretData.map((data) => ({\n data,\n })),\n });\n } finally {\n // release metadata lock\n if (metadataLockId) {\n try {\n await metadataStore.releaseMetadataLock(\n params.authKeyPair,\n metadataLockId,\n );\n } catch (error) {\n console.error('Failed to release metadata lock:', error);\n }\n }\n }\n }\n\n /**\n * This function fetches all secret data items associated with the given\n * auth pub key, decrypts, and returns them.\n *\n * @param params - The parameters for fetching the secret data.\n * @param params.decKey - The decryption key to be used to decrypt the secret data.\n * @param params.authKeyPair - The authentication key to be used to provide valid signature for fetching the secret data.\n *\n * @returns The decrypted secret data. Returns an empty array if no secret data is found.\n */\n async fetchAllSecretDataItems(\n params: FetchAllSecretDataParams,\n ): Promise<Uint8Array[]> {\n const metadataStore = await this.#createMetadataStore();\n const dataItems = await metadataStore.fetchAllSecretDataItems(\n params.decKey,\n params.authKeyPair,\n );\n return dataItems.map((dataItem: SecretDataItem) => dataItem.data);\n }\n\n /**\n * This function fetches the authentication public key.\n *\n * @param params - The parameters for getting the authentication public key.\n * @param params.authTokens - The auth tokens issued by the nodes on authenticating the user.\n * @param params.authConnectionId - The auth connection name used for authentication.\n * @param params.groupedAuthConnectionId - An optional grouped auth connection name used for authentication with aggregate (single id) verifier.\n * @param params.userId - The user id of the user.\n *\n * @returns The authentication public key.\n */\n async fetchAuthPubKey(\n params: FetchAuthPubKeyParams,\n ): Promise<FetchAuthPubKeyResult> {\n const {\n nodeAuthTokens,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n } = params;\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n return getPubKey({\n authTokens: nodeAuthTokens,\n nodeEndpointsMap,\n authConnectionId,\n userId,\n groupedAuthConnectionId,\n });\n }\n\n /**\n * This function looks up a password encryption key from the password\n * encryption key history.\n *\n * @param params - The parameters for getting the password encryption key.\n * @param params.targetPwPubKey - The target password public key.\n * @param params.curPwEncKey - The current password encryption key.\n * @param params.curAuthKeyPair - The current authentication key pair.\n * @param params.maxPwChainLength - Optional maximum password chain length\n * allowed to be traversed.\n *\n * @returns The password encryption key.\n */\n async recoverPwEncKey(\n params: RecoverPwEncKeyParams,\n ): Promise<RecoverPwEncKeyResult> {\n const {\n targetAuthPubKey: targetPwPubKey,\n curPwEncKey,\n curAuthKeyPair,\n maxPwChainLength = MAX_PASSWORD_CHAIN_LENGTH,\n } = params;\n\n let pwAndKeys = {\n password: '',\n encKey: curPwEncKey,\n authKeyPair: curAuthKeyPair,\n };\n\n for (let i = 0; i < maxPwChainLength; i++) {\n try {\n pwAndKeys = await this.#getPrevPasswordAndKeys({\n encKey: pwAndKeys.encKey,\n authKeyPair: pwAndKeys.authKeyPair,\n });\n if (equalBytes(pwAndKeys.authKeyPair.pk, targetPwPubKey)) {\n return { pwEncKey: pwAndKeys.encKey };\n }\n } catch (error) {\n throw TOPRFError.couldNotFetchPassword((error as Error).message);\n }\n }\n\n throw TOPRFError.maxKeyChainLengthExceeded();\n }\n\n /**\n * Gets the node details.\n *\n * @returns The node details containing the node endpoints, indexes and pubkeys.\n */\n async #getNodeDetails(): Promise<{\n nodeEndpoints: string[];\n nodeEndpointsMap: Record<number, string>;\n nodeIndexes: number[];\n nodePubkeys: INodePub[];\n }> {\n let finalIndexes = this.#nodeDetailsOverride?.indexes;\n let finalPubKeys = this.#nodeDetailsOverride?.pubKeys;\n let finalEndpoints = this.#nodeDetailsOverride?.endpoints;\n\n if (finalIndexes && finalPubKeys && Array.isArray(finalEndpoints)) {\n ToprfSecureBackup.#validateNodeDetailsLengths(\n finalIndexes,\n finalPubKeys,\n finalEndpoints,\n );\n return {\n nodeEndpoints: finalEndpoints,\n nodeEndpointsMap: createNodeEndpointsMap(finalEndpoints, finalIndexes),\n nodeIndexes: finalIndexes,\n nodePubkeys: finalPubKeys,\n };\n }\n\n const { torusNodeSSSEndpoints, torusIndexes, torusNodePub } =\n await this.#nodeDetailManager.getNodeDetails({\n verifier: 'auth-connection-id',\n verifierId: 'user-id',\n });\n\n finalIndexes ??= torusIndexes;\n finalPubKeys ??= torusNodePub;\n\n if (!Array.isArray(finalEndpoints)) {\n if (!torusNodeSSSEndpoints) {\n const message = 'Failed to get node details';\n throw new Error(message);\n }\n\n finalEndpoints = finalEndpoints\n ? torusNodeSSSEndpoints.map((endpoint) => {\n const url = new URL(endpoint);\n url.pathname = finalEndpoints as string;\n return url.href;\n })\n : torusNodeSSSEndpoints;\n }\n\n ToprfSecureBackup.#validateNodeDetailsLengths(\n finalIndexes,\n finalPubKeys,\n finalEndpoints,\n );\n\n return {\n nodeEndpoints: finalEndpoints,\n nodeEndpointsMap: createNodeEndpointsMap(finalEndpoints, finalIndexes),\n nodeIndexes: finalIndexes,\n nodePubkeys: finalPubKeys,\n };\n }\n\n /**\n * Creates and caches the metadata store instance.\n *\n * @returns The metadata store.\n */\n async #createMetadataStore(): Promise<MetadataStore> {\n if (this.#metadataStoreCache) {\n return this.#metadataStoreCache;\n }\n\n const { nodeEndpointsMap } = await this.#getNodeDetails();\n const metadataEndpointsMap =\n await this.#getMetadataEndpointsMap(nodeEndpointsMap);\n const node1MetadataEndpoint = metadataEndpointsMap['1'];\n\n const metadataStore = new MetadataStore({\n metadataEndpoint: node1MetadataEndpoint,\n fetchMetadataAccessCreds: this.#fetchMetadataAccessCreds,\n });\n\n this.#metadataStoreCache = metadataStore;\n\n return metadataStore;\n }\n\n /**\n * Gets the metadata endpoints.\n *\n * @param nodeEndpointsMap - The node endpoints map.\n *\n * @returns The metadata endpoints map with node index as key and metadata endpoint as value.\n */\n async #getMetadataEndpointsMap(\n nodeEndpointsMap: Record<number, string>,\n ): Promise<{ [nodeIndex: string]: string }> {\n const metadataEndpointsMap: { [nodeIndex: string]: string } = {};\n Object.entries(nodeEndpointsMap).forEach(([key, value]) => {\n const url = new URL(value);\n metadataEndpointsMap[key] = `${url.origin}/metadata`;\n });\n return metadataEndpointsMap;\n }\n\n /**\n * Gets the previous password and keys.\n *\n * @param params - The parameters for getting the previous password and keys.\n * @param params.encKey - The encryption key to be used for decrypting the secret data.\n * @param params.authKeyPair - The authentication key pair to be used for authenticating the secret data.\n *\n * @returns The previous password and keys.\n */\n async #getPrevPasswordAndKeys(params: {\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n }): Promise<{\n password: string;\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n }> {\n const metadataStore = await this.#createMetadataStore();\n\n const pwBackupData = await metadataStore.fetchAllSecretDataItems(\n params.encKey,\n params.authKeyPair,\n PW_BACKUP_ITEM_ID,\n );\n\n if (pwBackupData.length === 0) {\n throw new Error('Failed to get previous password and keys');\n }\n\n // Parse JSON object.\n const pwBackupDataJson = deserializePwBackup(pwBackupData[0].data);\n\n return {\n password: pwBackupDataJson.pw,\n encKey: pwBackupDataJson.encKey,\n authKeyPair: pwBackupDataJson.authKeyPair,\n };\n }\n\n /**\n * Validates that the lengths of node detail arrays are consistent.\n *\n * @param indexes - Array of node indexes.\n * @param pubKeys - Array of node public keys.\n * @param endpoints - Array of SSS endpoint URLs.\n * @throws If lengths are inconsistent.\n */\n static #validateNodeDetailsLengths(\n indexes: unknown[],\n pubKeys: unknown[],\n endpoints: unknown[],\n ): void {\n if (\n indexes.length !== pubKeys.length ||\n indexes.length !== endpoints.length\n ) {\n const message =\n 'Node details arrays (indexes, pubKeys, endpoints) must have equal lengths';\n throw new Error(message);\n }\n }\n}\n\n/**\n * Serializes the password, encryption key, and authentication key pair into a JSON string.\n *\n * @param pw - The password.\n * @param encKey - The encryption key.\n * @param authKeyPair - The authentication key pair.\n * @returns The serialized JSON string.\n */\nfunction serializePwBackup(\n pw: string,\n encKey: Uint8Array,\n authKeyPair: KeyPair,\n): Uint8Array {\n return utf8ToBytes(\n JSON.stringify({\n pw,\n encKey: bytesToHex(encKey),\n authKeyPair: {\n sk: authKeyPair.sk.toString(),\n pk: bytesToHex(authKeyPair.pk),\n },\n }),\n );\n}\n\n/**\n * Deserializes the password, encryption key, and authentication key pair from a JSON string.\n *\n * @param data - The serialized JSON string.\n * @returns The password, encryption key, and authentication key pair.\n */\nfunction deserializePwBackup(data: Uint8Array): {\n pw: string;\n encKey: Uint8Array;\n authKeyPair: KeyPair;\n} {\n const json = JSON.parse(bytesToUtf8(data));\n return {\n pw: json.pw,\n encKey: hexToBytes(json.encKey),\n authKeyPair: {\n sk: BigInt(json.authKeyPair.sk),\n pk: hexToBytes(json.authKeyPair.pk),\n },\n };\n}\n"]}
{
"name": "@metamask/toprf-secure-backup",
"version": "0.7.0",
"version": "0.7.1",
"description": "The MetaMask Node module template",

@@ -5,0 +5,0 @@ "keywords": [