@metamask/keyring-api 17.4.0 → 17.6.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/api/account.cjs +6 -0
- package/dist/api/account.cjs.map +1 -1
- package/dist/api/account.d.cts +10 -4
- package/dist/api/account.d.cts.map +1 -1
- package/dist/api/account.d.mts +10 -4
- package/dist/api/account.d.mts.map +1 -1
- package/dist/api/account.mjs +6 -0
- package/dist/api/account.mjs.map +1 -1
- package/dist/api/transaction.cjs +18 -0
- package/dist/api/transaction.cjs.map +1 -1
- package/dist/api/transaction.d.cts +28 -7
- package/dist/api/transaction.d.cts.map +1 -1
- package/dist/api/transaction.d.mts +28 -7
- package/dist/api/transaction.d.mts.map +1 -1
- package/dist/api/transaction.mjs +18 -0
- package/dist/api/transaction.mjs.map +1 -1
- package/dist/btc/types.cjs +63 -14
- package/dist/btc/types.cjs.map +1 -1
- package/dist/btc/types.d.cts +95 -4
- package/dist/btc/types.d.cts.map +1 -1
- package/dist/btc/types.d.mts +95 -4
- package/dist/btc/types.d.mts.map +1 -1
- package/dist/btc/types.mjs +64 -15
- package/dist/btc/types.mjs.map +1 -1
- package/dist/events.d.cts +17 -11
- package/dist/events.d.cts.map +1 -1
- package/dist/events.d.mts +17 -11
- package/dist/events.d.mts.map +1 -1
- package/dist/rpc.d.cts +30 -15
- package/dist/rpc.d.cts.map +1 -1
- package/dist/rpc.d.mts +30 -15
- package/dist/rpc.d.mts.map +1 -1
- package/package.json +2 -2
package/dist/btc/types.cjs
CHANGED
@@ -1,18 +1,33 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.BtcP2wpkhAccountStruct = exports.BtcMethod = exports.BtcP2wpkhAddressStruct = void 0;
|
3
|
+
exports.BtcP2trAccountStruct = exports.BtcP2wpkhAccountStruct = exports.BtcP2shAccountStruct = exports.BtcP2pkhAccountStruct = exports.BtcMethod = exports.BtcP2trAddressStruct = exports.BtcP2wpkhAddressStruct = exports.BtcP2shAddressStruct = exports.BtcP2pkhAddressStruct = void 0;
|
4
4
|
const keyring_utils_1 = require("@metamask/keyring-utils");
|
5
5
|
const superstruct_1 = require("@metamask/superstruct");
|
6
|
-
const
|
6
|
+
const bitcoin_address_validation_1 = require("bitcoin-address-validation");
|
7
7
|
const api_1 = require("../api/index.cjs");
|
8
|
-
|
8
|
+
const validateAddress = (address, type) => {
|
9
9
|
try {
|
10
|
-
|
10
|
+
const addressInfo = (0, bitcoin_address_validation_1.getAddressInfo)(address);
|
11
|
+
if (addressInfo.type === type) {
|
12
|
+
return true;
|
13
|
+
}
|
14
|
+
return new Error(`Invalid ${type} address`);
|
11
15
|
}
|
12
16
|
catch (error) {
|
13
|
-
return new Error(`
|
17
|
+
return new Error(`Failed to decode ${type} address: ${error.message}`);
|
14
18
|
}
|
15
|
-
|
19
|
+
};
|
20
|
+
exports.BtcP2pkhAddressStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'BtcP2pkhAddressStruct', (address) => {
|
21
|
+
return validateAddress(address, bitcoin_address_validation_1.AddressType.p2pkh);
|
22
|
+
});
|
23
|
+
exports.BtcP2shAddressStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'BtcP2shAddressStruct', (address) => {
|
24
|
+
return validateAddress(address, bitcoin_address_validation_1.AddressType.p2sh);
|
25
|
+
});
|
26
|
+
exports.BtcP2wpkhAddressStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'BtcP2wpkhAddressStruct', (address) => {
|
27
|
+
return validateAddress(address, bitcoin_address_validation_1.AddressType.p2wpkh);
|
28
|
+
});
|
29
|
+
exports.BtcP2trAddressStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'BtcP2trAddressStruct', (address) => {
|
30
|
+
return validateAddress(address, bitcoin_address_validation_1.AddressType.p2tr);
|
16
31
|
});
|
17
32
|
/**
|
18
33
|
* Supported Bitcoin methods.
|
@@ -22,25 +37,59 @@ var BtcMethod;
|
|
22
37
|
// General transaction methods
|
23
38
|
BtcMethod["SendBitcoin"] = "sendBitcoin";
|
24
39
|
})(BtcMethod || (exports.BtcMethod = BtcMethod = {}));
|
25
|
-
|
40
|
+
const BtcAccountStruct = (0, keyring_utils_1.object)({
|
26
41
|
...api_1.KeyringAccountStruct.schema,
|
27
42
|
/**
|
28
|
-
* Account
|
43
|
+
* Account supported scopes (CAIP-2 chain ID).
|
44
|
+
*/
|
45
|
+
scopes: (0, superstruct_1.nonempty)((0, superstruct_1.array)(api_1.CaipChainIdStruct)),
|
46
|
+
/**
|
47
|
+
* Account supported methods.
|
48
|
+
*/
|
49
|
+
methods: (0, superstruct_1.array)((0, superstruct_1.enums)([`${BtcMethod.SendBitcoin}`])),
|
50
|
+
});
|
51
|
+
exports.BtcP2pkhAccountStruct = (0, keyring_utils_1.object)({
|
52
|
+
...BtcAccountStruct.schema,
|
53
|
+
/**
|
54
|
+
* Account P2PKH address.
|
55
|
+
*/
|
56
|
+
address: exports.BtcP2pkhAddressStruct,
|
57
|
+
/**
|
58
|
+
* Account type.
|
59
|
+
*/
|
60
|
+
type: (0, superstruct_1.literal)(`${api_1.BtcAccountType.P2pkh}`),
|
61
|
+
});
|
62
|
+
exports.BtcP2shAccountStruct = (0, keyring_utils_1.object)({
|
63
|
+
...BtcAccountStruct.schema,
|
64
|
+
/**
|
65
|
+
* Account P2SH address.
|
66
|
+
*/
|
67
|
+
address: exports.BtcP2shAddressStruct,
|
68
|
+
/**
|
69
|
+
* Account type.
|
70
|
+
*/
|
71
|
+
type: (0, superstruct_1.literal)(`${api_1.BtcAccountType.P2sh}`),
|
72
|
+
});
|
73
|
+
exports.BtcP2wpkhAccountStruct = (0, keyring_utils_1.object)({
|
74
|
+
...BtcAccountStruct.schema,
|
75
|
+
/**
|
76
|
+
* Account P2WPKH address.
|
29
77
|
*/
|
30
78
|
address: exports.BtcP2wpkhAddressStruct,
|
31
79
|
/**
|
32
80
|
* Account type.
|
33
81
|
*/
|
34
82
|
type: (0, superstruct_1.literal)(`${api_1.BtcAccountType.P2wpkh}`),
|
83
|
+
});
|
84
|
+
exports.BtcP2trAccountStruct = (0, keyring_utils_1.object)({
|
85
|
+
...BtcAccountStruct.schema,
|
35
86
|
/**
|
36
|
-
* Account
|
37
|
-
*
|
38
|
-
* NOTE: We consider a Bitcoin address to be valid on only 1 network at time.
|
87
|
+
* Account P2TR address.
|
39
88
|
*/
|
40
|
-
|
89
|
+
address: exports.BtcP2trAddressStruct,
|
41
90
|
/**
|
42
|
-
* Account
|
91
|
+
* Account type.
|
43
92
|
*/
|
44
|
-
|
93
|
+
type: (0, superstruct_1.literal)(`${api_1.BtcAccountType.P2tr}`),
|
45
94
|
});
|
46
95
|
//# sourceMappingURL=types.cjs.map
|
package/dist/btc/types.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":";;;AAAA,2DAAiD;AAEjD,uDAO+B;AAC/B,
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":";;;AAAA,2DAAiD;AAEjD,uDAO+B;AAC/B,2EAAyE;AAEzE,0CAIgB;AAEhB,MAAM,eAAe,GAAG,CACtB,OAAe,EACf,IAAiB,EACA,EAAE;IACnB,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,IAAA,2CAAc,EAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,WAAW,IAAI,UAAU,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAI,KAAK,CACd,oBAAoB,IAAI,aAAc,KAAe,CAAC,OAAO,EAAE,CAChE,CAAC;IACJ,CAAC;AACH,CAAC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CAAC,CAAC;AAEU,QAAA,qBAAqB,GAAG,IAAA,sBAAM,EAAC;IAC1C,GAAG,gBAAgB,CAAC,MAAM;IAE1B;;OAEG;IACH,OAAO,EAAE,6BAAqB;IAE9B;;OAEG;IACH,IAAI,EAAE,IAAA,qBAAO,EAAC,GAAG,oBAAc,CAAC,KAAK,EAAE,CAAC;CACzC,CAAC,CAAC;AAEU,QAAA,oBAAoB,GAAG,IAAA,sBAAM,EAAC;IACzC,GAAG,gBAAgB,CAAC,MAAM;IAE1B;;OAEG;IACH,OAAO,EAAE,4BAAoB;IAE7B;;OAEG;IACH,IAAI,EAAE,IAAA,qBAAO,EAAC,GAAG,oBAAc,CAAC,IAAI,EAAE,CAAC;CACxC,CAAC,CAAC;AAEU,QAAA,sBAAsB,GAAG,IAAA,sBAAM,EAAC;IAC3C,GAAG,gBAAgB,CAAC,MAAM;IAE1B;;OAEG;IACH,OAAO,EAAE,8BAAsB;IAE/B;;OAEG;IACH,IAAI,EAAE,IAAA,qBAAO,EAAC,GAAG,oBAAc,CAAC,MAAM,EAAE,CAAC;CAC1C,CAAC,CAAC;AAEU,QAAA,oBAAoB,GAAG,IAAA,sBAAM,EAAC;IACzC,GAAG,gBAAgB,CAAC,MAAM;IAE1B;;OAEG;IACH,OAAO,EAAE,4BAAoB;IAE7B;;OAEG;IACH,IAAI,EAAE,IAAA,qBAAO,EAAC,GAAG,oBAAc,CAAC,IAAI,EAAE,CAAC;CACxC,CAAC,CAAC","sourcesContent":["import { object } from '@metamask/keyring-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n string,\n array,\n enums,\n refine,\n literal,\n nonempty,\n} from '@metamask/superstruct';\nimport { AddressType, getAddressInfo } from 'bitcoin-address-validation';\n\nimport {\n BtcAccountType,\n CaipChainIdStruct,\n KeyringAccountStruct,\n} from '../api';\n\nconst validateAddress = (\n address: string,\n type: AddressType,\n): boolean | Error => {\n try {\n const addressInfo = getAddressInfo(address);\n if (addressInfo.type === type) {\n return true;\n }\n return new Error(`Invalid ${type} address`);\n } catch (error) {\n return new Error(\n `Failed to decode ${type} address: ${(error as Error).message}`,\n );\n }\n};\n\nexport const BtcP2pkhAddressStruct = refine(\n string(),\n 'BtcP2pkhAddressStruct',\n (address: string) => {\n return validateAddress(address, AddressType.p2pkh);\n },\n);\n\nexport const BtcP2shAddressStruct = refine(\n string(),\n 'BtcP2shAddressStruct',\n (address: string) => {\n return validateAddress(address, AddressType.p2sh);\n },\n);\n\nexport const BtcP2wpkhAddressStruct = refine(\n string(),\n 'BtcP2wpkhAddressStruct',\n (address: string) => {\n return validateAddress(address, AddressType.p2wpkh);\n },\n);\n\nexport const BtcP2trAddressStruct = refine(\n string(),\n 'BtcP2trAddressStruct',\n (address: string) => {\n return validateAddress(address, AddressType.p2tr);\n },\n);\n\n/**\n * Supported Bitcoin methods.\n */\nexport enum BtcMethod {\n // General transaction methods\n SendBitcoin = 'sendBitcoin',\n}\n\nconst BtcAccountStruct = object({\n ...KeyringAccountStruct.schema,\n\n /**\n * Account supported scopes (CAIP-2 chain ID).\n */\n scopes: nonempty(array(CaipChainIdStruct)),\n\n /**\n * Account supported methods.\n */\n methods: array(enums([`${BtcMethod.SendBitcoin}`])),\n});\n\nexport const BtcP2pkhAccountStruct = object({\n ...BtcAccountStruct.schema,\n\n /**\n * Account P2PKH address.\n */\n address: BtcP2pkhAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2pkh}`),\n});\n\nexport const BtcP2shAccountStruct = object({\n ...BtcAccountStruct.schema,\n\n /**\n * Account P2SH address.\n */\n address: BtcP2shAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2sh}`),\n});\n\nexport const BtcP2wpkhAccountStruct = object({\n ...BtcAccountStruct.schema,\n\n /**\n * Account P2WPKH address.\n */\n address: BtcP2wpkhAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2wpkh}`),\n});\n\nexport const BtcP2trAccountStruct = object({\n ...BtcAccountStruct.schema,\n\n /**\n * Account P2TR address.\n */\n address: BtcP2trAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2tr}`),\n});\n\nexport type BtcP2pkhAccount = Infer<typeof BtcP2pkhAccountStruct>;\nexport type BtcP2shAccount = Infer<typeof BtcP2shAccountStruct>;\nexport type BtcP2wpkhAccount = Infer<typeof BtcP2wpkhAccountStruct>;\nexport type BtcP2trAccount = Infer<typeof BtcP2trAccountStruct>;\n"]}
|
package/dist/btc/types.d.cts
CHANGED
@@ -1,11 +1,72 @@
|
|
1
1
|
import type { Infer } from "@metamask/superstruct";
|
2
|
+
export declare const BtcP2pkhAddressStruct: import("@metamask/superstruct").Struct<string, null>;
|
3
|
+
export declare const BtcP2shAddressStruct: import("@metamask/superstruct").Struct<string, null>;
|
2
4
|
export declare const BtcP2wpkhAddressStruct: import("@metamask/superstruct").Struct<string, null>;
|
5
|
+
export declare const BtcP2trAddressStruct: import("@metamask/superstruct").Struct<string, null>;
|
3
6
|
/**
|
4
7
|
* Supported Bitcoin methods.
|
5
8
|
*/
|
6
9
|
export declare enum BtcMethod {
|
7
10
|
SendBitcoin = "sendBitcoin"
|
8
11
|
}
|
12
|
+
export declare const BtcP2pkhAccountStruct: import("@metamask/superstruct").Struct<{
|
13
|
+
type: "bip122:p2pkh";
|
14
|
+
id: string;
|
15
|
+
options: Record<string, import("@metamask/utils").Json>;
|
16
|
+
address: string;
|
17
|
+
scopes: `${string}:${string}`[];
|
18
|
+
methods: "sendBitcoin"[];
|
19
|
+
}, {
|
20
|
+
/**
|
21
|
+
* Account P2PKH address.
|
22
|
+
*/
|
23
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
24
|
+
/**
|
25
|
+
* Account type.
|
26
|
+
*/
|
27
|
+
type: import("@metamask/superstruct").Struct<"bip122:p2pkh", "bip122:p2pkh">;
|
28
|
+
/**
|
29
|
+
* Account supported scopes (CAIP-2 chain ID).
|
30
|
+
*/
|
31
|
+
scopes: import("@metamask/superstruct").Struct<`${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}`, null>>;
|
32
|
+
/**
|
33
|
+
* Account supported methods.
|
34
|
+
*/
|
35
|
+
methods: import("@metamask/superstruct").Struct<"sendBitcoin"[], import("@metamask/superstruct").Struct<"sendBitcoin", {
|
36
|
+
sendBitcoin: "sendBitcoin";
|
37
|
+
}>>;
|
38
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
39
|
+
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
40
|
+
}>;
|
41
|
+
export declare const BtcP2shAccountStruct: import("@metamask/superstruct").Struct<{
|
42
|
+
type: "bip122:p2sh";
|
43
|
+
id: string;
|
44
|
+
options: Record<string, import("@metamask/utils").Json>;
|
45
|
+
address: string;
|
46
|
+
scopes: `${string}:${string}`[];
|
47
|
+
methods: "sendBitcoin"[];
|
48
|
+
}, {
|
49
|
+
/**
|
50
|
+
* Account P2SH address.
|
51
|
+
*/
|
52
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
53
|
+
/**
|
54
|
+
* Account type.
|
55
|
+
*/
|
56
|
+
type: import("@metamask/superstruct").Struct<"bip122:p2sh", "bip122:p2sh">;
|
57
|
+
/**
|
58
|
+
* Account supported scopes (CAIP-2 chain ID).
|
59
|
+
*/
|
60
|
+
scopes: import("@metamask/superstruct").Struct<`${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}`, null>>;
|
61
|
+
/**
|
62
|
+
* Account supported methods.
|
63
|
+
*/
|
64
|
+
methods: import("@metamask/superstruct").Struct<"sendBitcoin"[], import("@metamask/superstruct").Struct<"sendBitcoin", {
|
65
|
+
sendBitcoin: "sendBitcoin";
|
66
|
+
}>>;
|
67
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
68
|
+
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
69
|
+
}>;
|
9
70
|
export declare const BtcP2wpkhAccountStruct: import("@metamask/superstruct").Struct<{
|
10
71
|
type: "bip122:p2wpkh";
|
11
72
|
id: string;
|
@@ -15,7 +76,7 @@ export declare const BtcP2wpkhAccountStruct: import("@metamask/superstruct").Str
|
|
15
76
|
methods: "sendBitcoin"[];
|
16
77
|
}, {
|
17
78
|
/**
|
18
|
-
* Account address.
|
79
|
+
* Account P2WPKH address.
|
19
80
|
*/
|
20
81
|
address: import("@metamask/superstruct").Struct<string, null>;
|
21
82
|
/**
|
@@ -23,9 +84,36 @@ export declare const BtcP2wpkhAccountStruct: import("@metamask/superstruct").Str
|
|
23
84
|
*/
|
24
85
|
type: import("@metamask/superstruct").Struct<"bip122:p2wpkh", "bip122:p2wpkh">;
|
25
86
|
/**
|
26
|
-
* Account supported
|
27
|
-
|
28
|
-
|
87
|
+
* Account supported scopes (CAIP-2 chain ID).
|
88
|
+
*/
|
89
|
+
scopes: import("@metamask/superstruct").Struct<`${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}`, null>>;
|
90
|
+
/**
|
91
|
+
* Account supported methods.
|
92
|
+
*/
|
93
|
+
methods: import("@metamask/superstruct").Struct<"sendBitcoin"[], import("@metamask/superstruct").Struct<"sendBitcoin", {
|
94
|
+
sendBitcoin: "sendBitcoin";
|
95
|
+
}>>;
|
96
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
97
|
+
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
98
|
+
}>;
|
99
|
+
export declare const BtcP2trAccountStruct: import("@metamask/superstruct").Struct<{
|
100
|
+
type: "bip122:p2tr";
|
101
|
+
id: string;
|
102
|
+
options: Record<string, import("@metamask/utils").Json>;
|
103
|
+
address: string;
|
104
|
+
scopes: `${string}:${string}`[];
|
105
|
+
methods: "sendBitcoin"[];
|
106
|
+
}, {
|
107
|
+
/**
|
108
|
+
* Account P2TR address.
|
109
|
+
*/
|
110
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
111
|
+
/**
|
112
|
+
* Account type.
|
113
|
+
*/
|
114
|
+
type: import("@metamask/superstruct").Struct<"bip122:p2tr", "bip122:p2tr">;
|
115
|
+
/**
|
116
|
+
* Account supported scopes (CAIP-2 chain ID).
|
29
117
|
*/
|
30
118
|
scopes: import("@metamask/superstruct").Struct<`${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}`, null>>;
|
31
119
|
/**
|
@@ -37,5 +125,8 @@ export declare const BtcP2wpkhAccountStruct: import("@metamask/superstruct").Str
|
|
37
125
|
id: import("@metamask/superstruct").Struct<string, null>;
|
38
126
|
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
39
127
|
}>;
|
128
|
+
export type BtcP2pkhAccount = Infer<typeof BtcP2pkhAccountStruct>;
|
129
|
+
export type BtcP2shAccount = Infer<typeof BtcP2shAccountStruct>;
|
40
130
|
export type BtcP2wpkhAccount = Infer<typeof BtcP2wpkhAccountStruct>;
|
131
|
+
export type BtcP2trAccount = Infer<typeof BtcP2trAccountStruct>;
|
41
132
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/btc/types.d.cts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAkCnD,eAAO,MAAM,qBAAqB,sDAMjC,CAAC;AAEF,eAAO,MAAM,oBAAoB,sDAMhC,CAAC;AAEF,eAAO,MAAM,sBAAsB,sDAMlC,CAAC;AAEF,eAAO,MAAM,oBAAoB,sDAMhC,CAAC;AAEF;;GAEG;AACH,oBAAY,SAAS;IAEnB,WAAW,gBAAgB;CAC5B;AAgBD,eAAO,MAAM,qBAAqB;;;;;;;;IAGhC;;OAEG;;IAGH;;OAEG;;IArBH;;OAEG;;IAGH;;OAEG;;;;;;EAgBH,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;IAG/B;;OAEG;;IAGH;;OAEG;;IAnCH;;OAEG;;IAGH;;OAEG;;;;;;EA8BH,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;IAGjC;;OAEG;;IAGH;;OAEG;;IAjDH;;OAEG;;IAGH;;OAEG;;;;;;EA4CH,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;IAG/B;;OAEG;;IAGH;;OAEG;;IA/DH;;OAEG;;IAGH;;OAEG;;;;;;EA0DH,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAClE,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACpE,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/dist/btc/types.d.mts
CHANGED
@@ -1,11 +1,72 @@
|
|
1
1
|
import type { Infer } from "@metamask/superstruct";
|
2
|
+
export declare const BtcP2pkhAddressStruct: import("@metamask/superstruct").Struct<string, null>;
|
3
|
+
export declare const BtcP2shAddressStruct: import("@metamask/superstruct").Struct<string, null>;
|
2
4
|
export declare const BtcP2wpkhAddressStruct: import("@metamask/superstruct").Struct<string, null>;
|
5
|
+
export declare const BtcP2trAddressStruct: import("@metamask/superstruct").Struct<string, null>;
|
3
6
|
/**
|
4
7
|
* Supported Bitcoin methods.
|
5
8
|
*/
|
6
9
|
export declare enum BtcMethod {
|
7
10
|
SendBitcoin = "sendBitcoin"
|
8
11
|
}
|
12
|
+
export declare const BtcP2pkhAccountStruct: import("@metamask/superstruct").Struct<{
|
13
|
+
type: "bip122:p2pkh";
|
14
|
+
id: string;
|
15
|
+
options: Record<string, import("@metamask/utils").Json>;
|
16
|
+
address: string;
|
17
|
+
scopes: `${string}:${string}`[];
|
18
|
+
methods: "sendBitcoin"[];
|
19
|
+
}, {
|
20
|
+
/**
|
21
|
+
* Account P2PKH address.
|
22
|
+
*/
|
23
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
24
|
+
/**
|
25
|
+
* Account type.
|
26
|
+
*/
|
27
|
+
type: import("@metamask/superstruct").Struct<"bip122:p2pkh", "bip122:p2pkh">;
|
28
|
+
/**
|
29
|
+
* Account supported scopes (CAIP-2 chain ID).
|
30
|
+
*/
|
31
|
+
scopes: import("@metamask/superstruct").Struct<`${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}`, null>>;
|
32
|
+
/**
|
33
|
+
* Account supported methods.
|
34
|
+
*/
|
35
|
+
methods: import("@metamask/superstruct").Struct<"sendBitcoin"[], import("@metamask/superstruct").Struct<"sendBitcoin", {
|
36
|
+
sendBitcoin: "sendBitcoin";
|
37
|
+
}>>;
|
38
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
39
|
+
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
40
|
+
}>;
|
41
|
+
export declare const BtcP2shAccountStruct: import("@metamask/superstruct").Struct<{
|
42
|
+
type: "bip122:p2sh";
|
43
|
+
id: string;
|
44
|
+
options: Record<string, import("@metamask/utils").Json>;
|
45
|
+
address: string;
|
46
|
+
scopes: `${string}:${string}`[];
|
47
|
+
methods: "sendBitcoin"[];
|
48
|
+
}, {
|
49
|
+
/**
|
50
|
+
* Account P2SH address.
|
51
|
+
*/
|
52
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
53
|
+
/**
|
54
|
+
* Account type.
|
55
|
+
*/
|
56
|
+
type: import("@metamask/superstruct").Struct<"bip122:p2sh", "bip122:p2sh">;
|
57
|
+
/**
|
58
|
+
* Account supported scopes (CAIP-2 chain ID).
|
59
|
+
*/
|
60
|
+
scopes: import("@metamask/superstruct").Struct<`${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}`, null>>;
|
61
|
+
/**
|
62
|
+
* Account supported methods.
|
63
|
+
*/
|
64
|
+
methods: import("@metamask/superstruct").Struct<"sendBitcoin"[], import("@metamask/superstruct").Struct<"sendBitcoin", {
|
65
|
+
sendBitcoin: "sendBitcoin";
|
66
|
+
}>>;
|
67
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
68
|
+
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
69
|
+
}>;
|
9
70
|
export declare const BtcP2wpkhAccountStruct: import("@metamask/superstruct").Struct<{
|
10
71
|
type: "bip122:p2wpkh";
|
11
72
|
id: string;
|
@@ -15,7 +76,7 @@ export declare const BtcP2wpkhAccountStruct: import("@metamask/superstruct").Str
|
|
15
76
|
methods: "sendBitcoin"[];
|
16
77
|
}, {
|
17
78
|
/**
|
18
|
-
* Account address.
|
79
|
+
* Account P2WPKH address.
|
19
80
|
*/
|
20
81
|
address: import("@metamask/superstruct").Struct<string, null>;
|
21
82
|
/**
|
@@ -23,9 +84,36 @@ export declare const BtcP2wpkhAccountStruct: import("@metamask/superstruct").Str
|
|
23
84
|
*/
|
24
85
|
type: import("@metamask/superstruct").Struct<"bip122:p2wpkh", "bip122:p2wpkh">;
|
25
86
|
/**
|
26
|
-
* Account supported
|
27
|
-
|
28
|
-
|
87
|
+
* Account supported scopes (CAIP-2 chain ID).
|
88
|
+
*/
|
89
|
+
scopes: import("@metamask/superstruct").Struct<`${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}`, null>>;
|
90
|
+
/**
|
91
|
+
* Account supported methods.
|
92
|
+
*/
|
93
|
+
methods: import("@metamask/superstruct").Struct<"sendBitcoin"[], import("@metamask/superstruct").Struct<"sendBitcoin", {
|
94
|
+
sendBitcoin: "sendBitcoin";
|
95
|
+
}>>;
|
96
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
97
|
+
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
98
|
+
}>;
|
99
|
+
export declare const BtcP2trAccountStruct: import("@metamask/superstruct").Struct<{
|
100
|
+
type: "bip122:p2tr";
|
101
|
+
id: string;
|
102
|
+
options: Record<string, import("@metamask/utils").Json>;
|
103
|
+
address: string;
|
104
|
+
scopes: `${string}:${string}`[];
|
105
|
+
methods: "sendBitcoin"[];
|
106
|
+
}, {
|
107
|
+
/**
|
108
|
+
* Account P2TR address.
|
109
|
+
*/
|
110
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
111
|
+
/**
|
112
|
+
* Account type.
|
113
|
+
*/
|
114
|
+
type: import("@metamask/superstruct").Struct<"bip122:p2tr", "bip122:p2tr">;
|
115
|
+
/**
|
116
|
+
* Account supported scopes (CAIP-2 chain ID).
|
29
117
|
*/
|
30
118
|
scopes: import("@metamask/superstruct").Struct<`${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}`, null>>;
|
31
119
|
/**
|
@@ -37,5 +125,8 @@ export declare const BtcP2wpkhAccountStruct: import("@metamask/superstruct").Str
|
|
37
125
|
id: import("@metamask/superstruct").Struct<string, null>;
|
38
126
|
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
39
127
|
}>;
|
128
|
+
export type BtcP2pkhAccount = Infer<typeof BtcP2pkhAccountStruct>;
|
129
|
+
export type BtcP2shAccount = Infer<typeof BtcP2shAccountStruct>;
|
40
130
|
export type BtcP2wpkhAccount = Infer<typeof BtcP2wpkhAccountStruct>;
|
131
|
+
export type BtcP2trAccount = Infer<typeof BtcP2trAccountStruct>;
|
41
132
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/btc/types.d.mts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAkCnD,eAAO,MAAM,qBAAqB,sDAMjC,CAAC;AAEF,eAAO,MAAM,oBAAoB,sDAMhC,CAAC;AAEF,eAAO,MAAM,sBAAsB,sDAMlC,CAAC;AAEF,eAAO,MAAM,oBAAoB,sDAMhC,CAAC;AAEF;;GAEG;AACH,oBAAY,SAAS;IAEnB,WAAW,gBAAgB;CAC5B;AAgBD,eAAO,MAAM,qBAAqB;;;;;;;;IAGhC;;OAEG;;IAGH;;OAEG;;IArBH;;OAEG;;IAGH;;OAEG;;;;;;EAgBH,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;IAG/B;;OAEG;;IAGH;;OAEG;;IAnCH;;OAEG;;IAGH;;OAEG;;;;;;EA8BH,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;IAGjC;;OAEG;;IAGH;;OAEG;;IAjDH;;OAEG;;IAGH;;OAEG;;;;;;EA4CH,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;IAG/B;;OAEG;;IAGH;;OAEG;;IA/DH;;OAEG;;IAGH;;OAEG;;;;;;EA0DH,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAClE,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACpE,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/dist/btc/types.mjs
CHANGED
@@ -1,15 +1,30 @@
|
|
1
1
|
import { object } from "@metamask/keyring-utils";
|
2
|
-
import { string, array, enums, refine, literal,
|
3
|
-
import {
|
4
|
-
import { BtcAccountType,
|
5
|
-
|
2
|
+
import { string, array, enums, refine, literal, nonempty } from "@metamask/superstruct";
|
3
|
+
import { AddressType, getAddressInfo } from "bitcoin-address-validation";
|
4
|
+
import { BtcAccountType, CaipChainIdStruct, KeyringAccountStruct } from "../api/index.mjs";
|
5
|
+
const validateAddress = (address, type) => {
|
6
6
|
try {
|
7
|
-
|
7
|
+
const addressInfo = getAddressInfo(address);
|
8
|
+
if (addressInfo.type === type) {
|
9
|
+
return true;
|
10
|
+
}
|
11
|
+
return new Error(`Invalid ${type} address`);
|
8
12
|
}
|
9
13
|
catch (error) {
|
10
|
-
return new Error(`
|
14
|
+
return new Error(`Failed to decode ${type} address: ${error.message}`);
|
11
15
|
}
|
12
|
-
|
16
|
+
};
|
17
|
+
export const BtcP2pkhAddressStruct = refine(string(), 'BtcP2pkhAddressStruct', (address) => {
|
18
|
+
return validateAddress(address, AddressType.p2pkh);
|
19
|
+
});
|
20
|
+
export const BtcP2shAddressStruct = refine(string(), 'BtcP2shAddressStruct', (address) => {
|
21
|
+
return validateAddress(address, AddressType.p2sh);
|
22
|
+
});
|
23
|
+
export const BtcP2wpkhAddressStruct = refine(string(), 'BtcP2wpkhAddressStruct', (address) => {
|
24
|
+
return validateAddress(address, AddressType.p2wpkh);
|
25
|
+
});
|
26
|
+
export const BtcP2trAddressStruct = refine(string(), 'BtcP2trAddressStruct', (address) => {
|
27
|
+
return validateAddress(address, AddressType.p2tr);
|
13
28
|
});
|
14
29
|
/**
|
15
30
|
* Supported Bitcoin methods.
|
@@ -19,25 +34,59 @@ export var BtcMethod;
|
|
19
34
|
// General transaction methods
|
20
35
|
BtcMethod["SendBitcoin"] = "sendBitcoin";
|
21
36
|
})(BtcMethod || (BtcMethod = {}));
|
22
|
-
|
37
|
+
const BtcAccountStruct = object({
|
23
38
|
...KeyringAccountStruct.schema,
|
24
39
|
/**
|
25
|
-
* Account
|
40
|
+
* Account supported scopes (CAIP-2 chain ID).
|
41
|
+
*/
|
42
|
+
scopes: nonempty(array(CaipChainIdStruct)),
|
43
|
+
/**
|
44
|
+
* Account supported methods.
|
45
|
+
*/
|
46
|
+
methods: array(enums([`${BtcMethod.SendBitcoin}`])),
|
47
|
+
});
|
48
|
+
export const BtcP2pkhAccountStruct = object({
|
49
|
+
...BtcAccountStruct.schema,
|
50
|
+
/**
|
51
|
+
* Account P2PKH address.
|
52
|
+
*/
|
53
|
+
address: BtcP2pkhAddressStruct,
|
54
|
+
/**
|
55
|
+
* Account type.
|
56
|
+
*/
|
57
|
+
type: literal(`${BtcAccountType.P2pkh}`),
|
58
|
+
});
|
59
|
+
export const BtcP2shAccountStruct = object({
|
60
|
+
...BtcAccountStruct.schema,
|
61
|
+
/**
|
62
|
+
* Account P2SH address.
|
63
|
+
*/
|
64
|
+
address: BtcP2shAddressStruct,
|
65
|
+
/**
|
66
|
+
* Account type.
|
67
|
+
*/
|
68
|
+
type: literal(`${BtcAccountType.P2sh}`),
|
69
|
+
});
|
70
|
+
export const BtcP2wpkhAccountStruct = object({
|
71
|
+
...BtcAccountStruct.schema,
|
72
|
+
/**
|
73
|
+
* Account P2WPKH address.
|
26
74
|
*/
|
27
75
|
address: BtcP2wpkhAddressStruct,
|
28
76
|
/**
|
29
77
|
* Account type.
|
30
78
|
*/
|
31
79
|
type: literal(`${BtcAccountType.P2wpkh}`),
|
80
|
+
});
|
81
|
+
export const BtcP2trAccountStruct = object({
|
82
|
+
...BtcAccountStruct.schema,
|
32
83
|
/**
|
33
|
-
* Account
|
34
|
-
*
|
35
|
-
* NOTE: We consider a Bitcoin address to be valid on only 1 network at time.
|
84
|
+
* Account P2TR address.
|
36
85
|
*/
|
37
|
-
|
86
|
+
address: BtcP2trAddressStruct,
|
38
87
|
/**
|
39
|
-
* Account
|
88
|
+
* Account type.
|
40
89
|
*/
|
41
|
-
|
90
|
+
type: literal(`${BtcAccountType.P2tr}`),
|
42
91
|
});
|
43
92
|
//# sourceMappingURL=types.mjs.map
|
package/dist/btc/types.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":"AAAA,O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C,IAAI,EAAE,CAAC;CACxC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;IAC3C,GAAG,gBAAgB,CAAC,MAAM;IAE1B;;OAEG;IACH,OAAO,EAAE,sBAAsB;IAE/B;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC;CAC1C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;IACzC,GAAG,gBAAgB,CAAC,MAAM;IAE1B;;OAEG;IACH,OAAO,EAAE,oBAAoB;IAE7B;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC,GAAG,cAAc,CAAC,IAAI,EAAE,CAAC;CACxC,CAAC,CAAC","sourcesContent":["import { object } from '@metamask/keyring-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n string,\n array,\n enums,\n refine,\n literal,\n nonempty,\n} from '@metamask/superstruct';\nimport { AddressType, getAddressInfo } from 'bitcoin-address-validation';\n\nimport {\n BtcAccountType,\n CaipChainIdStruct,\n KeyringAccountStruct,\n} from '../api';\n\nconst validateAddress = (\n address: string,\n type: AddressType,\n): boolean | Error => {\n try {\n const addressInfo = getAddressInfo(address);\n if (addressInfo.type === type) {\n return true;\n }\n return new Error(`Invalid ${type} address`);\n } catch (error) {\n return new Error(\n `Failed to decode ${type} address: ${(error as Error).message}`,\n );\n }\n};\n\nexport const BtcP2pkhAddressStruct = refine(\n string(),\n 'BtcP2pkhAddressStruct',\n (address: string) => {\n return validateAddress(address, AddressType.p2pkh);\n },\n);\n\nexport const BtcP2shAddressStruct = refine(\n string(),\n 'BtcP2shAddressStruct',\n (address: string) => {\n return validateAddress(address, AddressType.p2sh);\n },\n);\n\nexport const BtcP2wpkhAddressStruct = refine(\n string(),\n 'BtcP2wpkhAddressStruct',\n (address: string) => {\n return validateAddress(address, AddressType.p2wpkh);\n },\n);\n\nexport const BtcP2trAddressStruct = refine(\n string(),\n 'BtcP2trAddressStruct',\n (address: string) => {\n return validateAddress(address, AddressType.p2tr);\n },\n);\n\n/**\n * Supported Bitcoin methods.\n */\nexport enum BtcMethod {\n // General transaction methods\n SendBitcoin = 'sendBitcoin',\n}\n\nconst BtcAccountStruct = object({\n ...KeyringAccountStruct.schema,\n\n /**\n * Account supported scopes (CAIP-2 chain ID).\n */\n scopes: nonempty(array(CaipChainIdStruct)),\n\n /**\n * Account supported methods.\n */\n methods: array(enums([`${BtcMethod.SendBitcoin}`])),\n});\n\nexport const BtcP2pkhAccountStruct = object({\n ...BtcAccountStruct.schema,\n\n /**\n * Account P2PKH address.\n */\n address: BtcP2pkhAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2pkh}`),\n});\n\nexport const BtcP2shAccountStruct = object({\n ...BtcAccountStruct.schema,\n\n /**\n * Account P2SH address.\n */\n address: BtcP2shAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2sh}`),\n});\n\nexport const BtcP2wpkhAccountStruct = object({\n ...BtcAccountStruct.schema,\n\n /**\n * Account P2WPKH address.\n */\n address: BtcP2wpkhAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2wpkh}`),\n});\n\nexport const BtcP2trAccountStruct = object({\n ...BtcAccountStruct.schema,\n\n /**\n * Account P2TR address.\n */\n address: BtcP2trAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2tr}`),\n});\n\nexport type BtcP2pkhAccount = Infer<typeof BtcP2pkhAccountStruct>;\nexport type BtcP2shAccount = Infer<typeof BtcP2shAccountStruct>;\nexport type BtcP2wpkhAccount = Infer<typeof BtcP2wpkhAccountStruct>;\nexport type BtcP2trAccount = Infer<typeof BtcP2trAccountStruct>;\n"]}
|