@metamask/snaps-utils 0.26.2 → 0.27.1
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/dist/entropy.d.ts +3 -0
- package/dist/entropy.js +8 -0
- package/dist/entropy.js.map +1 -0
- package/dist/handlers.d.ts +115 -0
- package/dist/handlers.js +3 -0
- package/dist/handlers.js.map +1 -0
- package/dist/index.browser.d.ts +2 -0
- package/dist/index.browser.js +2 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/manifest/validation.d.ts +0 -1
- package/dist/manifest/validation.js +6 -4
- package/dist/manifest/validation.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.js.map +1 -1
- package/package.json +3 -2
package/dist/entropy.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STATE_ENCRYPTION_MAGIC_VALUE = exports.SIP_6_MAGIC_VALUE = void 0;
|
|
4
|
+
// 0xd36e6170 - 0x80000000
|
|
5
|
+
exports.SIP_6_MAGIC_VALUE = `1399742832'`;
|
|
6
|
+
// `${bytesToNumber(keccak256('Snaps state encryption').slice(0, 4))}'`
|
|
7
|
+
exports.STATE_ENCRYPTION_MAGIC_VALUE = `572232532'`;
|
|
8
|
+
//# sourceMappingURL=entropy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropy.js","sourceRoot":"","sources":["../src/entropy.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AACb,QAAA,iBAAiB,GAAG,aAA6B,CAAC;AAE/D,uEAAuE;AAC1D,QAAA,4BAA4B,GAAG,YAA4B,CAAC","sourcesContent":["// 0xd36e6170 - 0x80000000\nexport const SIP_6_MAGIC_VALUE = `1399742832'` as `${number}'`;\n\n// `${bytesToNumber(keccak256('Snaps state encryption').slice(0, 4))}'`\nexport const STATE_ENCRYPTION_MAGIC_VALUE = `572232532'` as `${number}'`;\n\nexport type MagicValue =\n | typeof SIP_6_MAGIC_VALUE\n | typeof STATE_ENCRYPTION_MAGIC_VALUE;\n"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { StreamProvider } from '@metamask/providers';
|
|
2
|
+
import { Component } from '@metamask/snaps-ui';
|
|
3
|
+
import { Json, JsonRpcRequest } from '@metamask/utils';
|
|
4
|
+
import { AccountId, ChainId, RequestArguments } from './namespace';
|
|
5
|
+
/**
|
|
6
|
+
* The global `snap` object. This is injected into the global scope of a snap.
|
|
7
|
+
*/
|
|
8
|
+
export declare type SnapsGlobalObject = {
|
|
9
|
+
request: StreamProvider['request'];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The `onRpcRequest` handler. This is called whenever a JSON-RPC request is
|
|
13
|
+
* made to the snap.
|
|
14
|
+
*
|
|
15
|
+
* @param args - The request arguments.
|
|
16
|
+
* @param args.origin - The origin of the request. This can be the ID of another
|
|
17
|
+
* snap, or the URL of a dapp.
|
|
18
|
+
* @param args.request - The JSON-RPC request sent to the snap.
|
|
19
|
+
* @returns The JSON-RPC response. This must be a JSON-serializable value.
|
|
20
|
+
*/
|
|
21
|
+
export declare type OnRpcRequestHandler = (args: {
|
|
22
|
+
origin: string;
|
|
23
|
+
request: JsonRpcRequest<Json[] | Record<string, Json>>;
|
|
24
|
+
}) => Promise<unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* The response from a snap's `onTransaction` handler.
|
|
27
|
+
*
|
|
28
|
+
* @property insights - The insights object. This is a key-value map of the
|
|
29
|
+
* insights that the snap has about the transaction. The keys are the insight
|
|
30
|
+
* names, and the values are the insight values. The insight values must be
|
|
31
|
+
* JSON-serializable.
|
|
32
|
+
*
|
|
33
|
+
* If the snap has no insights about the transaction, this should be `null`.
|
|
34
|
+
*/
|
|
35
|
+
export declare type OnTransactionResponse = {
|
|
36
|
+
content: Component;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The `onTransaction` handler. This is called whenever a transaction is
|
|
40
|
+
* submitted to the snap. It can return insights about the transaction, which
|
|
41
|
+
* will be displayed to the user.
|
|
42
|
+
*
|
|
43
|
+
* @param args - The request arguments.
|
|
44
|
+
* @param args.transaction - The transaction object.
|
|
45
|
+
* @param args.chainId - The CAIP-2 chain ID of the network the transaction is
|
|
46
|
+
* being submitted to.
|
|
47
|
+
* @param args.transactionOrigin - The origin of the transaction. This is the
|
|
48
|
+
* URL of the dapp that submitted the transaction.
|
|
49
|
+
* @returns Insights about the transaction. See {@link OnTransactionResponse}.
|
|
50
|
+
*/
|
|
51
|
+
export declare type OnTransactionHandler = (args: {
|
|
52
|
+
transaction: {
|
|
53
|
+
[key: string]: Json;
|
|
54
|
+
};
|
|
55
|
+
chainId: string;
|
|
56
|
+
transactionOrigin?: string;
|
|
57
|
+
}) => Promise<OnTransactionResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* The `onCronjob` handler. This is called on a regular interval, as defined by
|
|
60
|
+
* the snap's manifest.
|
|
61
|
+
*
|
|
62
|
+
* @param args - The request arguments.
|
|
63
|
+
* @param args.request - The JSON-RPC request sent to the snap.
|
|
64
|
+
*/
|
|
65
|
+
export declare type OnCronjobHandler = (args: {
|
|
66
|
+
request: JsonRpcRequest<Json[] | Record<string, Json>>;
|
|
67
|
+
}) => Promise<unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* A request sent to the `handleRequest` handler of a snap keyring.
|
|
70
|
+
*
|
|
71
|
+
* @property chainId - The CAIP-2 chain ID of the network the request is being
|
|
72
|
+
* made to.
|
|
73
|
+
* @property origin - The origin of the request. This can be the ID of another
|
|
74
|
+
* snap, or the URL of a dapp.
|
|
75
|
+
*/
|
|
76
|
+
export declare type KeyringRequest = {
|
|
77
|
+
chainId: ChainId;
|
|
78
|
+
origin: string;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* A keyring event, which consists of a {@link KeyringRequest}, combined with
|
|
82
|
+
* the name of the event.
|
|
83
|
+
*/
|
|
84
|
+
export declare type KeyringEvent = KeyringRequest & {
|
|
85
|
+
eventName: string;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* A snap keyring object, which can be exported as `keyring` in a snap.
|
|
89
|
+
*/
|
|
90
|
+
export interface SnapKeyring {
|
|
91
|
+
getAccounts(): Promise<AccountId[]>;
|
|
92
|
+
handleRequest(data: KeyringRequest & {
|
|
93
|
+
request: RequestArguments;
|
|
94
|
+
}): Promise<Json>;
|
|
95
|
+
on(data: KeyringEvent, listener: (...args: Json[]) => void): void;
|
|
96
|
+
off(data: KeyringEvent): void;
|
|
97
|
+
addAccount?(chainId: ChainId): Promise<AccountId>;
|
|
98
|
+
removeAccount?(accountId: AccountId): Promise<void>;
|
|
99
|
+
importAccount?(chainId: ChainId, data: Json): Promise<AccountId>;
|
|
100
|
+
exportAccount?(accountId: AccountId): Promise<Json>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* All the function-based handlers that a snap can implement.
|
|
104
|
+
*/
|
|
105
|
+
export declare type SnapFunctionExports = {
|
|
106
|
+
onRpcRequest?: OnRpcRequestHandler;
|
|
107
|
+
onTransaction?: OnTransactionHandler;
|
|
108
|
+
onCronjob?: OnCronjobHandler;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* All handlers that a snap can implement.
|
|
112
|
+
*/
|
|
113
|
+
export declare type SnapExports = SnapFunctionExports & {
|
|
114
|
+
keyring?: SnapKeyring;
|
|
115
|
+
};
|
package/dist/handlers.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"","sourcesContent":["import type { StreamProvider } from '@metamask/providers';\nimport { Component } from '@metamask/snaps-ui';\nimport { Json, JsonRpcRequest } from '@metamask/utils';\n\nimport { AccountId, ChainId, RequestArguments } from './namespace';\n\n/**\n * The global `snap` object. This is injected into the global scope of a snap.\n */\nexport type SnapsGlobalObject = { request: StreamProvider['request'] };\n\n/**\n * The `onRpcRequest` handler. This is called whenever a JSON-RPC request is\n * made to the snap.\n *\n * @param args - The request arguments.\n * @param args.origin - The origin of the request. This can be the ID of another\n * snap, or the URL of a dapp.\n * @param args.request - The JSON-RPC request sent to the snap.\n * @returns The JSON-RPC response. This must be a JSON-serializable value.\n */\nexport type OnRpcRequestHandler = (args: {\n origin: string;\n request: JsonRpcRequest<Json[] | Record<string, Json>>;\n}) => Promise<unknown>;\n\n/**\n * The response from a snap's `onTransaction` handler.\n *\n * @property insights - The insights object. This is a key-value map of the\n * insights that the snap has about the transaction. The keys are the insight\n * names, and the values are the insight values. The insight values must be\n * JSON-serializable.\n *\n * If the snap has no insights about the transaction, this should be `null`.\n */\nexport type OnTransactionResponse = {\n content: Component;\n};\n\n/**\n * The `onTransaction` handler. This is called whenever a transaction is\n * submitted to the snap. It can return insights about the transaction, which\n * will be displayed to the user.\n *\n * @param args - The request arguments.\n * @param args.transaction - The transaction object.\n * @param args.chainId - The CAIP-2 chain ID of the network the transaction is\n * being submitted to.\n * @param args.transactionOrigin - The origin of the transaction. This is the\n * URL of the dapp that submitted the transaction.\n * @returns Insights about the transaction. See {@link OnTransactionResponse}.\n */\n// TODO: Improve type.\nexport type OnTransactionHandler = (args: {\n transaction: { [key: string]: Json };\n chainId: string;\n transactionOrigin?: string;\n}) => Promise<OnTransactionResponse>;\n\n/**\n * The `onCronjob` handler. This is called on a regular interval, as defined by\n * the snap's manifest.\n *\n * @param args - The request arguments.\n * @param args.request - The JSON-RPC request sent to the snap.\n */\nexport type OnCronjobHandler = (args: {\n request: JsonRpcRequest<Json[] | Record<string, Json>>;\n}) => Promise<unknown>;\n\n/**\n * A request sent to the `handleRequest` handler of a snap keyring.\n *\n * @property chainId - The CAIP-2 chain ID of the network the request is being\n * made to.\n * @property origin - The origin of the request. This can be the ID of another\n * snap, or the URL of a dapp.\n */\nexport type KeyringRequest = {\n chainId: ChainId;\n origin: string;\n};\n\n/**\n * A keyring event, which consists of a {@link KeyringRequest}, combined with\n * the name of the event.\n */\nexport type KeyringEvent = KeyringRequest & { eventName: string };\n\n/**\n * A snap keyring object, which can be exported as `keyring` in a snap.\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface SnapKeyring {\n getAccounts(): Promise<AccountId[]>;\n handleRequest(\n data: KeyringRequest & {\n request: RequestArguments;\n },\n ): Promise<Json>;\n on(data: KeyringEvent, listener: (...args: Json[]) => void): void;\n off(data: KeyringEvent): void;\n\n addAccount?(chainId: ChainId): Promise<AccountId>;\n removeAccount?(accountId: AccountId): Promise<void>;\n\n importAccount?(chainId: ChainId, data: Json): Promise<AccountId>;\n exportAccount?(accountId: AccountId): Promise<Json>;\n}\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n onRpcRequest?: OnRpcRequestHandler;\n onTransaction?: OnTransactionHandler;\n onCronjob?: OnCronjobHandler;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports & {\n keyring?: SnapKeyring;\n};\n"]}
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './caveats';
|
|
2
2
|
export * from './deep-clone';
|
|
3
3
|
export * from './default-endowments';
|
|
4
|
+
export * from './entropy';
|
|
4
5
|
export * from './flatMap';
|
|
6
|
+
export * from './handlers';
|
|
5
7
|
export * from './json-rpc';
|
|
6
8
|
export * from './manifest/index.browser';
|
|
7
9
|
export * from './namespace';
|
package/dist/index.browser.js
CHANGED
|
@@ -17,7 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./caveats"), exports);
|
|
18
18
|
__exportStar(require("./deep-clone"), exports);
|
|
19
19
|
__exportStar(require("./default-endowments"), exports);
|
|
20
|
+
__exportStar(require("./entropy"), exports);
|
|
20
21
|
__exportStar(require("./flatMap"), exports);
|
|
22
|
+
__exportStar(require("./handlers"), exports);
|
|
21
23
|
__exportStar(require("./json-rpc"), exports);
|
|
22
24
|
__exportStar(require("./manifest/index.browser"), exports);
|
|
23
25
|
__exportStar(require("./namespace"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,+CAA6B;AAC7B,uDAAqC;AACrC,4CAA0B;AAC1B,6CAA2B;AAC3B,2DAAyC;AACzC,8CAA4B;AAC5B,iDAA+B;AAC/B,2CAAyB;AACzB,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,+DAA6C","sourcesContent":["export * from './caveats';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './flatMap';\nexport * from './json-rpc';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './notification';\nexport * from './object';\nexport * from './path';\nexport * from './snaps';\nexport * from './types';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"]}
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,+CAA6B;AAC7B,uDAAqC;AACrC,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B;AAC3B,6CAA2B;AAC3B,2DAAyC;AACzC,8CAA4B;AAC5B,iDAA+B;AAC/B,2CAAyB;AACzB,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,+DAA6C","sourcesContent":["export * from './caveats';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './flatMap';\nexport * from './handlers';\nexport * from './json-rpc';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './notification';\nexport * from './object';\nexport * from './path';\nexport * from './snaps';\nexport * from './types';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ export * from './caveats';
|
|
|
2
2
|
export * from './cronjob';
|
|
3
3
|
export * from './deep-clone';
|
|
4
4
|
export * from './default-endowments';
|
|
5
|
+
export * from './entropy';
|
|
5
6
|
export * from './eval';
|
|
6
7
|
export * from './flatMap';
|
|
7
8
|
export * from './fs';
|
|
9
|
+
export * from './handlers';
|
|
8
10
|
export * from './json-rpc';
|
|
9
11
|
export * from './manifest';
|
|
10
12
|
export * from './mock';
|
package/dist/index.js
CHANGED
|
@@ -18,9 +18,11 @@ __exportStar(require("./caveats"), exports);
|
|
|
18
18
|
__exportStar(require("./cronjob"), exports);
|
|
19
19
|
__exportStar(require("./deep-clone"), exports);
|
|
20
20
|
__exportStar(require("./default-endowments"), exports);
|
|
21
|
+
__exportStar(require("./entropy"), exports);
|
|
21
22
|
__exportStar(require("./eval"), exports);
|
|
22
23
|
__exportStar(require("./flatMap"), exports);
|
|
23
24
|
__exportStar(require("./fs"), exports);
|
|
25
|
+
__exportStar(require("./handlers"), exports);
|
|
24
26
|
__exportStar(require("./json-rpc"), exports);
|
|
25
27
|
__exportStar(require("./manifest"), exports);
|
|
26
28
|
__exportStar(require("./mock"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B;AAC7B,uDAAqC;AACrC,yCAAuB;AACvB,4CAA0B;AAC1B,uCAAqB;AACrB,6CAA2B;AAC3B,6CAA2B;AAC3B,yCAAuB;AACvB,8CAA4B;AAC5B,iDAA+B;AAC/B,wCAAsB;AACtB,2CAAyB;AACzB,yCAAuB;AACvB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,iDAA+B","sourcesContent":["export * from './caveats';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './eval';\nexport * from './flatMap';\nexport * from './fs';\nexport * from './json-rpc';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './notification';\nexport * from './npm';\nexport * from './object';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './types';\nexport * from './versions';\nexport * from './virtual-file';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B;AAC7B,uDAAqC;AACrC,4CAA0B;AAC1B,yCAAuB;AACvB,4CAA0B;AAC1B,uCAAqB;AACrB,6CAA2B;AAC3B,6CAA2B;AAC3B,6CAA2B;AAC3B,yCAAuB;AACvB,8CAA4B;AAC5B,iDAA+B;AAC/B,wCAAsB;AACtB,2CAAyB;AACzB,yCAAuB;AACvB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,iDAA+B","sourcesContent":["export * from './caveats';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './eval';\nexport * from './flatMap';\nexport * from './fs';\nexport * from './handlers';\nexport * from './json-rpc';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './notification';\nexport * from './npm';\nexport * from './object';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './types';\nexport * from './versions';\nexport * from './virtual-file';\n"]}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSnapManifest = exports.assertIsSnapManifest = exports.isSnapManifest = exports.SnapManifestStruct = exports.PermissionsStruct = exports.SnapGetBip32EntropyPermissionsStruct = exports.Bip32EntropyStruct = exports.bip32entropy = exports.Bip32PathStruct = exports.base64 =
|
|
3
|
+
exports.createSnapManifest = exports.assertIsSnapManifest = exports.isSnapManifest = exports.SnapManifestStruct = exports.PermissionsStruct = exports.SnapGetBip32EntropyPermissionsStruct = exports.Bip32EntropyStruct = exports.bip32entropy = exports.Bip32PathStruct = exports.base64 = void 0;
|
|
4
4
|
const utils_1 = require("@metamask/utils");
|
|
5
5
|
const superstruct_1 = require("superstruct");
|
|
6
6
|
const cronjob_1 = require("../cronjob");
|
|
7
|
+
const entropy_1 = require("../entropy");
|
|
7
8
|
const json_rpc_1 = require("../json-rpc");
|
|
8
9
|
const namespace_1 = require("../namespace");
|
|
9
10
|
const path_1 = require("../path");
|
|
10
11
|
const types_1 = require("../types");
|
|
11
12
|
const versions_1 = require("../versions");
|
|
12
|
-
// 0xd36e6170 - 0x80000000
|
|
13
|
-
exports.SIP_6_MAGIC_VALUE = `1399742832'`;
|
|
14
13
|
// BIP-43 purposes that cannot be used for entropy derivation. These are in the
|
|
15
14
|
// string form, ending with `'`.
|
|
16
|
-
const FORBIDDEN_PURPOSES = [
|
|
15
|
+
const FORBIDDEN_PURPOSES = [
|
|
16
|
+
entropy_1.SIP_6_MAGIC_VALUE,
|
|
17
|
+
entropy_1.STATE_ENCRYPTION_MAGIC_VALUE,
|
|
18
|
+
];
|
|
17
19
|
/**
|
|
18
20
|
* Ensure that a provided string-based struct is valid base64.
|
|
19
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AACvD,6CAmBqB;AAErB,wCAA6D;AAC7D,0CAA+C;AAC/C,4CAAgD;AAChD,kCAA4C;AAC5C,oCAAwD;AACxD,0CAA4C;AAE5C,0BAA0B;AACb,QAAA,iBAAiB,GAAG,aAA6B,CAAC;AAE/D,+EAA+E;AAC/E,gCAAgC;AAChC,MAAM,kBAAkB,GAAa,CAAC,yBAAiB,CAAC,CAAC;AAmBzD;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AU;gBACvB,QAAQ,EAAE,IAAA,mBAAK,EAAC;oBACd,IAAA,qBAAO,EAAC,4BAA4B,CAAC;oBACrC,IAAA,qBAAO,EAAC,6BAA6B,CAAC;iBACvC,CAAC;aACH,CAAC;SACH,CAAC;KACH,CAAC;IACF,kBAAkB,EAAE,yBAAiB;IACrC,eAAe,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;CAChC,CAAC,CAAC;AAIH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAA,oBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,IAAI,wBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AARD,oDAQC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,IAAA,oBAAM,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AAC3C,CAAC;AAHD,gDAGC","sourcesContent":["import { assert, assertStruct } from '@metamask/utils';\nimport {\n array,\n boolean,\n coerce,\n create,\n enums,\n Infer,\n integer,\n is,\n literal,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n Struct,\n type,\n union,\n} from 'superstruct';\n\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { RpcOriginsStruct } from '../json-rpc';\nimport { NamespacesStruct } from '../namespace';\nimport { normalizeRelative } from '../path';\nimport { NameStruct, NpmSnapFileNames } from '../types';\nimport { VersionStruct } from '../versions';\n\n// 0xd36e6170 - 0x80000000\nexport const SIP_6_MAGIC_VALUE = `1399742832'` as `${number}'`;\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [SIP_6_MAGIC_VALUE];\n\nexport type Base64Opts = {\n /**\n * Is the `=` padding at the end required or not.\n *\n * @default false\n */\n // Padding is optional in RFC 4648, that's why the default value is false\n paddingRequired?: boolean;\n /**\n * Which character set should be used.\n * The sets are based on {@link https://datatracker.ietf.org/doc/html/rfc4648 RFC 4648}.\n *\n * @default 'base64'\n */\n characterSet?: 'base64' | 'base64url';\n};\n\n/**\n * Ensure that a provided string-based struct is valid base64.\n *\n * @param struct - The string based struct.\n * @param opts - Optional options to specialize base64 validation. See {@link Base64Opts} documentation.\n * @returns A superstruct validating base64.\n */\nexport const base64 = <T extends string, S>(\n struct: Struct<T, S>,\n opts: Base64Opts = {},\n) => {\n const paddingRequired = opts.paddingRequired ?? false;\n const characterSet = opts.characterSet ?? 'base64';\n\n let letters: string;\n if (characterSet === 'base64') {\n letters = String.raw`[A-Za-z0-9+\\/]`;\n } else {\n assert(characterSet === 'base64url');\n letters = String.raw`[-_A-Za-z0-9]`;\n }\n\n let re: RegExp;\n if (paddingRequired) {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n } else {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{2,3}|${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n }\n\n return pattern(struct, re);\n};\n\nconst BIP32_INDEX_REGEX = /^\\d+'?$/u;\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !BIP32_INDEX_REGEX.test(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <T extends { path: string[]; curve: string }, S>(\n struct: Struct<T, S>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: enums(['ed25519', 'secp256k1']),\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct = type({\n 'endowment:long-running': optional(object({})),\n 'endowment:network-access': optional(object({})),\n 'endowment:transaction-insight': optional(\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n 'endowment:cronjob': optional(\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n 'endowment:rpc': optional(RpcOriginsStruct),\n snap_confirm: optional(object({})),\n snap_manageState: optional(object({})),\n snap_notify: optional(object({})),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(object({})),\n 'endowment:keyring': optional(\n object({\n namespaces: NamespacesStruct,\n }),\n ),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nconst relativePath = <Type extends string>(struct: Struct<Type>) =>\n coerce(struct, struct, (value) => normalizeRelative(value));\n\nexport type SnapPermissions = Infer<typeof PermissionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(\n pattern(\n string(),\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u,\n ),\n 1,\n 214,\n ),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: size(base64(string(), { paddingRequired: true }), 44, 44),\n location: object({\n npm: object({\n filePath: relativePath(size(string(), 1, Infinity)),\n iconPath: optional(relativePath(size(string(), 1, Infinity))),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n }),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AACvD,6CAmBqB;AAErB,wCAA6D;AAC7D,wCAA6E;AAC7E,0CAA+C;AAC/C,4CAAgD;AAChD,kCAA4C;AAC5C,oC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Q,EAAC,YAAY,CAAC,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;gBAC7D,WAAW,EAAE,kBAAU;gBACvB,QAAQ,EAAE,IAAA,mBAAK,EAAC;oBACd,IAAA,qBAAO,EAAC,4BAA4B,CAAC;oBACrC,IAAA,qBAAO,EAAC,6BAA6B,CAAC;iBACvC,CAAC;aACH,CAAC;SACH,CAAC;KACH,CAAC;IACF,kBAAkB,EAAE,yBAAiB;IACrC,eAAe,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;CAChC,CAAC,CAAC;AAIH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAA,oBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,IAAI,wBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AARD,oDAQC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,IAAA,oBAAM,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AAC3C,CAAC;AAHD,gDAGC","sourcesContent":["import { assert, assertStruct } from '@metamask/utils';\nimport {\n array,\n boolean,\n coerce,\n create,\n enums,\n Infer,\n integer,\n is,\n literal,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n Struct,\n type,\n union,\n} from 'superstruct';\n\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { RpcOriginsStruct } from '../json-rpc';\nimport { NamespacesStruct } from '../namespace';\nimport { normalizeRelative } from '../path';\nimport { NameStruct, NpmSnapFileNames } from '../types';\nimport { VersionStruct } from '../versions';\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [\n SIP_6_MAGIC_VALUE,\n STATE_ENCRYPTION_MAGIC_VALUE,\n];\n\nexport type Base64Opts = {\n /**\n * Is the `=` padding at the end required or not.\n *\n * @default false\n */\n // Padding is optional in RFC 4648, that's why the default value is false\n paddingRequired?: boolean;\n /**\n * Which character set should be used.\n * The sets are based on {@link https://datatracker.ietf.org/doc/html/rfc4648 RFC 4648}.\n *\n * @default 'base64'\n */\n characterSet?: 'base64' | 'base64url';\n};\n\n/**\n * Ensure that a provided string-based struct is valid base64.\n *\n * @param struct - The string based struct.\n * @param opts - Optional options to specialize base64 validation. See {@link Base64Opts} documentation.\n * @returns A superstruct validating base64.\n */\nexport const base64 = <T extends string, S>(\n struct: Struct<T, S>,\n opts: Base64Opts = {},\n) => {\n const paddingRequired = opts.paddingRequired ?? false;\n const characterSet = opts.characterSet ?? 'base64';\n\n let letters: string;\n if (characterSet === 'base64') {\n letters = String.raw`[A-Za-z0-9+\\/]`;\n } else {\n assert(characterSet === 'base64url');\n letters = String.raw`[-_A-Za-z0-9]`;\n }\n\n let re: RegExp;\n if (paddingRequired) {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n } else {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{2,3}|${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n }\n\n return pattern(struct, re);\n};\n\nconst BIP32_INDEX_REGEX = /^\\d+'?$/u;\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !BIP32_INDEX_REGEX.test(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <T extends { path: string[]; curve: string }, S>(\n struct: Struct<T, S>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: enums(['ed25519', 'secp256k1']),\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct = type({\n 'endowment:long-running': optional(object({})),\n 'endowment:network-access': optional(object({})),\n 'endowment:transaction-insight': optional(\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n 'endowment:cronjob': optional(\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n 'endowment:rpc': optional(RpcOriginsStruct),\n snap_confirm: optional(object({})),\n snap_manageState: optional(object({})),\n snap_notify: optional(object({})),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(object({})),\n 'endowment:keyring': optional(\n object({\n namespaces: NamespacesStruct,\n }),\n ),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nconst relativePath = <Type extends string>(struct: Struct<Type>) =>\n coerce(struct, struct, (value) => normalizeRelative(value));\n\nexport type SnapPermissions = Infer<typeof PermissionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(\n pattern(\n string(),\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u,\n ),\n 1,\n 214,\n ),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: size(base64(string(), { paddingRequired: true }), 44, 44),\n location: object({\n npm: object({\n filePath: relativePath(size(string(), 1, Infinity)),\n iconPath: optional(relativePath(size(string(), 1, Infinity))),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n }),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SnapFunctionExports, SnapKeyring as Keyring } from '@metamask/snaps-types';
|
|
2
1
|
import { Json } from '@metamask/utils';
|
|
3
2
|
import { Infer, Struct } from 'superstruct';
|
|
4
|
-
import {
|
|
3
|
+
import { SnapFunctionExports, SnapKeyring as Keyring } from './handlers';
|
|
4
|
+
import { SnapManifest } from './manifest';
|
|
5
5
|
export declare enum NpmSnapFileNames {
|
|
6
6
|
PackageJson = "package.json",
|
|
7
7
|
Manifest = "snap.manifest.json"
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,2CAAqD;AACrD,6CAcqB;AAIrB,yCAA2C;AAE3C,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,gDAA4B,CAAA;IAC5B,mDAA+B,CAAA;AACjC,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B;AAEY,QAAA,UAAU,GAAG,IAAA,kBAAI,EAC5B,IAAA,qBAAO,EACL,IAAA,oBAAM,GAAE,EACR,6DAA6D,CAC9D,EACD,CAAC,EACD,GAAG,CACJ,CAAC;AAEF,2EAA2E;AAC3E,sBAAsB;AACT,QAAA,wBAAwB,GAAG,IAAA,kBAAI,EAAC;IAC3C,OAAO,EAAE,wBAAa;IACtB,IAAI,EAAE,kBAAU;IAChB,IAAI,EAAE,IAAA,sBAAQ,EAAC,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC3C,UAAU,EAAE,IAAA,sBAAQ,EAClB,IAAA,oBAAM,EAAC;QACL,IAAI,EAAE,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,QAAQ,CAAC;QACjC,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,OAAwB,EAAE,EAAE,EAAE,CAChD,IAAA,oBAAM,EAAC,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,sBAAQ,EAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;IACxD,IAAI;QACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAE3B,MAAM,SAAS,GAAG,IAAA,kBAAI,EAAC,IAAI,CAAC,CAAC;QAC7B,IAAA,oBAAiB,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;KACb;IAAC,WAAM;QACN,OAAO,sBAAsB,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC;KACnD;AACH,CAAC,CAAC,CAAC;AAXQ,QAAA,GAAG,OAWX;AAEL;;;;;;GAMG;AACH,SAAgB,UAAU,CACxB,GAAY,EACZ,OAAwB,EAAE;IAE1B,OAAO,IAAA,gBAAE,EAAC,GAAG,EAAE,IAAA,WAAG,EAAC,IAAI,CAAC,CAAC,CAAC;AAC5B,CAAC;AALD,gCAKC","sourcesContent":["import { assertStruct, Json } from '@metamask/utils';\nimport {\n Infer,\n instance,\n is,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n Struct,\n type,\n union,\n assert as assertSuperstruct,\n} from 'superstruct';\n\nimport { SnapFunctionExports, SnapKeyring as Keyring } from './handlers';\nimport { SnapManifest } from './manifest';\nimport { VersionStruct } from './versions';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n pattern(\n string(),\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * Check if the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link NpmSnapPackageJson} object.\n */\nexport function isNpmSnapPackageJson(\n value: unknown,\n): value is NpmSnapPackageJson {\n return is(value, NpmSnapPackageJsonStruct);\n}\n\n/**\n * Asserts that the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link NpmSnapPackageJson} object.\n */\nexport function assertIsNpmSnapPackageJson(\n value: unknown,\n): asserts value is NpmSnapPackageJson {\n assertStruct(\n value,\n NpmSnapPackageJsonStruct,\n `\"${NpmSnapFileNames.PackageJson}\" is invalid`,\n );\n}\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: Json;\n packageJson?: Json;\n sourceCode?: string;\n svgIcon?: string;\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: SnapManifest;\n packageJson: NpmSnapPackageJson;\n sourceCode: string;\n svgIcon?: string;\n};\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapId = string;\n\n/**\n * Snap validation failure reason codes that are programmatically fixable\n * if validation occurs during development.\n */\nexport enum SnapValidationFailureReason {\n NameMismatch = '\"name\" field mismatch',\n VersionMismatch = '\"version\" field mismatch',\n RepositoryMismatch = '\"repository\" field mismatch',\n ShasumMismatch = '\"shasum\" field mismatch',\n}\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport enum HandlerType {\n OnRpcRequest = 'onRpcRequest',\n OnTransaction = 'onTransaction',\n SnapKeyring = 'keyring',\n OnCronjob = 'onCronjob',\n}\n\nexport const SNAP_EXPORT_NAMES = Object.values(HandlerType);\n\nexport type SnapRpcHookArgs = {\n origin: string;\n handler: HandlerType;\n request: Record<string, unknown>;\n};\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\ntype KeyringParameter<Fn> = Fn extends (...args: any[]) => unknown\n ? Parameters<Fn>\n : never;\n\ntype KeyringParameters = KeyringParameter<Keyring[keyof Keyring]>;\n\nexport type SnapExportsParameters =\n | ObjectParameters<SnapFunctionExports>\n | KeyringParameters;\n\n// We use a symbol property name instead of { _type: Brand }, because that would show up in IDE suggestions,\n// while internal symbols do not.\ndeclare const brand: unique symbol;\nexport type Opaque<Base, Brand extends symbol> = Base & { [brand]: Brand };\n\ntype UriOptions<T extends string> = {\n protocol?: Struct<T>;\n hash?: Struct<T>;\n port?: Struct<T>;\n hostname?: Struct<T>;\n pathname?: Struct<T>;\n search?: Struct<T>;\n};\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(union([string(), instance(URL)]), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch {\n return `Expected URL, got \"${value.toString()}\".`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string | URL {\n return is(url, uri(opts));\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/MetaMask/snaps-monorepo.git"
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@babel/core": "^7.18.6",
|
|
54
54
|
"@babel/types": "^7.18.7",
|
|
55
|
-
"@metamask/
|
|
55
|
+
"@metamask/providers": "^10.2.1",
|
|
56
|
+
"@metamask/snaps-ui": "^0.27.1",
|
|
56
57
|
"@metamask/utils": "^3.3.1",
|
|
57
58
|
"@noble/hashes": "^1.1.3",
|
|
58
59
|
"@scure/base": "^1.1.1",
|