@metamask/snaps-rpc-methods 11.13.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -1
- package/dist/permitted/listEntropySources.cjs +5 -2
- package/dist/permitted/listEntropySources.cjs.map +1 -1
- package/dist/permitted/listEntropySources.d.cts +6 -0
- package/dist/permitted/listEntropySources.d.cts.map +1 -1
- package/dist/permitted/listEntropySources.d.mts +6 -0
- package/dist/permitted/listEntropySources.d.mts.map +1 -1
- package/dist/permitted/listEntropySources.mjs +5 -2
- package/dist/permitted/listEntropySources.mjs.map +1 -1
- package/dist/restricted/getBip32Entropy.cjs +16 -3
- package/dist/restricted/getBip32Entropy.cjs.map +1 -1
- package/dist/restricted/getBip32Entropy.d.cts +11 -1
- package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip32Entropy.d.mts +11 -1
- package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip32Entropy.mjs +17 -4
- package/dist/restricted/getBip32Entropy.mjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.cjs +19 -3
- package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.cts +11 -1
- package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.mts +11 -1
- package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
- package/dist/restricted/getBip32PublicKey.mjs +20 -4
- package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
- package/dist/restricted/getBip44Entropy.cjs +8 -5
- package/dist/restricted/getBip44Entropy.cjs.map +1 -1
- package/dist/restricted/getBip44Entropy.d.cts +6 -6
- package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip44Entropy.d.mts +6 -6
- package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip44Entropy.mjs +9 -6
- package/dist/restricted/getBip44Entropy.mjs.map +1 -1
- package/dist/restricted/getEntropy.cjs +7 -7
- package/dist/restricted/getEntropy.cjs.map +1 -1
- package/dist/restricted/getEntropy.d.cts +7 -7
- package/dist/restricted/getEntropy.d.cts.map +1 -1
- package/dist/restricted/getEntropy.d.mts +7 -7
- package/dist/restricted/getEntropy.d.mts.map +1 -1
- package/dist/restricted/getEntropy.mjs +8 -8
- package/dist/restricted/getEntropy.mjs.map +1 -1
- package/dist/restricted/manageState.cjs +4 -4
- package/dist/restricted/manageState.cjs.map +1 -1
- package/dist/restricted/manageState.d.cts +3 -3
- package/dist/restricted/manageState.d.cts.map +1 -1
- package/dist/restricted/manageState.d.mts +3 -3
- package/dist/restricted/manageState.d.mts.map +1 -1
- package/dist/restricted/manageState.mjs +5 -5
- package/dist/restricted/manageState.mjs.map +1 -1
- package/dist/utils.cjs +68 -23
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +40 -16
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +40 -16
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +63 -19
- package/dist/utils.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [12.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** Use mnemonic seed for `snap_get*Entropy` RPC methods ([#3220](https://github.com/MetaMask/snaps/pull/3220))
|
|
15
|
+
- A `getMnemonicSeed` hook is now required to support the RPC methods.
|
|
16
|
+
- Use mnemonic seed for state encryption key derivation ([#3217](https://github.com/MetaMask/snaps/pull/3217))
|
|
17
|
+
|
|
18
|
+
## [11.13.1]
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Unlock client before calling `getEntropySources` in `snap_listEntropySources` method ([#3194](https://github.com/MetaMask/snaps/pull/3194))
|
|
23
|
+
|
|
10
24
|
## [11.13.0]
|
|
11
25
|
|
|
12
26
|
### Added
|
|
@@ -400,7 +414,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
400
414
|
- The version of the package no longer needs to match the version of all other
|
|
401
415
|
MetaMask Snaps packages.
|
|
402
416
|
|
|
403
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@
|
|
417
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@12.0.0...HEAD
|
|
418
|
+
[12.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.13.1...@metamask/snaps-rpc-methods@12.0.0
|
|
419
|
+
[11.13.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.13.0...@metamask/snaps-rpc-methods@11.13.1
|
|
404
420
|
[11.13.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.12.0...@metamask/snaps-rpc-methods@11.13.0
|
|
405
421
|
[11.12.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.11.0...@metamask/snaps-rpc-methods@11.12.0
|
|
406
422
|
[11.11.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.10.0...@metamask/snaps-rpc-methods@11.11.0
|
|
@@ -19,6 +19,7 @@ const REQUIRED_PERMISSIONS = [
|
|
|
19
19
|
const hookNames = {
|
|
20
20
|
hasPermission: true,
|
|
21
21
|
getEntropySources: true,
|
|
22
|
+
getUnlockPromise: true,
|
|
22
23
|
};
|
|
23
24
|
exports.listEntropySourcesHandler = {
|
|
24
25
|
methodNames: ['snap_listEntropySources'],
|
|
@@ -26,7 +27,7 @@ exports.listEntropySourcesHandler = {
|
|
|
26
27
|
hookNames,
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
|
-
* The `
|
|
30
|
+
* The `snap_listEntropySources` method implementation.
|
|
30
31
|
*
|
|
31
32
|
* @param _request - The JSON-RPC request object. Not used by this function.
|
|
32
33
|
* @param response - The JSON-RPC response object.
|
|
@@ -37,13 +38,15 @@ exports.listEntropySourcesHandler = {
|
|
|
37
38
|
* @param hooks.hasPermission - The function to check if the origin has a
|
|
38
39
|
* permission.
|
|
39
40
|
* @param hooks.getEntropySources - The function to get the entropy sources.
|
|
41
|
+
* @param hooks.getUnlockPromise - The function to get the unlock promise.
|
|
40
42
|
* @returns Noting.
|
|
41
43
|
*/
|
|
42
|
-
function listEntropySourcesImplementation(_request, response, _next, end, { hasPermission, getEntropySources }) {
|
|
44
|
+
async function listEntropySourcesImplementation(_request, response, _next, end, { hasPermission, getEntropySources, getUnlockPromise, }) {
|
|
43
45
|
const isPermitted = REQUIRED_PERMISSIONS.some(hasPermission);
|
|
44
46
|
if (!isPermitted) {
|
|
45
47
|
return end(rpc_errors_1.providerErrors.unauthorized());
|
|
46
48
|
}
|
|
49
|
+
await getUnlockPromise(true);
|
|
47
50
|
response.result = getEntropySources();
|
|
48
51
|
return end();
|
|
49
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listEntropySources.cjs","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":";;;AAEA,qDAAsD;AAStD,uEAAuE;AACvE,2EAA2E;AAC3E,uEAAuE;AACvE,6DAA6D;AAG7D;;;GAGG;AACH,MAAM,oBAAoB,GAAG;IAC3B,wCAAsB,CAAC,UAAU;IACjC,4CAAwB,CAAC,UAAU;IACnC,wCAAsB,CAAC,UAAU;IACjC,8BAAiB,CAAC,UAAU;CAC7B,CAAC;AAEF,MAAM,SAAS,GAA+C;IAC5D,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;
|
|
1
|
+
{"version":3,"file":"listEntropySources.cjs","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":";;;AAEA,qDAAsD;AAStD,uEAAuE;AACvE,2EAA2E;AAC3E,uEAAuE;AACvE,6DAA6D;AAG7D;;;GAGG;AACH,MAAM,oBAAoB,GAAG;IAC3B,wCAAsB,CAAC,UAAU;IACjC,4CAAwB,CAAC,UAAU;IACnC,wCAAsB,CAAC,UAAU;IACjC,8BAAiB,CAAC,UAAU;CAC7B,CAAC;AAEF,MAAM,SAAS,GAA+C;IAC5D,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;IACvB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AA0BW,QAAA,yBAAyB,GAIlC;IACF,WAAW,EAAE,CAAC,yBAAyB,CAAC;IACxC,cAAc,EAAE,gCAAgC;IAChD,SAAS;CACV,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,KAAK,UAAU,gCAAgC,CAC7C,QAAkD,EAClD,QAA0D,EAC1D,KAAc,EACd,GAA6B,EAC7B,EACE,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACQ;IAE1B,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC7D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CAAC,2BAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAE7B,QAAQ,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;IACtC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors } from '@metamask/rpc-errors';\nimport type {\n EntropySource,\n JsonRpcRequest,\n ListEntropySourcesParams,\n ListEntropySourcesResult,\n} from '@metamask/snaps-sdk';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { getBip32EntropyBuilder } from '../restricted/getBip32Entropy';\nimport { getBip32PublicKeyBuilder } from '../restricted/getBip32PublicKey';\nimport { getBip44EntropyBuilder } from '../restricted/getBip44Entropy';\nimport { getEntropyBuilder } from '../restricted/getEntropy';\nimport type { MethodHooksObject } from '../utils';\n\n/**\n * A list of permissions that the requesting origin must have at least one of\n * in order to call this method.\n */\nconst REQUIRED_PERMISSIONS = [\n getBip32EntropyBuilder.targetName,\n getBip32PublicKeyBuilder.targetName,\n getBip44EntropyBuilder.targetName,\n getEntropyBuilder.targetName,\n];\n\nconst hookNames: MethodHooksObject<ListEntropySourcesHooks> = {\n hasPermission: true,\n getEntropySources: true,\n getUnlockPromise: true,\n};\n\nexport type ListEntropySourcesHooks = {\n /**\n * Check if the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * Get the entropy sources from the client.\n *\n * @returns The entropy sources.\n */\n getEntropySources: () => EntropySource[];\n\n /**\n * Wait for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n};\n\nexport const listEntropySourcesHandler: PermittedHandlerExport<\n ListEntropySourcesHooks,\n ListEntropySourcesParams,\n ListEntropySourcesResult\n> = {\n methodNames: ['snap_listEntropySources'],\n implementation: listEntropySourcesImplementation,\n hookNames,\n};\n\n/**\n * The `snap_listEntropySources` method implementation.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - The function to check if the origin has a\n * permission.\n * @param hooks.getEntropySources - The function to get the entropy sources.\n * @param hooks.getUnlockPromise - The function to get the unlock promise.\n * @returns Noting.\n */\nasync function listEntropySourcesImplementation(\n _request: JsonRpcRequest<ListEntropySourcesParams>,\n response: PendingJsonRpcResponse<ListEntropySourcesResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n hasPermission,\n getEntropySources,\n getUnlockPromise,\n }: ListEntropySourcesHooks,\n): Promise<void> {\n const isPermitted = REQUIRED_PERMISSIONS.some(hasPermission);\n if (!isPermitted) {\n return end(providerErrors.unauthorized());\n }\n\n await getUnlockPromise(true);\n\n response.result = getEntropySources();\n return end();\n}\n"]}
|
|
@@ -14,6 +14,12 @@ export type ListEntropySourcesHooks = {
|
|
|
14
14
|
* @returns The entropy sources.
|
|
15
15
|
*/
|
|
16
16
|
getEntropySources: () => EntropySource[];
|
|
17
|
+
/**
|
|
18
|
+
* Wait for the extension to be unlocked.
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that resolves once the extension is unlocked.
|
|
21
|
+
*/
|
|
22
|
+
getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
|
|
17
23
|
};
|
|
18
24
|
export declare const listEntropySourcesHandler: PermittedHandlerExport<ListEntropySourcesHooks, ListEntropySourcesParams, ListEntropySourcesResult>;
|
|
19
25
|
//# sourceMappingURL=listEntropySources.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listEntropySources.d.cts","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,aAAa,EAEb,wBAAwB,EACxB,wBAAwB,EACzB,4BAA4B;
|
|
1
|
+
{"version":3,"file":"listEntropySources.d.cts","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,aAAa,EAEb,wBAAwB,EACxB,wBAAwB,EACzB,4BAA4B;AA0B7B,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;OAKG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,aAAa,EAAE,CAAC;IAEzC;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,sBAAsB,CAC5D,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,CAKzB,CAAC"}
|
|
@@ -14,6 +14,12 @@ export type ListEntropySourcesHooks = {
|
|
|
14
14
|
* @returns The entropy sources.
|
|
15
15
|
*/
|
|
16
16
|
getEntropySources: () => EntropySource[];
|
|
17
|
+
/**
|
|
18
|
+
* Wait for the extension to be unlocked.
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that resolves once the extension is unlocked.
|
|
21
|
+
*/
|
|
22
|
+
getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
|
|
17
23
|
};
|
|
18
24
|
export declare const listEntropySourcesHandler: PermittedHandlerExport<ListEntropySourcesHooks, ListEntropySourcesParams, ListEntropySourcesResult>;
|
|
19
25
|
//# sourceMappingURL=listEntropySources.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listEntropySources.d.mts","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,aAAa,EAEb,wBAAwB,EACxB,wBAAwB,EACzB,4BAA4B;
|
|
1
|
+
{"version":3,"file":"listEntropySources.d.mts","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,aAAa,EAEb,wBAAwB,EACxB,wBAAwB,EACzB,4BAA4B;AA0B7B,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;OAKG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,aAAa,EAAE,CAAC;IAEzC;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,sBAAsB,CAC5D,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,CAKzB,CAAC"}
|
|
@@ -16,6 +16,7 @@ const REQUIRED_PERMISSIONS = [
|
|
|
16
16
|
const hookNames = {
|
|
17
17
|
hasPermission: true,
|
|
18
18
|
getEntropySources: true,
|
|
19
|
+
getUnlockPromise: true,
|
|
19
20
|
};
|
|
20
21
|
export const listEntropySourcesHandler = {
|
|
21
22
|
methodNames: ['snap_listEntropySources'],
|
|
@@ -23,7 +24,7 @@ export const listEntropySourcesHandler = {
|
|
|
23
24
|
hookNames,
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
|
-
* The `
|
|
27
|
+
* The `snap_listEntropySources` method implementation.
|
|
27
28
|
*
|
|
28
29
|
* @param _request - The JSON-RPC request object. Not used by this function.
|
|
29
30
|
* @param response - The JSON-RPC response object.
|
|
@@ -34,13 +35,15 @@ export const listEntropySourcesHandler = {
|
|
|
34
35
|
* @param hooks.hasPermission - The function to check if the origin has a
|
|
35
36
|
* permission.
|
|
36
37
|
* @param hooks.getEntropySources - The function to get the entropy sources.
|
|
38
|
+
* @param hooks.getUnlockPromise - The function to get the unlock promise.
|
|
37
39
|
* @returns Noting.
|
|
38
40
|
*/
|
|
39
|
-
function listEntropySourcesImplementation(_request, response, _next, end, { hasPermission, getEntropySources }) {
|
|
41
|
+
async function listEntropySourcesImplementation(_request, response, _next, end, { hasPermission, getEntropySources, getUnlockPromise, }) {
|
|
40
42
|
const isPermitted = REQUIRED_PERMISSIONS.some(hasPermission);
|
|
41
43
|
if (!isPermitted) {
|
|
42
44
|
return end(providerErrors.unauthorized());
|
|
43
45
|
}
|
|
46
|
+
await getUnlockPromise(true);
|
|
44
47
|
response.result = getEntropySources();
|
|
45
48
|
return end();
|
|
46
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listEntropySources.mjs","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,6BAA6B;AAStD,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,wBAAwB,EAAE,4CAAwC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,iBAAiB,EAAE,qCAAiC;AAG7D;;;GAGG;AACH,MAAM,oBAAoB,GAAG;IAC3B,sBAAsB,CAAC,UAAU;IACjC,wBAAwB,CAAC,UAAU;IACnC,sBAAsB,CAAC,UAAU;IACjC,iBAAiB,CAAC,UAAU;CAC7B,CAAC;AAEF,MAAM,SAAS,GAA+C;IAC5D,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;
|
|
1
|
+
{"version":3,"file":"listEntropySources.mjs","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,6BAA6B;AAStD,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,wBAAwB,EAAE,4CAAwC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,iBAAiB,EAAE,qCAAiC;AAG7D;;;GAGG;AACH,MAAM,oBAAoB,GAAG;IAC3B,sBAAsB,CAAC,UAAU;IACjC,wBAAwB,CAAC,UAAU;IACnC,sBAAsB,CAAC,UAAU;IACjC,iBAAiB,CAAC,UAAU;CAC7B,CAAC;AAEF,MAAM,SAAS,GAA+C;IAC5D,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;IACvB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AA0BF,MAAM,CAAC,MAAM,yBAAyB,GAIlC;IACF,WAAW,EAAE,CAAC,yBAAyB,CAAC;IACxC,cAAc,EAAE,gCAAgC;IAChD,SAAS;CACV,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,KAAK,UAAU,gCAAgC,CAC7C,QAAkD,EAClD,QAA0D,EAC1D,KAAc,EACd,GAA6B,EAC7B,EACE,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACQ;IAE1B,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC7D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAE7B,QAAQ,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;IACtC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors } from '@metamask/rpc-errors';\nimport type {\n EntropySource,\n JsonRpcRequest,\n ListEntropySourcesParams,\n ListEntropySourcesResult,\n} from '@metamask/snaps-sdk';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { getBip32EntropyBuilder } from '../restricted/getBip32Entropy';\nimport { getBip32PublicKeyBuilder } from '../restricted/getBip32PublicKey';\nimport { getBip44EntropyBuilder } from '../restricted/getBip44Entropy';\nimport { getEntropyBuilder } from '../restricted/getEntropy';\nimport type { MethodHooksObject } from '../utils';\n\n/**\n * A list of permissions that the requesting origin must have at least one of\n * in order to call this method.\n */\nconst REQUIRED_PERMISSIONS = [\n getBip32EntropyBuilder.targetName,\n getBip32PublicKeyBuilder.targetName,\n getBip44EntropyBuilder.targetName,\n getEntropyBuilder.targetName,\n];\n\nconst hookNames: MethodHooksObject<ListEntropySourcesHooks> = {\n hasPermission: true,\n getEntropySources: true,\n getUnlockPromise: true,\n};\n\nexport type ListEntropySourcesHooks = {\n /**\n * Check if the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * Get the entropy sources from the client.\n *\n * @returns The entropy sources.\n */\n getEntropySources: () => EntropySource[];\n\n /**\n * Wait for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n};\n\nexport const listEntropySourcesHandler: PermittedHandlerExport<\n ListEntropySourcesHooks,\n ListEntropySourcesParams,\n ListEntropySourcesResult\n> = {\n methodNames: ['snap_listEntropySources'],\n implementation: listEntropySourcesImplementation,\n hookNames,\n};\n\n/**\n * The `snap_listEntropySources` method implementation.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - The function to check if the origin has a\n * permission.\n * @param hooks.getEntropySources - The function to get the entropy sources.\n * @param hooks.getUnlockPromise - The function to get the unlock promise.\n * @returns Noting.\n */\nasync function listEntropySourcesImplementation(\n _request: JsonRpcRequest<ListEntropySourcesParams>,\n response: PendingJsonRpcResponse<ListEntropySourcesResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n hasPermission,\n getEntropySources,\n getUnlockPromise,\n }: ListEntropySourcesHooks,\n): Promise<void> {\n const isPermitted = REQUIRED_PERMISSIONS.some(hasPermission);\n if (!isPermitted) {\n return end(providerErrors.unauthorized());\n }\n\n await getUnlockPromise(true);\n\n response.result = getEntropySources();\n return end();\n}\n"]}
|
|
@@ -35,6 +35,7 @@ const specificationBuilder = ({ methodHooks }) => {
|
|
|
35
35
|
};
|
|
36
36
|
const methodHooks = {
|
|
37
37
|
getMnemonic: true,
|
|
38
|
+
getMnemonicSeed: true,
|
|
38
39
|
getUnlockPromise: true,
|
|
39
40
|
getClientCryptography: true,
|
|
40
41
|
};
|
|
@@ -48,6 +49,7 @@ exports.getBip32EntropyBuilder = Object.freeze({
|
|
|
48
49
|
*
|
|
49
50
|
* @param hooks - The RPC method hooks.
|
|
50
51
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
52
|
+
* @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.
|
|
51
53
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
52
54
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
53
55
|
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
@@ -55,13 +57,24 @@ exports.getBip32EntropyBuilder = Object.freeze({
|
|
|
55
57
|
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
56
58
|
* @throws If the params are invalid.
|
|
57
59
|
*/
|
|
58
|
-
function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
|
|
60
|
+
function getBip32EntropyImplementation({ getMnemonic, getMnemonicSeed, getUnlockPromise, getClientCryptography, }) {
|
|
59
61
|
return async function getBip32Entropy(args) {
|
|
60
62
|
await getUnlockPromise(true);
|
|
61
63
|
const { params } = args;
|
|
62
64
|
(0, utils_1.assert)(params);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
// Using the seed is much faster, but we can only do it for these specific curves.
|
|
66
|
+
if (params.curve === 'secp256k1' || params.curve === 'ed25519') {
|
|
67
|
+
const seed = await (0, utils_2.getValueFromEntropySource)(getMnemonicSeed, params.source);
|
|
68
|
+
const node = await (0, utils_2.getNodeFromSeed)({
|
|
69
|
+
curve: params.curve,
|
|
70
|
+
path: params.path,
|
|
71
|
+
seed,
|
|
72
|
+
cryptographicFunctions: getClientCryptography(),
|
|
73
|
+
});
|
|
74
|
+
return node.toJSON();
|
|
75
|
+
}
|
|
76
|
+
const secretRecoveryPhrase = await (0, utils_2.getValueFromEntropySource)(getMnemonic, params.source);
|
|
77
|
+
const node = await (0, utils_2.getNodeFromMnemonic)({
|
|
65
78
|
curve: params.curve,
|
|
66
79
|
path: params.path,
|
|
67
80
|
secretRecoveryPhrase,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":";;;AAOA,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAAuD;AAEvD,2CAAyC;AAGzC,
|
|
1
|
+
{"version":3,"file":"getBip32Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":";;;AAOA,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAAuD;AAEvD,2CAAyC;AAGzC,wCAIkB;AAElB,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAoD1C;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAA8C,EAAE,EAAE;IAClE,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,4BAAc,CAAC,wBAAwB,CAAC;QACzD,oBAAoB,EAAE,6BAA6B,CAAC,WAAW,CAAC;QAChE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,OAAO,EAAE,MAAM,KAAK,CAAC;gBACrB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,4BAAc,CAAC,wBAAwB,EAC3D,CAAC;gBACD,MAAM,sBAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,sBAAsB,4BAAc,CAAC,wBAAwB,WAAW;iBAClF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,C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,qBAAqB,EAAE;SAChD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AA7CD,sEA6CC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32EntropyParams,\n GetBip32EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport {\n getNodeFromMnemonic,\n getNodeFromSeed,\n getValueFromEntropySource,\n} from '../utils';\n\nconst targetName = 'snap_getBip32Entropy';\n\nexport type GetBip32EntropyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Get the mnemonic seed of the provided source. If no source is provided, the\n * mnemonic seed of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic seed of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip32EntropySpecificationBuilderOptions = {\n methodHooks: GetBip32EntropyMethodHooks;\n};\n\ntype GetBip32EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip32Entropy` permission.\n * `snap_getBip32Entropy` lets the Snap control private keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32EntropySpecificationBuilderOptions,\n GetBip32EntropySpecification\n> = ({ methodHooks }: GetBip32EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32EntropyMethodHooks> = {\n getMnemonic: true,\n getMnemonicSeed: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip32EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `JsonSLIP10Node`.\n * @throws If the params are invalid.\n */\nexport function getBip32EntropyImplementation({\n getMnemonic,\n getMnemonicSeed,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip32EntropyMethodHooks) {\n return async function getBip32Entropy(\n args: RestrictedMethodOptions<GetBip32EntropyParams>,\n ): Promise<GetBip32EntropyResult> {\n await getUnlockPromise(true);\n\n const { params } = args;\n assert(params);\n\n // Using the seed is much faster, but we can only do it for these specific curves.\n if (params.curve === 'secp256k1' || params.curve === 'ed25519') {\n const seed = await getValueFromEntropySource(\n getMnemonicSeed,\n params.source,\n );\n\n const node = await getNodeFromSeed({\n curve: params.curve,\n path: params.path,\n seed,\n cryptographicFunctions: getClientCryptography(),\n });\n\n return node.toJSON();\n }\n\n const secretRecoveryPhrase = await getValueFromEntropySource(\n getMnemonic,\n params.source,\n );\n\n const node = await getNodeFromMnemonic({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase,\n cryptographicFunctions: getClientCryptography(),\n });\n\n return node.toJSON();\n };\n}\n"]}
|
|
@@ -15,6 +15,15 @@ export type GetBip32EntropyMethodHooks = {
|
|
|
15
15
|
* source is provided.
|
|
16
16
|
*/
|
|
17
17
|
getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the mnemonic seed of the provided source. If no source is provided, the
|
|
20
|
+
* mnemonic seed of the primary keyring will be returned.
|
|
21
|
+
*
|
|
22
|
+
* @param source - The optional ID of the source to get the mnemonic of.
|
|
23
|
+
* @returns The mnemonic seed of the provided source, or the default source if no
|
|
24
|
+
* source is provided.
|
|
25
|
+
*/
|
|
26
|
+
getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;
|
|
18
27
|
/**
|
|
19
28
|
* Waits for the extension to be unlocked.
|
|
20
29
|
*
|
|
@@ -49,6 +58,7 @@ export declare const getBip32EntropyBuilder: Readonly<{
|
|
|
49
58
|
*
|
|
50
59
|
* @param hooks - The RPC method hooks.
|
|
51
60
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
61
|
+
* @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.
|
|
52
62
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
53
63
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
54
64
|
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
@@ -56,6 +66,6 @@ export declare const getBip32EntropyBuilder: Readonly<{
|
|
|
56
66
|
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
57
67
|
* @throws If the params are invalid.
|
|
58
68
|
*/
|
|
59
|
-
export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
69
|
+
export declare function getBip32EntropyImplementation({ getMnemonic, getMnemonicSeed, getUnlockPromise, getClientCryptography, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
60
70
|
export {};
|
|
61
71
|
//# sourceMappingURL=getBip32Entropy.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32Entropy.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EA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;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAqClC"}
|
|
@@ -15,6 +15,15 @@ export type GetBip32EntropyMethodHooks = {
|
|
|
15
15
|
* source is provided.
|
|
16
16
|
*/
|
|
17
17
|
getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the mnemonic seed of the provided source. If no source is provided, the
|
|
20
|
+
* mnemonic seed of the primary keyring will be returned.
|
|
21
|
+
*
|
|
22
|
+
* @param source - The optional ID of the source to get the mnemonic of.
|
|
23
|
+
* @returns The mnemonic seed of the provided source, or the default source if no
|
|
24
|
+
* source is provided.
|
|
25
|
+
*/
|
|
26
|
+
getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;
|
|
18
27
|
/**
|
|
19
28
|
* Waits for the extension to be unlocked.
|
|
20
29
|
*
|
|
@@ -49,6 +58,7 @@ export declare const getBip32EntropyBuilder: Readonly<{
|
|
|
49
58
|
*
|
|
50
59
|
* @param hooks - The RPC method hooks.
|
|
51
60
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
61
|
+
* @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.
|
|
52
62
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
53
63
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
54
64
|
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
@@ -56,6 +66,6 @@ export declare const getBip32EntropyBuilder: Readonly<{
|
|
|
56
66
|
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
57
67
|
* @throws If the params are invalid.
|
|
58
68
|
*/
|
|
59
|
-
export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
69
|
+
export declare function getBip32EntropyImplementation({ getMnemonic, getMnemonicSeed, getUnlockPromise, getClientCryptography, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
60
70
|
export {};
|
|
61
71
|
//# sourceMappingURL=getBip32Entropy.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32Entropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;
|
|
1
|
+
{"version":3,"file":"getBip32Entropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAOlD,QAAA,MAAM,UAAU,yBAAyB,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;;;OAOG;IACH,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAElE;;;;;;;OAOG;IACH,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAEtE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;;;;;OAMG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACjE,CAAC;AAEF,KAAK,0CAA0C,GAAG;IAChD,WAAW,EAAE,0BAA0B,CAAC;CACzC,CAAC;AAkDF,eAAO,MAAM,sBAAsB;;;wBA/CjB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,oCAAoC,CAAC;wBACtD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EA+C/B,CAAC;AAEZ;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAqClC"}
|
|
@@ -2,7 +2,7 @@ import { PermissionType, SubjectType } from "@metamask/permission-controller";
|
|
|
2
2
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
3
3
|
import { SnapCaveatType } from "@metamask/snaps-utils";
|
|
4
4
|
import { assert } from "@metamask/utils";
|
|
5
|
-
import {
|
|
5
|
+
import { getNodeFromMnemonic, getNodeFromSeed, getValueFromEntropySource } from "../utils.mjs";
|
|
6
6
|
const targetName = 'snap_getBip32Entropy';
|
|
7
7
|
/**
|
|
8
8
|
* The specification builder for the `snap_getBip32Entropy` permission.
|
|
@@ -32,6 +32,7 @@ const specificationBuilder = ({ methodHooks }) => {
|
|
|
32
32
|
};
|
|
33
33
|
const methodHooks = {
|
|
34
34
|
getMnemonic: true,
|
|
35
|
+
getMnemonicSeed: true,
|
|
35
36
|
getUnlockPromise: true,
|
|
36
37
|
getClientCryptography: true,
|
|
37
38
|
};
|
|
@@ -45,6 +46,7 @@ export const getBip32EntropyBuilder = Object.freeze({
|
|
|
45
46
|
*
|
|
46
47
|
* @param hooks - The RPC method hooks.
|
|
47
48
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
49
|
+
* @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.
|
|
48
50
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
49
51
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
50
52
|
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
@@ -52,13 +54,24 @@ export const getBip32EntropyBuilder = Object.freeze({
|
|
|
52
54
|
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
53
55
|
* @throws If the params are invalid.
|
|
54
56
|
*/
|
|
55
|
-
export function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
|
|
57
|
+
export function getBip32EntropyImplementation({ getMnemonic, getMnemonicSeed, getUnlockPromise, getClientCryptography, }) {
|
|
56
58
|
return async function getBip32Entropy(args) {
|
|
57
59
|
await getUnlockPromise(true);
|
|
58
60
|
const { params } = args;
|
|
59
61
|
assert(params);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
// Using the seed is much faster, but we can only do it for these specific curves.
|
|
63
|
+
if (params.curve === 'secp256k1' || params.curve === 'ed25519') {
|
|
64
|
+
const seed = await getValueFromEntropySource(getMnemonicSeed, params.source);
|
|
65
|
+
const node = await getNodeFromSeed({
|
|
66
|
+
curve: params.curve,
|
|
67
|
+
path: params.path,
|
|
68
|
+
seed,
|
|
69
|
+
cryptographicFunctions: getClientCryptography(),
|
|
70
|
+
});
|
|
71
|
+
return node.toJSON();
|
|
72
|
+
}
|
|
73
|
+
const secretRecoveryPhrase = await getValueFromEntropySource(getMnemonic, params.source);
|
|
74
|
+
const node = await getNodeFromMnemonic({
|
|
62
75
|
curve: params.curve,
|
|
63
76
|
path: params.path,
|
|
64
77
|
secretRecoveryPhrase,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32Entropy.mjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EAAE,cAAc,EAAE,8BAA8B;AAEvD,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAGzC,OAAO,
|
|
1
|
+
{"version":3,"file":"getBip32Entropy.mjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EAAE,cAAc,EAAE,8BAA8B;AAEvD,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAGzC,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,yBAAyB,EAC1B,qBAAiB;AAElB,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAoD1C;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAA8C,EAAE,EAAE;IAClE,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,cAAc,CAAC,wBAAwB,CAAC;QACzD,oBAAoB,EAAE,6BAA6B,CAAC,WAAW,CAAC;QAChE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,OAAO,EAAE,MAAM,KAAK,CAAC;gBACrB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAA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oBAAoB,GAAG,MAAM,yBAAyB,CAC1D,WAAW,EACX,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,mBAAmB,CAAC;YACrC,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,oBAAoB;YACpB,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32EntropyParams,\n GetBip32EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport {\n getNodeFromMnemonic,\n getNodeFromSeed,\n getValueFromEntropySource,\n} from '../utils';\n\nconst targetName = 'snap_getBip32Entropy';\n\nexport type GetBip32EntropyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Get the mnemonic seed of the provided source. If no source is provided, the\n * mnemonic seed of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic seed of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip32EntropySpecificationBuilderOptions = {\n methodHooks: GetBip32EntropyMethodHooks;\n};\n\ntype GetBip32EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip32Entropy` permission.\n * `snap_getBip32Entropy` lets the Snap control private keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32EntropySpecificationBuilderOptions,\n GetBip32EntropySpecification\n> = ({ methodHooks }: GetBip32EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32EntropyMethodHooks> = {\n getMnemonic: true,\n getMnemonicSeed: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip32EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `JsonSLIP10Node`.\n * @throws If the params are invalid.\n */\nexport function getBip32EntropyImplementation({\n getMnemonic,\n getMnemonicSeed,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip32EntropyMethodHooks) {\n return async function getBip32Entropy(\n args: RestrictedMethodOptions<GetBip32EntropyParams>,\n ): Promise<GetBip32EntropyResult> {\n await getUnlockPromise(true);\n\n const { params } = args;\n assert(params);\n\n // Using the seed is much faster, but we can only do it for these specific curves.\n if (params.curve === 'secp256k1' || params.curve === 'ed25519') {\n const seed = await getValueFromEntropySource(\n getMnemonicSeed,\n params.source,\n );\n\n const node = await getNodeFromSeed({\n curve: params.curve,\n path: params.path,\n seed,\n cryptographicFunctions: getClientCryptography(),\n });\n\n return node.toJSON();\n }\n\n const secretRecoveryPhrase = await getValueFromEntropySource(\n getMnemonic,\n params.source,\n );\n\n const node = await getNodeFromMnemonic({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase,\n cryptographicFunctions: getClientCryptography(),\n });\n\n return node.toJSON();\n };\n}\n"]}
|
|
@@ -42,6 +42,7 @@ const specificationBuilder = ({ methodHooks }) => {
|
|
|
42
42
|
};
|
|
43
43
|
const methodHooks = {
|
|
44
44
|
getMnemonic: true,
|
|
45
|
+
getMnemonicSeed: true,
|
|
45
46
|
getUnlockPromise: true,
|
|
46
47
|
getClientCryptography: true,
|
|
47
48
|
};
|
|
@@ -55,6 +56,7 @@ exports.getBip32PublicKeyBuilder = Object.freeze({
|
|
|
55
56
|
*
|
|
56
57
|
* @param hooks - The RPC method hooks.
|
|
57
58
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
59
|
+
* @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.
|
|
58
60
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
59
61
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
60
62
|
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
@@ -62,13 +64,27 @@ exports.getBip32PublicKeyBuilder = Object.freeze({
|
|
|
62
64
|
* @returns The method implementation which returns a public key.
|
|
63
65
|
* @throws If the params are invalid.
|
|
64
66
|
*/
|
|
65
|
-
function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
|
|
67
|
+
function getBip32PublicKeyImplementation({ getMnemonic, getMnemonicSeed, getUnlockPromise, getClientCryptography, }) {
|
|
66
68
|
return async function getBip32PublicKey(args) {
|
|
67
69
|
await getUnlockPromise(true);
|
|
68
70
|
(0, utils_1.assertStruct)(args.params, exports.Bip32PublicKeyArgsStruct, 'Invalid BIP-32 public key params', rpc_errors_1.rpcErrors.invalidParams);
|
|
69
71
|
const { params } = args;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
// Using the seed is much faster, but we can only do it for these specific curves.
|
|
73
|
+
if (params.curve === 'secp256k1' || params.curve === 'ed25519') {
|
|
74
|
+
const seed = await (0, utils_2.getValueFromEntropySource)(getMnemonicSeed, params.source);
|
|
75
|
+
const node = await (0, utils_2.getNodeFromSeed)({
|
|
76
|
+
curve: params.curve,
|
|
77
|
+
path: params.path,
|
|
78
|
+
seed,
|
|
79
|
+
cryptographicFunctions: getClientCryptography(),
|
|
80
|
+
});
|
|
81
|
+
if (params.compressed) {
|
|
82
|
+
return node.compressedPublicKey;
|
|
83
|
+
}
|
|
84
|
+
return node.publicKey;
|
|
85
|
+
}
|
|
86
|
+
const secretRecoveryPhrase = await (0, utils_2.getValueFromEntropySource)(getMnemonic, params.source);
|
|
87
|
+
const node = await (0, utils_2.getNodeFromMnemonic)({
|
|
72
88
|
curve: params.curve,
|
|
73
89
|
path: params.path,
|
|
74
90
|
secretRecoveryPhrase,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32PublicKey.cjs","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":";;;AAOA,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAK+B;AAC/B,uDAA0E;AAE1E,2CAA+C;AAG/C,
|
|
1
|
+
{"version":3,"file":"getBip32PublicKey.cjs","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":";;;AAOA,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAK+B;AAC/B,uDAA0E;AAE1E,2CAA+C;AAG/C,wCAIkB;AAElB,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAoD/B,QAAA,wBAAwB,GAAG,IAAA,0BAAY,EAClD,IAAA,oBAAM,EAAC;IACL,IAAI,EAAE,6BAAe;IACrB,KAAK,EAAE,yBAAW;IAClB,UAAU,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC/B,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC3B,CAAC,CACH,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAAgD,EAAE,EAAE;IACpE,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,4BAAc,CAAC,wBAAwB,CAAC;QACzD,oBAAoB,EAAE,+BAA+B,CAAC,WAAW,CAAC;QAClE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,OAAO,EAAE,MAAM,KAAK,CAAC;gBACrB,OAAO,CAAC,CAAC,CAAC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qB,EAAE;aAChD,CAAC,CAAC;YAEH,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC,mBAAmB,CAAC;YAClC,CAAC;YAED,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC;QAED,MAAM,oBAAoB,GAAG,MAAM,IAAA,iCAAyB,EAC1D,WAAW,EACX,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,IAAA,2BAAmB,EAAC;YACrC,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,oBAAoB;YACpB,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,mBAAmB,CAAC;QAClC,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC;AA3DD,0EA2DC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32PublicKeyParams,\n GetBip32PublicKeyResult,\n} from '@metamask/snaps-sdk';\nimport {\n bip32entropy,\n Bip32PathStruct,\n CurveStruct,\n SnapCaveatType,\n} from '@metamask/snaps-utils';\nimport { boolean, object, optional, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport {\n getValueFromEntropySource,\n getNodeFromMnemonic,\n getNodeFromSeed,\n} from '../utils';\n\nconst targetName = 'snap_getBip32PublicKey';\n\nexport type GetBip32PublicKeyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Get the mnemonic seed of the provided source. If no source is provided, the\n * mnemonic seed of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic seed of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip32PublicKeySpecificationBuilderOptions = {\n methodHooks: GetBip32PublicKeyMethodHooks;\n};\n\ntype GetBip32PublicKeySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32PublicKeyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\nexport const Bip32PublicKeyArgsStruct = bip32entropy(\n object({\n path: Bip32PathStruct,\n curve: CurveStruct,\n compressed: optional(boolean()),\n source: optional(string()),\n }),\n);\n\n/**\n * The specification builder for the `snap_getBip32PublicKey` permission.\n * `snap_getBip32PublicKey` lets the Snap retrieve public keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32PublicKey` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32PublicKeySpecificationBuilderOptions,\n GetBip32PublicKeySpecification\n> = ({ methodHooks }: GetBip32PublicKeySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32PublicKeyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32PublicKeyMethodHooks> = {\n getMnemonic: true,\n getMnemonicSeed: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip32PublicKeyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32PublicKey`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a public key.\n * @throws If the params are invalid.\n */\nexport function getBip32PublicKeyImplementation({\n getMnemonic,\n getMnemonicSeed,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip32PublicKeyMethodHooks) {\n return async function getBip32PublicKey(\n args: RestrictedMethodOptions<GetBip32PublicKeyParams>,\n ): Promise<GetBip32PublicKeyResult> {\n await getUnlockPromise(true);\n\n assertStruct(\n args.params,\n Bip32PublicKeyArgsStruct,\n 'Invalid BIP-32 public key params',\n rpcErrors.invalidParams,\n );\n\n const { params } = args;\n\n // Using the seed is much faster, but we can only do it for these specific curves.\n if (params.curve === 'secp256k1' || params.curve === 'ed25519') {\n const seed = await getValueFromEntropySource(\n getMnemonicSeed,\n params.source,\n );\n\n const node = await getNodeFromSeed({\n curve: params.curve,\n path: params.path,\n seed,\n cryptographicFunctions: getClientCryptography(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n }\n\n const secretRecoveryPhrase = await getValueFromEntropySource(\n getMnemonic,\n params.source,\n );\n\n const node = await getNodeFromMnemonic({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase,\n cryptographicFunctions: getClientCryptography(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n };\n}\n"]}
|
|
@@ -15,6 +15,15 @@ export type GetBip32PublicKeyMethodHooks = {
|
|
|
15
15
|
* source is provided.
|
|
16
16
|
*/
|
|
17
17
|
getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the mnemonic seed of the provided source. If no source is provided, the
|
|
20
|
+
* mnemonic seed of the primary keyring will be returned.
|
|
21
|
+
*
|
|
22
|
+
* @param source - The optional ID of the source to get the mnemonic of.
|
|
23
|
+
* @returns The mnemonic seed of the provided source, or the default source if no
|
|
24
|
+
* source is provided.
|
|
25
|
+
*/
|
|
26
|
+
getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;
|
|
18
27
|
/**
|
|
19
28
|
* Waits for the extension to be unlocked.
|
|
20
29
|
*
|
|
@@ -60,6 +69,7 @@ export declare const getBip32PublicKeyBuilder: Readonly<{
|
|
|
60
69
|
*
|
|
61
70
|
* @param hooks - The RPC method hooks.
|
|
62
71
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
72
|
+
* @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.
|
|
63
73
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
64
74
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
65
75
|
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
@@ -67,6 +77,6 @@ export declare const getBip32PublicKeyBuilder: Readonly<{
|
|
|
67
77
|
* @returns The method implementation which returns a public key.
|
|
68
78
|
* @throws If the params are invalid.
|
|
69
79
|
*/
|
|
70
|
-
export declare function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }: GetBip32PublicKeyMethodHooks): (args: RestrictedMethodOptions<GetBip32PublicKeyParams>) => Promise<GetBip32PublicKeyResult>;
|
|
80
|
+
export declare function getBip32PublicKeyImplementation({ getMnemonic, getMnemonicSeed, getUnlockPromise, getClientCryptography, }: GetBip32PublicKeyMethodHooks): (args: RestrictedMethodOptions<GetBip32PublicKeyParams>) => Promise<GetBip32PublicKeyResult>;
|
|
71
81
|
export {};
|
|
72
82
|
//# sourceMappingURL=getBip32PublicKey.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32PublicKey.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,4BAA4B;AAQ7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;
|
|
1
|
+
{"version":3,"file":"getBip32PublicKey.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAw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17
17
|
getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the mnemonic seed of the provided source. If no source is provided, the
|
|
20
|
+
* mnemonic seed of the primary keyring will be returned.
|
|
21
|
+
*
|
|
22
|
+
* @param source - The optional ID of the source to get the mnemonic of.
|
|
23
|
+
* @returns The mnemonic seed of the provided source, or the default source if no
|
|
24
|
+
* source is provided.
|
|
25
|
+
*/
|
|
26
|
+
getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;
|
|
18
27
|
/**
|
|
19
28
|
* Waits for the extension to be unlocked.
|
|
20
29
|
*
|
|
@@ -60,6 +69,7 @@ export declare const getBip32PublicKeyBuilder: Readonly<{
|
|
|
60
69
|
*
|
|
61
70
|
* @param hooks - The RPC method hooks.
|
|
62
71
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
72
|
+
* @param hooks.getMnemonicSeed - A function to retrieve the BIP-39 seed of the user.
|
|
63
73
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
64
74
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
65
75
|
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
@@ -67,6 +77,6 @@ export declare const getBip32PublicKeyBuilder: Readonly<{
|
|
|
67
77
|
* @returns The method implementation which returns a public key.
|
|
68
78
|
* @throws If the params are invalid.
|
|
69
79
|
*/
|
|
70
|
-
export declare function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }: GetBip32PublicKeyMethodHooks): (args: RestrictedMethodOptions<GetBip32PublicKeyParams>) => Promise<GetBip32PublicKeyResult>;
|
|
80
|
+
export declare function getBip32PublicKeyImplementation({ getMnemonic, getMnemonicSeed, getUnlockPromise, getClientCryptography, }: GetBip32PublicKeyMethodHooks): (args: RestrictedMethodOptions<GetBip32PublicKeyParams>) => Promise<GetBip32PublicKeyResult>;
|
|
71
81
|
export {};
|
|
72
82
|
//# sourceMappingURL=getBip32PublicKey.d.mts.map
|