@metamask/keyring-api 5.1.0 → 6.1.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 +27 -1
- package/dist/api.d.ts +49 -61
- package/dist/api.js +34 -50
- package/dist/api.js.map +1 -1
- package/dist/base-types.d.ts +62 -0
- package/dist/base-types.js +32 -0
- package/dist/base-types.js.map +1 -0
- package/dist/btc/index.d.ts +1 -0
- package/dist/btc/index.js +18 -0
- package/dist/btc/index.js.map +1 -0
- package/dist/btc/types.d.ts +36 -0
- package/dist/btc/types.js +42 -0
- package/dist/btc/types.js.map +1 -0
- package/dist/eth/erc4337/types.d.ts +1 -1
- package/dist/eth/index.d.ts +1 -0
- package/dist/eth/index.js +1 -0
- package/dist/eth/index.js.map +1 -1
- package/dist/eth/types.d.ts +83 -0
- package/dist/eth/types.js +76 -5
- package/dist/eth/types.js.map +1 -1
- package/dist/eth/utils.d.ts +7 -0
- package/dist/eth/utils.js +14 -0
- package/dist/eth/utils.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/api.d.ts +109 -101
- package/dist/internal/events.d.ts +92 -62
- package/dist/internal/types.d.ts +205 -24
- package/dist/internal/types.js +31 -3
- package/dist/internal/types.js.map +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [6.1.0]
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Add `isEvmAccountType` helper ([#297](https://github.com/MetaMask/keyring-api/pull/297))
|
15
|
+
- Add `bip121:p2wpkh` account support ([#294](https://github.com/MetaMask/keyring-api/pull/294))
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- Remove incorrect `SignTransaction` from `EthErc4337Account` ([#300](https://github.com/MetaMask/keyring-api/pull/300))
|
20
|
+
- Bump @metamask/providers from 16.0.0 to 16.1.0 ([#298](https://github.com/MetaMask/keyring-api/pull/298))
|
21
|
+
- Bump @metamask/snaps-sdk from 4.0.0 to 4.0.1 ([#292](https://github.com/MetaMask/keyring-api/pull/292))
|
22
|
+
- Split account types (EOA + Erc4337) ([#293](https://github.com/MetaMask/keyring-api/pull/293))
|
23
|
+
|
24
|
+
## [6.0.0]
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
|
28
|
+
- **BREAKING**: Add `importTime` property to `InternalAccount` metadata ([#289](https://github.com/MetaMask/keyring-api/pull/289))
|
29
|
+
- Bump tar from 6.1.15 to 6.2.1 ([#286](https://github.com/MetaMask/keyring-api/pull/286))
|
30
|
+
- Bump @metamask/snaps-sdk from 3.2.0 to 4.0.0 ([#287](https://github.com/MetaMask/keyring-api/pull/287))
|
31
|
+
- Add documentation for `eth_decodeUserOperationCallData` ([#254](https://github.com/MetaMask/keyring-api/pull/254))
|
32
|
+
- Bump @metamask/snaps-sdk from 3.1.1 to 3.2.0 ([#284](https://github.com/MetaMask/keyring-api/pull/284))
|
33
|
+
|
10
34
|
## [5.1.0]
|
11
35
|
|
12
36
|
### Changed
|
@@ -252,7 +276,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
252
276
|
- SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
|
253
277
|
- Helper functions to create keyring handler in the snap.
|
254
278
|
|
255
|
-
[Unreleased]: https://github.com/MetaMask/keyring-api/compare/
|
279
|
+
[Unreleased]: https://github.com/MetaMask/keyring-api/compare/v6.1.0...HEAD
|
280
|
+
[6.1.0]: https://github.com/MetaMask/keyring-api/compare/v6.0.0...v6.1.0
|
281
|
+
[6.0.0]: https://github.com/MetaMask/keyring-api/compare/v5.1.0...v6.0.0
|
256
282
|
[5.1.0]: https://github.com/MetaMask/keyring-api/compare/v5.0.0...v5.1.0
|
257
283
|
[5.0.0]: https://github.com/MetaMask/keyring-api/compare/v4.0.2...v5.0.0
|
258
284
|
[4.0.2]: https://github.com/MetaMask/keyring-api/compare/v4.0.1...v4.0.2
|
package/dist/api.d.ts
CHANGED
@@ -1,77 +1,65 @@
|
|
1
1
|
import type { Json } from '@metamask/utils';
|
2
|
-
import type { Infer } from 'superstruct';
|
2
|
+
import type { Infer, Struct } from 'superstruct';
|
3
|
+
import type { StaticAssertAbstractAccount } from './base-types';
|
4
|
+
import type { BtcP2wpkhAccount } from './btc';
|
5
|
+
import type { EthEoaAccount, EthErc4337Account } from './eth';
|
3
6
|
/**
|
4
|
-
*
|
7
|
+
* Type of supported accounts.
|
5
8
|
*/
|
6
|
-
export declare
|
7
|
-
PersonalSign = "personal_sign",
|
8
|
-
Sign = "eth_sign",
|
9
|
-
SignTransaction = "eth_signTransaction",
|
10
|
-
SignTypedDataV1 = "eth_signTypedData_v1",
|
11
|
-
SignTypedDataV3 = "eth_signTypedData_v3",
|
12
|
-
SignTypedDataV4 = "eth_signTypedData_v4",
|
13
|
-
PrepareUserOperation = "eth_prepareUserOperation",
|
14
|
-
PatchUserOperation = "eth_patchUserOperation",
|
15
|
-
SignUserOperation = "eth_signUserOperation"
|
16
|
-
}
|
9
|
+
export declare type KeyringAccounts = StaticAssertAbstractAccount<EthEoaAccount | EthErc4337Account | BtcP2wpkhAccount>;
|
17
10
|
/**
|
18
|
-
*
|
11
|
+
* Mapping between account types and their matching `superstruct` schema.
|
19
12
|
*/
|
20
|
-
export declare
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
export declare const
|
25
|
-
type: "eip155:eoa" | "eip155:erc4337";
|
26
|
-
id: string;
|
27
|
-
address: string;
|
28
|
-
options: Record<string, Json>;
|
29
|
-
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
|
13
|
+
export declare const KeyringAccountStructs: Record<string, Struct<EthEoaAccount> | Struct<EthErc4337Account> | Struct<BtcP2wpkhAccount>>;
|
14
|
+
/**
|
15
|
+
* Base type for `KeyringAccount` as a `superstruct.object`.
|
16
|
+
*/
|
17
|
+
export declare const BaseKeyringAccountStruct: Struct<{
|
18
|
+
type: "bip122:p2wpkh" | "eip155:eoa" | "eip155:erc4337";
|
30
19
|
}, {
|
31
|
-
/**
|
32
|
-
* Account ID (UUIDv4).
|
33
|
-
*/
|
34
|
-
id: import("superstruct").Struct<string, null>;
|
35
|
-
/**
|
36
|
-
* Account address or next receive address (UTXO).
|
37
|
-
*/
|
38
|
-
address: import("superstruct").Struct<string, null>;
|
39
|
-
/**
|
40
|
-
* Keyring-dependent account options.
|
41
|
-
*/
|
42
|
-
options: import("superstruct").Struct<Record<string, Json>, null>;
|
43
|
-
/**
|
44
|
-
* Account supported methods.
|
45
|
-
*/
|
46
|
-
methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
|
47
|
-
personal_sign: "personal_sign";
|
48
|
-
eth_sign: "eth_sign";
|
49
|
-
eth_signTransaction: "eth_signTransaction";
|
50
|
-
eth_signTypedData_v1: "eth_signTypedData_v1";
|
51
|
-
eth_signTypedData_v3: "eth_signTypedData_v3";
|
52
|
-
eth_signTypedData_v4: "eth_signTypedData_v4";
|
53
|
-
eth_prepareUserOperation: "eth_prepareUserOperation";
|
54
|
-
eth_patchUserOperation: "eth_patchUserOperation";
|
55
|
-
eth_signUserOperation: "eth_signUserOperation";
|
56
|
-
}>>;
|
57
20
|
/**
|
58
21
|
* Account type.
|
59
22
|
*/
|
60
|
-
type:
|
23
|
+
type: Struct<"bip122:p2wpkh" | "eip155:eoa" | "eip155:erc4337", {
|
24
|
+
"bip122:p2wpkh": "bip122:p2wpkh";
|
61
25
|
"eip155:eoa": "eip155:eoa";
|
62
26
|
"eip155:erc4337": "eip155:erc4337";
|
63
27
|
}>;
|
64
28
|
}>;
|
29
|
+
/**
|
30
|
+
* Account as a `superstruct.object`.
|
31
|
+
*
|
32
|
+
* See {@link KeyringAccount}.
|
33
|
+
*/
|
34
|
+
export declare const KeyringAccountStruct: Struct<{
|
35
|
+
type: "bip122:p2wpkh";
|
36
|
+
id: string;
|
37
|
+
address: string;
|
38
|
+
options: Record<string, Json>;
|
39
|
+
methods: "btc_sendmany"[];
|
40
|
+
} | {
|
41
|
+
type: "eip155:eoa";
|
42
|
+
id: string;
|
43
|
+
address: string;
|
44
|
+
options: Record<string, Json>;
|
45
|
+
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
46
|
+
} | {
|
47
|
+
type: "eip155:erc4337";
|
48
|
+
id: string;
|
49
|
+
address: string;
|
50
|
+
options: Record<string, Json>;
|
51
|
+
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
|
52
|
+
}, null>;
|
65
53
|
/**
|
66
54
|
* Account object.
|
67
55
|
*
|
68
56
|
* Represents an account with its properties and capabilities.
|
69
57
|
*/
|
70
58
|
export declare type KeyringAccount = Infer<typeof KeyringAccountStruct>;
|
71
|
-
export declare const KeyringRequestStruct:
|
59
|
+
export declare const KeyringRequestStruct: Struct<{
|
72
60
|
id: string;
|
73
|
-
scope: string;
|
74
61
|
account: string;
|
62
|
+
scope: string;
|
75
63
|
request: {
|
76
64
|
method: string;
|
77
65
|
params?: Json[] | Record<string, Json>;
|
@@ -80,24 +68,24 @@ export declare const KeyringRequestStruct: import("superstruct").Struct<{
|
|
80
68
|
/**
|
81
69
|
* Keyring request ID (UUIDv4).
|
82
70
|
*/
|
83
|
-
id:
|
71
|
+
id: Struct<string, null>;
|
84
72
|
/**
|
85
73
|
* Request's scope (CAIP-2 chain ID).
|
86
74
|
*/
|
87
|
-
scope:
|
75
|
+
scope: Struct<string, null>;
|
88
76
|
/**
|
89
77
|
* Account ID (UUIDv4).
|
90
78
|
*/
|
91
|
-
account:
|
79
|
+
account: Struct<string, null>;
|
92
80
|
/**
|
93
81
|
* Inner request sent by the client application.
|
94
82
|
*/
|
95
|
-
request:
|
83
|
+
request: Struct<{
|
96
84
|
method: string;
|
97
85
|
params?: Json[] | Record<string, Json>;
|
98
86
|
}, {
|
99
|
-
method:
|
100
|
-
params:
|
87
|
+
method: Struct<string, null>;
|
88
|
+
params: Struct<import("./superstruct").ExactOptionalTag | Json[] | Record<string, Json>, null>;
|
101
89
|
}>;
|
102
90
|
}>;
|
103
91
|
/**
|
@@ -106,14 +94,14 @@ export declare const KeyringRequestStruct: import("superstruct").Struct<{
|
|
106
94
|
* Represents a request made to the keyring for account-related operations.
|
107
95
|
*/
|
108
96
|
export declare type KeyringRequest = Infer<typeof KeyringRequestStruct>;
|
109
|
-
export declare const KeyringAccountDataStruct:
|
97
|
+
export declare const KeyringAccountDataStruct: Struct<Record<string, Json>, null>;
|
110
98
|
/**
|
111
99
|
* Response to a call to `exportAccount`.
|
112
100
|
*
|
113
101
|
* The exact response depends on the keyring implementation.
|
114
102
|
*/
|
115
103
|
export declare type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;
|
116
|
-
export declare const KeyringResponseStruct:
|
104
|
+
export declare const KeyringResponseStruct: Struct<{
|
117
105
|
pending: true;
|
118
106
|
redirect?: {
|
119
107
|
message?: string;
|
package/dist/api.js
CHANGED
@@ -1,66 +1,50 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.KeyringResponseStruct = exports.KeyringAccountDataStruct = exports.KeyringRequestStruct = exports.KeyringAccountStruct = exports.
|
3
|
+
exports.KeyringResponseStruct = exports.KeyringAccountDataStruct = exports.KeyringRequestStruct = exports.KeyringAccountStruct = exports.BaseKeyringAccountStruct = exports.KeyringAccountStructs = void 0;
|
4
4
|
const utils_1 = require("@metamask/utils");
|
5
5
|
const superstruct_1 = require("superstruct");
|
6
|
+
const btc_1 = require("./btc");
|
7
|
+
const eth_1 = require("./eth");
|
6
8
|
const superstruct_2 = require("./superstruct");
|
7
9
|
const utils_2 = require("./utils");
|
8
10
|
/**
|
9
|
-
*
|
11
|
+
* Mapping between account types and their matching `superstruct` schema.
|
10
12
|
*/
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
EthMethod["SignTransaction"] = "eth_signTransaction";
|
17
|
-
EthMethod["SignTypedDataV1"] = "eth_signTypedData_v1";
|
18
|
-
EthMethod["SignTypedDataV3"] = "eth_signTypedData_v3";
|
19
|
-
EthMethod["SignTypedDataV4"] = "eth_signTypedData_v4";
|
20
|
-
// ERC-4337 methods
|
21
|
-
EthMethod["PrepareUserOperation"] = "eth_prepareUserOperation";
|
22
|
-
EthMethod["PatchUserOperation"] = "eth_patchUserOperation";
|
23
|
-
EthMethod["SignUserOperation"] = "eth_signUserOperation";
|
24
|
-
})(EthMethod = exports.EthMethod || (exports.EthMethod = {}));
|
13
|
+
exports.KeyringAccountStructs = {
|
14
|
+
[`${eth_1.EthAccountType.Eoa}`]: eth_1.EthEoaAccountStruct,
|
15
|
+
[`${eth_1.EthAccountType.Erc4337}`]: eth_1.EthErc4337AccountStruct,
|
16
|
+
[`${btc_1.BtcAccountType.P2wpkh}`]: btc_1.BtcP2wpkhAccountStruct,
|
17
|
+
};
|
25
18
|
/**
|
26
|
-
*
|
19
|
+
* Base type for `KeyringAccount` as a `superstruct.object`.
|
27
20
|
*/
|
28
|
-
|
29
|
-
(function (EthAccountType) {
|
30
|
-
EthAccountType["Eoa"] = "eip155:eoa";
|
31
|
-
EthAccountType["Erc4337"] = "eip155:erc4337";
|
32
|
-
})(EthAccountType = exports.EthAccountType || (exports.EthAccountType = {}));
|
33
|
-
exports.KeyringAccountStruct = (0, superstruct_2.object)({
|
34
|
-
/**
|
35
|
-
* Account ID (UUIDv4).
|
36
|
-
*/
|
37
|
-
id: utils_2.UuidStruct,
|
38
|
-
/**
|
39
|
-
* Account address or next receive address (UTXO).
|
40
|
-
*/
|
41
|
-
address: (0, superstruct_1.string)(),
|
42
|
-
/**
|
43
|
-
* Keyring-dependent account options.
|
44
|
-
*/
|
45
|
-
options: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
|
46
|
-
/**
|
47
|
-
* Account supported methods.
|
48
|
-
*/
|
49
|
-
methods: (0, superstruct_1.array)((0, superstruct_1.enums)([
|
50
|
-
`${EthMethod.PersonalSign}`,
|
51
|
-
`${EthMethod.Sign}`,
|
52
|
-
`${EthMethod.SignTransaction}`,
|
53
|
-
`${EthMethod.SignTypedDataV1}`,
|
54
|
-
`${EthMethod.SignTypedDataV3}`,
|
55
|
-
`${EthMethod.SignTypedDataV4}`,
|
56
|
-
`${EthMethod.PrepareUserOperation}`,
|
57
|
-
`${EthMethod.PatchUserOperation}`,
|
58
|
-
`${EthMethod.SignUserOperation}`,
|
59
|
-
])),
|
21
|
+
exports.BaseKeyringAccountStruct = (0, superstruct_2.object)({
|
60
22
|
/**
|
61
23
|
* Account type.
|
62
24
|
*/
|
63
|
-
type: (0, superstruct_1.enums)([
|
25
|
+
type: (0, superstruct_1.enums)([
|
26
|
+
`${eth_1.EthAccountType.Eoa}`,
|
27
|
+
`${eth_1.EthAccountType.Erc4337}`,
|
28
|
+
`${btc_1.BtcAccountType.P2wpkh}`,
|
29
|
+
]),
|
30
|
+
});
|
31
|
+
/**
|
32
|
+
* Account as a `superstruct.object`.
|
33
|
+
*
|
34
|
+
* See {@link KeyringAccount}.
|
35
|
+
*/
|
36
|
+
exports.KeyringAccountStruct = (0, superstruct_1.define)(
|
37
|
+
// We do use a custom `define` for this type to avoid having to use a `union` since error
|
38
|
+
// messages are a bit confusing.
|
39
|
+
//
|
40
|
+
// Doing manual validation allows us to use the "concrete" type of each supported acounts giving
|
41
|
+
// use a much nicer message from `superstruct`.
|
42
|
+
'KeyringAccount', (value) => {
|
43
|
+
// This will also raise if `value` does not match any of the supported account types!
|
44
|
+
const account = (0, superstruct_1.mask)(value, exports.BaseKeyringAccountStruct);
|
45
|
+
// At this point, we know that `value.type` can be used as an index for `KeyringAccountStructs`
|
46
|
+
const [error] = (0, superstruct_1.validate)(value, exports.KeyringAccountStructs[account.type]);
|
47
|
+
return error ?? true;
|
64
48
|
});
|
65
49
|
exports.KeyringRequestStruct = (0, superstruct_2.object)({
|
66
50
|
/**
|
package/dist/api.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"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","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, enums, literal, record, string, union } from 'superstruct';\n\nimport { exactOptional, object } from './superstruct';\nimport { UuidStruct } from './utils';\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n // General signing methods\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n // ERC-4337 methods\n PrepareUserOperation = 'eth_prepareUserOperation',\n PatchUserOperation = 'eth_patchUserOperation',\n SignUserOperation = 'eth_signUserOperation',\n}\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Erc4337 = 'eip155:erc4337',\n}\n\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n `${EthMethod.PrepareUserOperation}`,\n `${EthMethod.PatchUserOperation}`,\n `${EthMethod.SignUserOperation}`,\n ]),\n ),\n\n /**\n * Account type.\n */\n type: enums([`${EthAccountType.Eoa}`, `${EthAccountType.Erc4337}`]),\n});\n\n/**\n * Account object.\n *\n * Represents an account with its properties and capabilities.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n\nexport const KeyringRequestStruct = object({\n /**\n * Keyring request ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Inner request sent by the client application.\n */\n request: object({\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n }),\n});\n\n/**\n * Keyring request.\n *\n * Represents a request made to the keyring for account-related operations.\n */\nexport type KeyringRequest = Infer<typeof KeyringRequestStruct>;\n\nexport const KeyringAccountDataStruct = record(string(), JsonStruct);\n\n/**\n * Response to a call to `exportAccount`.\n *\n * The exact response depends on the keyring implementation.\n */\nexport type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;\n\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: exactOptional(\n object({\n message: exactOptional(string()),\n url: exactOptional(string()),\n }),\n ),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL and message\n * to be shown to the user. The user can choose to follow the link or cancel\n * the request. The main use case for this is to redirect the user to the snap\n * dapp to review the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with optional, keyring-defined, account options.\n *\n * @param options - Keyring-defined options for the account (optional).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests?(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest?(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<KeyringResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest?(id: string): Promise<void>;\n};\n"]}
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAE7C,6CAUqB;AAIrB,+BAA+D;AAE/D,+BAIe;AACf,+CAAsD;AACtD,mCAAqC;AASrC;;GAEG;AACU,QAAA,qBAAqB,GAG9B;IACF,CAAC,GAAG,oBAAc,CAAC,GAAG,EAAE,CAAC,EAAE,yBAAmB;IAC9C,CAAC,GAAG,oBAAc,CAAC,OAAO,EAAE,CAAC,EAAE,6BAAuB;IACtD,CAAC,GAAG,oBAAc,CAAC,MAAM,EAAE,CAAC,EAAE,4BAAsB;CACrD,CAAC;AAEF;;GAEG;AACU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC;IAC7C;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC;QACV,GAAG,oBAAc,CAAC,GAAG,EAAE;QACvB,GAAG,oBAAc,CAAC,OAAO,EAAE;QAC3B,GAAG,oBAAc,CAAC,MAAM,EAAE;KAC3B,CAAC;CACH,CAAC,CAAC;AAEH;;;;GAIG;AACU,QAAA,oBAAoB,GAAG,IAAA,oBAAM;AACxC,yFAAyF;AACzF,gCAAgC;AAChC,EAAE;AACF,gGAAgG;AAChG,+CAA+C;AAC/C,gBAAgB,EAChB,CAAC,KAAc,EAAE,EAAE;IACjB,qFAAqF;IACrF,MAAM,OAAO,GAAG,IAAA,kBAAI,EAAC,KAAK,EAAE,gCAAwB,CAAC,CAAC;IAEtD,+FAA+F;IAC/F,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAQ,EACtB,KAAK,EACL,6BAAqB,CAAC,OAAO,CAAC,IAAI,CAAW,CAC9C,CAAC;IAEF,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC,CACF,CAAC;AASW,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,KAAK,EAAE,IAAA,oBAAM,GAAE;IAEf;;OAEG;IACH,OAAO,EAAE,kBAAU;IAEnB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC;QACd,MAAM,EAAE,IAAA,oBAAM,GAAE;QAChB,MAAM,EAAE,IAAA,2BAAa,EACnB,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC,CACzD;KACF,CAAC;CACH,CAAC,CAAC;AASU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC;AASxD,QAAA,qBAAqB,GAAG,IAAA,mBAAK,EAAC;IACzC,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC;QAEtB;;;;;;WAMG;QACH,QAAQ,EAAE,IAAA,2BAAa,EACrB,IAAA,oBAAM,EAAC;YACL,OAAO,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;YAChC,GAAG,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;SAC7B,CAAC,CACH;KACF,CAAC;IACF,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n enums,\n array,\n define,\n validate,\n literal,\n record,\n string,\n union,\n mask,\n} from 'superstruct';\n\nimport type { StaticAssertAbstractAccount } from './base-types';\nimport type { BtcP2wpkhAccount } from './btc';\nimport { BtcP2wpkhAccountStruct, BtcAccountType } from './btc';\nimport type { EthEoaAccount, EthErc4337Account } from './eth';\nimport {\n EthEoaAccountStruct,\n EthErc4337AccountStruct,\n EthAccountType,\n} from './eth';\nimport { exactOptional, object } from './superstruct';\nimport { UuidStruct } from './utils';\n\n/**\n * Type of supported accounts.\n */\nexport type KeyringAccounts = StaticAssertAbstractAccount<\n EthEoaAccount | EthErc4337Account | BtcP2wpkhAccount\n>;\n\n/**\n * Mapping between account types and their matching `superstruct` schema.\n */\nexport const KeyringAccountStructs: Record<\n string,\n Struct<EthEoaAccount> | Struct<EthErc4337Account> | Struct<BtcP2wpkhAccount>\n> = {\n [`${EthAccountType.Eoa}`]: EthEoaAccountStruct,\n [`${EthAccountType.Erc4337}`]: EthErc4337AccountStruct,\n [`${BtcAccountType.P2wpkh}`]: BtcP2wpkhAccountStruct,\n};\n\n/**\n * Base type for `KeyringAccount` as a `superstruct.object`.\n */\nexport const BaseKeyringAccountStruct = object({\n /**\n * Account type.\n */\n type: enums([\n `${EthAccountType.Eoa}`,\n `${EthAccountType.Erc4337}`,\n `${BtcAccountType.P2wpkh}`,\n ]),\n});\n\n/**\n * Account as a `superstruct.object`.\n *\n * See {@link KeyringAccount}.\n */\nexport const KeyringAccountStruct = define<KeyringAccounts>(\n // We do use a custom `define` for this type to avoid having to use a `union` since error\n // messages are a bit confusing.\n //\n // Doing manual validation allows us to use the \"concrete\" type of each supported acounts giving\n // use a much nicer message from `superstruct`.\n 'KeyringAccount',\n (value: unknown) => {\n // This will also raise if `value` does not match any of the supported account types!\n const account = mask(value, BaseKeyringAccountStruct);\n\n // At this point, we know that `value.type` can be used as an index for `KeyringAccountStructs`\n const [error] = validate(\n value,\n KeyringAccountStructs[account.type] as Struct,\n );\n\n return error ?? true;\n },\n);\n\n/**\n * Account object.\n *\n * Represents an account with its properties and capabilities.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n\nexport const KeyringRequestStruct = object({\n /**\n * Keyring request ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Inner request sent by the client application.\n */\n request: object({\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n }),\n});\n\n/**\n * Keyring request.\n *\n * Represents a request made to the keyring for account-related operations.\n */\nexport type KeyringRequest = Infer<typeof KeyringRequestStruct>;\n\nexport const KeyringAccountDataStruct = record(string(), JsonStruct);\n\n/**\n * Response to a call to `exportAccount`.\n *\n * The exact response depends on the keyring implementation.\n */\nexport type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;\n\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: exactOptional(\n object({\n message: exactOptional(string()),\n url: exactOptional(string()),\n }),\n ),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL and message\n * to be shown to the user. The user can choose to follow the link or cancel\n * the request. The main use case for this is to redirect the user to the snap\n * dapp to review the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with optional, keyring-defined, account options.\n *\n * @param options - Keyring-defined options for the account (optional).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests?(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest?(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<KeyringResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest?(id: string): Promise<void>;\n};\n"]}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import type { Json } from '@metamask/utils';
|
2
|
+
/**
|
3
|
+
* Base type for any account. This type must be composed and extended to add a `methods`
|
4
|
+
* and `type` fields.
|
5
|
+
*
|
6
|
+
* NOTE: This type isn't a `superstruct.object` as it is used to compose other objects. See
|
7
|
+
* {@link BaseAccountStruct}.
|
8
|
+
*/
|
9
|
+
export declare const BaseAccount: {
|
10
|
+
/**
|
11
|
+
* Account ID (UUIDv4).
|
12
|
+
*/
|
13
|
+
id: import("superstruct").Struct<string, null>;
|
14
|
+
/**
|
15
|
+
* Account address or next receive address (UTXO).
|
16
|
+
*/
|
17
|
+
address: import("superstruct").Struct<string, null>;
|
18
|
+
/**
|
19
|
+
* Keyring-dependent account options.
|
20
|
+
*/
|
21
|
+
options: import("superstruct").Struct<Record<string, Json>, null>;
|
22
|
+
};
|
23
|
+
/**
|
24
|
+
* Base type for any account as a `superstruct.object`.
|
25
|
+
*/
|
26
|
+
export declare const BaseAccountStruct: import("superstruct").Struct<{
|
27
|
+
id: string;
|
28
|
+
address: string;
|
29
|
+
options: Record<string, Json>;
|
30
|
+
}, {
|
31
|
+
/**
|
32
|
+
* Account ID (UUIDv4).
|
33
|
+
*/
|
34
|
+
id: import("superstruct").Struct<string, null>;
|
35
|
+
/**
|
36
|
+
* Account address or next receive address (UTXO).
|
37
|
+
*/
|
38
|
+
address: import("superstruct").Struct<string, null>;
|
39
|
+
/**
|
40
|
+
* Keyring-dependent account options.
|
41
|
+
*/
|
42
|
+
options: import("superstruct").Struct<Record<string, Json>, null>;
|
43
|
+
}>;
|
44
|
+
/**
|
45
|
+
* Abstract struct that is used to match every supported account type. Making sure their type
|
46
|
+
* definition do not diverge from each others.
|
47
|
+
*
|
48
|
+
* NOTE: This type is using "primitive types" such as `string` to not contrain any real account
|
49
|
+
* type. It's up to those types to use more restrictions on their type definition.
|
50
|
+
*/
|
51
|
+
export declare type AbstractAccount = {
|
52
|
+
id: string;
|
53
|
+
address: string;
|
54
|
+
options: Record<string, Json>;
|
55
|
+
type: string;
|
56
|
+
methods: string[];
|
57
|
+
};
|
58
|
+
/**
|
59
|
+
* Type helper to make sure `Type` is "equal to" `AbstractAccount`, asserting that `Type` (an account
|
60
|
+
* type actually) never diverges from other account types.
|
61
|
+
*/
|
62
|
+
export declare type StaticAssertAbstractAccount<Type extends AbstractAccount> = Type;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BaseAccountStruct = exports.BaseAccount = void 0;
|
4
|
+
const utils_1 = require("@metamask/utils");
|
5
|
+
const superstruct_1 = require("superstruct");
|
6
|
+
const utils_2 = require("./utils");
|
7
|
+
/**
|
8
|
+
* Base type for any account. This type must be composed and extended to add a `methods`
|
9
|
+
* and `type` fields.
|
10
|
+
*
|
11
|
+
* NOTE: This type isn't a `superstruct.object` as it is used to compose other objects. See
|
12
|
+
* {@link BaseAccountStruct}.
|
13
|
+
*/
|
14
|
+
exports.BaseAccount = {
|
15
|
+
/**
|
16
|
+
* Account ID (UUIDv4).
|
17
|
+
*/
|
18
|
+
id: utils_2.UuidStruct,
|
19
|
+
/**
|
20
|
+
* Account address or next receive address (UTXO).
|
21
|
+
*/
|
22
|
+
address: (0, superstruct_1.string)(),
|
23
|
+
/**
|
24
|
+
* Keyring-dependent account options.
|
25
|
+
*/
|
26
|
+
options: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
|
27
|
+
};
|
28
|
+
/**
|
29
|
+
* Base type for any account as a `superstruct.object`.
|
30
|
+
*/
|
31
|
+
exports.BaseAccountStruct = (0, superstruct_1.object)(exports.BaseAccount);
|
32
|
+
//# sourceMappingURL=base-types.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"base-types.js","sourceRoot":"","sources":["../src/base-types.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAC7C,6CAAqD;AAErD,mCAAqC;AAErC;;;;;;GAMG;AACU,QAAA,WAAW,GAAG;IACzB;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,GAAE;IAEjB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;CACtC,CAAC;AAEF;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,oBAAM,EAAC,mBAAW,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport { object, record, string } from 'superstruct';\n\nimport { UuidStruct } from './utils';\n\n/**\n * Base type for any account. This type must be composed and extended to add a `methods`\n * and `type` fields.\n *\n * NOTE: This type isn't a `superstruct.object` as it is used to compose other objects. See\n * {@link BaseAccountStruct}.\n */\nexport const BaseAccount = {\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: record(string(), JsonStruct),\n};\n\n/**\n * Base type for any account as a `superstruct.object`.\n */\nexport const BaseAccountStruct = object(BaseAccount);\n\n/**\n * Abstract struct that is used to match every supported account type. Making sure their type\n * definition do not diverge from each others.\n *\n * NOTE: This type is using \"primitive types\" such as `string` to not contrain any real account\n * type. It's up to those types to use more restrictions on their type definition.\n */\nexport type AbstractAccount = {\n id: string;\n address: string;\n options: Record<string, Json>;\n type: string;\n methods: string[];\n};\n\n/**\n * Type helper to make sure `Type` is \"equal to\" `AbstractAccount`, asserting that `Type` (an account\n * type actually) never diverges from other account types.\n */\nexport type StaticAssertAbstractAccount<Type extends AbstractAccount> = Type;\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './types';
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./types"), exports);
|
18
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB","sourcesContent":["export * from './types';\n"]}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import type { Infer } from 'superstruct';
|
2
|
+
export declare const BtcP2wpkhAddressStruct: import("superstruct").Struct<string, null>;
|
3
|
+
/**
|
4
|
+
* Supported Bitcoin methods.
|
5
|
+
*/
|
6
|
+
export declare enum BtcMethod {
|
7
|
+
SendMany = "btc_sendmany"
|
8
|
+
}
|
9
|
+
/**
|
10
|
+
* Supported Bitcoin account types.
|
11
|
+
*/
|
12
|
+
export declare enum BtcAccountType {
|
13
|
+
P2wpkh = "bip122:p2wpkh"
|
14
|
+
}
|
15
|
+
export declare const BtcP2wpkhAccountStruct: import("superstruct").Struct<{
|
16
|
+
type: "bip122:p2wpkh";
|
17
|
+
id: string;
|
18
|
+
address: string;
|
19
|
+
options: Record<string, import("@metamask/utils").Json>;
|
20
|
+
methods: "btc_sendmany"[];
|
21
|
+
}, {
|
22
|
+
/**
|
23
|
+
* Account type.
|
24
|
+
*/
|
25
|
+
type: import("superstruct").Struct<"bip122:p2wpkh", "bip122:p2wpkh">;
|
26
|
+
/**
|
27
|
+
* Account supported methods.
|
28
|
+
*/
|
29
|
+
methods: import("superstruct").Struct<"btc_sendmany"[], import("superstruct").Struct<"btc_sendmany", {
|
30
|
+
btc_sendmany: "btc_sendmany";
|
31
|
+
}>>;
|
32
|
+
id: import("superstruct").Struct<string, null>;
|
33
|
+
address: import("superstruct").Struct<string, null>;
|
34
|
+
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
35
|
+
}>;
|
36
|
+
export declare type BtcP2wpkhAccount = Infer<typeof BtcP2wpkhAccountStruct>;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BtcP2wpkhAccountStruct = exports.BtcAccountType = exports.BtcMethod = exports.BtcP2wpkhAddressStruct = void 0;
|
4
|
+
const bech32_1 = require("bech32");
|
5
|
+
const superstruct_1 = require("superstruct");
|
6
|
+
const base_types_1 = require("../base-types");
|
7
|
+
exports.BtcP2wpkhAddressStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'BtcP2wpkhAddressStruct', (address) => {
|
8
|
+
try {
|
9
|
+
bech32_1.bech32.decode(address);
|
10
|
+
}
|
11
|
+
catch (error) {
|
12
|
+
return new Error(`Could not decode P2WPKH address: ${error.message}`);
|
13
|
+
}
|
14
|
+
return true;
|
15
|
+
});
|
16
|
+
/**
|
17
|
+
* Supported Bitcoin methods.
|
18
|
+
*/
|
19
|
+
var BtcMethod;
|
20
|
+
(function (BtcMethod) {
|
21
|
+
// General transaction methods
|
22
|
+
BtcMethod["SendMany"] = "btc_sendmany";
|
23
|
+
})(BtcMethod = exports.BtcMethod || (exports.BtcMethod = {}));
|
24
|
+
/**
|
25
|
+
* Supported Bitcoin account types.
|
26
|
+
*/
|
27
|
+
var BtcAccountType;
|
28
|
+
(function (BtcAccountType) {
|
29
|
+
BtcAccountType["P2wpkh"] = "bip122:p2wpkh";
|
30
|
+
})(BtcAccountType = exports.BtcAccountType || (exports.BtcAccountType = {}));
|
31
|
+
exports.BtcP2wpkhAccountStruct = (0, superstruct_1.object)({
|
32
|
+
...base_types_1.BaseAccount,
|
33
|
+
/**
|
34
|
+
* Account type.
|
35
|
+
*/
|
36
|
+
type: (0, superstruct_1.literal)(`${BtcAccountType.P2wpkh}`),
|
37
|
+
/**
|
38
|
+
* Account supported methods.
|
39
|
+
*/
|
40
|
+
methods: (0, superstruct_1.array)((0, superstruct_1.enums)([`${BtcMethod.SendMany}`])),
|
41
|
+
});
|
42
|
+
//# sourceMappingURL=types.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,6CAA4E;AAE5E,8CAA4C;AAE/B,QAAA,sBAAsB,GAAG,IAAA,oBAAM,EAC1C,IAAA,oBAAM,GAAE,EACR,wBAAwB,EACxB,CAAC,OAAe,EAAE,EAAE;IAClB,IAAI;QACF,eAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;KACxB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,IAAI,KAAK,CACd,oCAAqC,KAAe,CAAC,OAAO,EAAE,CAC/D,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF;;GAEG;AACH,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,8BAA8B;IAC9B,sCAAyB,CAAA;AAC3B,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB;AAED;;GAEG;AACH,IAAY,cAEX;AAFD,WAAY,cAAc;IACxB,0CAAwB,CAAA;AAC1B,CAAC,EAFW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAEzB;AAEY,QAAA,sBAAsB,GAAG,IAAA,oBAAM,EAAC;IAC3C,GAAG,wBAAW;IAEd;;OAEG;IACH,IAAI,EAAE,IAAA,qBAAO,EAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC;IAEzC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC,IAAA,mBAAK,EAAC,CAAC,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;CACjD,CAAC,CAAC","sourcesContent":["import { bech32 } from 'bech32';\nimport type { Infer } from 'superstruct';\nimport { object, string, array, enums, literal, refine } from 'superstruct';\n\nimport { BaseAccount } from '../base-types';\n\nexport const BtcP2wpkhAddressStruct = refine(\n string(),\n 'BtcP2wpkhAddressStruct',\n (address: string) => {\n try {\n bech32.decode(address);\n } catch (error) {\n return new Error(\n `Could not decode P2WPKH address: ${(error as Error).message}`,\n );\n }\n return true;\n },\n);\n\n/**\n * Supported Bitcoin methods.\n */\nexport enum BtcMethod {\n // General transaction methods\n SendMany = 'btc_sendmany',\n}\n\n/**\n * Supported Bitcoin account types.\n */\nexport enum BtcAccountType {\n P2wpkh = 'bip122:p2wpkh',\n}\n\nexport const BtcP2wpkhAccountStruct = object({\n ...BaseAccount,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2wpkh}`),\n\n /**\n * Account supported methods.\n */\n methods: array(enums([`${BtcMethod.SendMany}`])),\n});\n\nexport type BtcP2wpkhAccount = Infer<typeof BtcP2wpkhAccountStruct>;\n"]}
|
@@ -35,8 +35,8 @@ export declare type EthUserOperation = Infer<typeof EthUserOperationStruct>;
|
|
35
35
|
*/
|
36
36
|
export declare const EthBaseTransactionStruct: import("superstruct").Struct<{
|
37
37
|
value: string;
|
38
|
-
data: string;
|
39
38
|
to: string;
|
39
|
+
data: string;
|
40
40
|
}, {
|
41
41
|
/**
|
42
42
|
* Address of the transaction recipient.
|
package/dist/eth/index.d.ts
CHANGED
package/dist/eth/index.js
CHANGED
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./erc4337"), exports);
|
18
18
|
__exportStar(require("./types"), exports);
|
19
|
+
__exportStar(require("./utils"), exports);
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/dist/eth/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB","sourcesContent":["export * from './erc4337';\nexport * from './types';\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB","sourcesContent":["export * from './erc4337';\nexport * from './types';\nexport * from './utils';\n"]}
|