@metamask-previews/utils 11.12.1-preview-9962b7e

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.
Files changed (112) hide show
  1. package/CHANGELOG.md +584 -0
  2. package/LICENSE +15 -0
  3. package/README.md +106 -0
  4. package/dist/assert.d.ts +61 -0
  5. package/dist/assert.d.ts.map +1 -0
  6. package/dist/assert.js +115 -0
  7. package/dist/assert.js.map +1 -0
  8. package/dist/base64.d.ts +25 -0
  9. package/dist/base64.d.ts.map +1 -0
  10. package/dist/base64.js +30 -0
  11. package/dist/base64.js.map +1 -0
  12. package/dist/bytes.d.ts +198 -0
  13. package/dist/bytes.d.ts.map +1 -0
  14. package/dist/bytes.js +406 -0
  15. package/dist/bytes.js.map +1 -0
  16. package/dist/caip-types.d.ts +294 -0
  17. package/dist/caip-types.d.ts.map +1 -0
  18. package/dist/caip-types.js +369 -0
  19. package/dist/caip-types.js.map +1 -0
  20. package/dist/checksum.d.ts +2 -0
  21. package/dist/checksum.d.ts.map +1 -0
  22. package/dist/checksum.js +4 -0
  23. package/dist/checksum.js.map +1 -0
  24. package/dist/coercers.d.ts +97 -0
  25. package/dist/coercers.d.ts.map +1 -0
  26. package/dist/coercers.js +159 -0
  27. package/dist/coercers.js.map +1 -0
  28. package/dist/collections.d.ts +39 -0
  29. package/dist/collections.d.ts.map +1 -0
  30. package/dist/collections.js +105 -0
  31. package/dist/collections.js.map +1 -0
  32. package/dist/encryption-types.d.ts +7 -0
  33. package/dist/encryption-types.d.ts.map +1 -0
  34. package/dist/encryption-types.js +2 -0
  35. package/dist/encryption-types.js.map +1 -0
  36. package/dist/errors.d.ts +68 -0
  37. package/dist/errors.d.ts.map +1 -0
  38. package/dist/errors.js +121 -0
  39. package/dist/errors.js.map +1 -0
  40. package/dist/fs.d.ts +133 -0
  41. package/dist/fs.d.ts.map +1 -0
  42. package/dist/fs.js +210 -0
  43. package/dist/fs.js.map +1 -0
  44. package/dist/hashing.d.ts +28 -0
  45. package/dist/hashing.d.ts.map +1 -0
  46. package/dist/hashing.js +59 -0
  47. package/dist/hashing.js.map +1 -0
  48. package/dist/hex.d.ts +117 -0
  49. package/dist/hex.d.ts.map +1 -0
  50. package/dist/hex.js +174 -0
  51. package/dist/hex.js.map +1 -0
  52. package/dist/index.d.ts +26 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +21 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/json.d.ts +398 -0
  57. package/dist/json.d.ts.map +1 -0
  58. package/dist/json.js +402 -0
  59. package/dist/json.js.map +1 -0
  60. package/dist/keyring.d.ts +243 -0
  61. package/dist/keyring.d.ts.map +1 -0
  62. package/dist/keyring.js +2 -0
  63. package/dist/keyring.js.map +1 -0
  64. package/dist/logging.d.ts +30 -0
  65. package/dist/logging.d.ts.map +1 -0
  66. package/dist/logging.js +35 -0
  67. package/dist/logging.js.map +1 -0
  68. package/dist/misc.d.ts +127 -0
  69. package/dist/misc.d.ts.map +1 -0
  70. package/dist/misc.js +142 -0
  71. package/dist/misc.js.map +1 -0
  72. package/dist/mnemonic.d.ts +14 -0
  73. package/dist/mnemonic.d.ts.map +1 -0
  74. package/dist/mnemonic.js +25 -0
  75. package/dist/mnemonic.js.map +1 -0
  76. package/dist/node.d.ts +3 -0
  77. package/dist/node.d.ts.map +1 -0
  78. package/dist/node.js +3 -0
  79. package/dist/node.js.map +1 -0
  80. package/dist/number.d.ts +74 -0
  81. package/dist/number.d.ts.map +1 -0
  82. package/dist/number.js +95 -0
  83. package/dist/number.js.map +1 -0
  84. package/dist/opaque.d.ts +6 -0
  85. package/dist/opaque.d.ts.map +1 -0
  86. package/dist/opaque.js +2 -0
  87. package/dist/opaque.js.map +1 -0
  88. package/dist/promise.d.ts +45 -0
  89. package/dist/promise.d.ts.map +1 -0
  90. package/dist/promise.js +40 -0
  91. package/dist/promise.js.map +1 -0
  92. package/dist/superstruct.d.ts +20 -0
  93. package/dist/superstruct.d.ts.map +1 -0
  94. package/dist/superstruct.js +24 -0
  95. package/dist/superstruct.js.map +1 -0
  96. package/dist/time.d.ts +49 -0
  97. package/dist/time.d.ts.map +1 -0
  98. package/dist/time.js +62 -0
  99. package/dist/time.js.map +1 -0
  100. package/dist/transaction-types.d.ts +117 -0
  101. package/dist/transaction-types.d.ts.map +1 -0
  102. package/dist/transaction-types.js +2 -0
  103. package/dist/transaction-types.js.map +1 -0
  104. package/dist/unitsConversion.d.ts +80 -0
  105. package/dist/unitsConversion.d.ts.map +1 -0
  106. package/dist/unitsConversion.js +209 -0
  107. package/dist/unitsConversion.js.map +1 -0
  108. package/dist/versions.d.ts +101 -0
  109. package/dist/versions.d.ts.map +1 -0
  110. package/dist/versions.js +85 -0
  111. package/dist/versions.js.map +1 -0
  112. package/package.json +122 -0
@@ -0,0 +1,294 @@
1
+ import type { Infer } from '@metamask/superstruct';
2
+ export declare const CAIP_CHAIN_ID_REGEX: RegExp;
3
+ export declare const CAIP_NAMESPACE_REGEX: RegExp;
4
+ export declare const CAIP_REFERENCE_REGEX: RegExp;
5
+ export declare const CAIP_ACCOUNT_ID_REGEX: RegExp;
6
+ export declare const CAIP_ACCOUNT_ADDRESS_REGEX: RegExp;
7
+ export declare const CAIP_ASSET_NAMESPACE_REGEX: RegExp;
8
+ export declare const CAIP_ASSET_REFERENCE_REGEX: RegExp;
9
+ export declare const CAIP_TOKEN_ID_REGEX: RegExp;
10
+ export declare const CAIP_ASSET_TYPE_REGEX: RegExp;
11
+ export declare const CAIP_ASSET_ID_REGEX: RegExp;
12
+ /**
13
+ * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
14
+ */
15
+ export declare const CaipChainIdStruct: import("@metamask/superstruct").Struct<`${string}:${string}`, null>;
16
+ export type CaipChainId = Infer<typeof CaipChainIdStruct>;
17
+ /**
18
+ * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.
19
+ */
20
+ export declare const CaipNamespaceStruct: import("@metamask/superstruct").Struct<string, null>;
21
+ export type CaipNamespace = Infer<typeof CaipNamespaceStruct>;
22
+ /**
23
+ * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.
24
+ */
25
+ export declare const CaipReferenceStruct: import("@metamask/superstruct").Struct<string, null>;
26
+ export type CaipReference = Infer<typeof CaipReferenceStruct>;
27
+ /**
28
+ * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.
29
+ */
30
+ export declare const CaipAccountIdStruct: import("@metamask/superstruct").Struct<`${string}:${string}:${string}`, null>;
31
+ export type CaipAccountId = Infer<typeof CaipAccountIdStruct>;
32
+ /**
33
+ * A CAIP-10 account address, i.e., the third part of the CAIP account ID.
34
+ */
35
+ export declare const CaipAccountAddressStruct: import("@metamask/superstruct").Struct<string, null>;
36
+ export type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;
37
+ /**
38
+ * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.
39
+ */
40
+ export declare const CaipAssetNamespaceStruct: import("@metamask/superstruct").Struct<string, null>;
41
+ export type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;
42
+ /**
43
+ * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.
44
+ */
45
+ export declare const CaipAssetReferenceStruct: import("@metamask/superstruct").Struct<string, null>;
46
+ export type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;
47
+ /**
48
+ * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type
49
+ */
50
+ export declare const CaipTokenIdStruct: import("@metamask/superstruct").Struct<string, null>;
51
+ export type CaipTokenId = Infer<typeof CaipTokenIdStruct>;
52
+ /**
53
+ * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
54
+ */
55
+ export declare const CaipAssetTypeStruct: import("@metamask/superstruct").Struct<`${string}:${string}/${string}:${string}`, null>;
56
+ export type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;
57
+ /**
58
+ * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
59
+ */
60
+ export declare const CaipAssetIdStruct: import("@metamask/superstruct").Struct<`${string}:${string}/${string}:${string}/${string}`, null>;
61
+ export type CaipAssetId = Infer<typeof CaipAssetIdStruct>;
62
+ /**
63
+ * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.
64
+ */
65
+ export declare const CaipAssetTypeOrIdStruct: import("@metamask/superstruct").Struct<`${string}:${string}/${string}:${string}` | `${string}:${string}/${string}:${string}/${string}`, null>;
66
+ export type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;
67
+ /** Known CAIP namespaces. */
68
+ export declare enum KnownCaipNamespace {
69
+ /** BIP-122 (Bitcoin) compatible chains. */
70
+ Bip122 = "bip122",
71
+ /** Solana compatible chains */
72
+ Solana = "solana",
73
+ /** Stellar compatible chains */
74
+ Stellar = "stellar",
75
+ /** Tron compatible chains */
76
+ Tron = "tron",
77
+ /** EIP-155 compatible chains. */
78
+ Eip155 = "eip155",
79
+ Wallet = "wallet"
80
+ }
81
+ /**
82
+ * A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace
83
+ * (@see {@link KnownCaipNamespace}).
84
+ *
85
+ * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases
86
+ * where the chain namespace must be one of the known standards.
87
+ *
88
+ * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.
89
+ */
90
+ export type KnownCaipNamespacedChainId<Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`> = `${Namespace}:${string}`;
91
+ /**
92
+ * Check if the given value is a {@link CaipChainId}.
93
+ *
94
+ * @param value - The value to check.
95
+ * @returns Whether the value is a {@link CaipChainId}.
96
+ */
97
+ export declare function isCaipChainId(value: unknown): value is CaipChainId;
98
+ /**
99
+ * Check if the given value is a {@link CaipNamespace}.
100
+ *
101
+ * @param value - The value to check.
102
+ * @returns Whether the value is a {@link CaipNamespace}.
103
+ */
104
+ export declare function isCaipNamespace(value: unknown): value is CaipNamespace;
105
+ /**
106
+ * Check if the given value is a {@link CaipReference}.
107
+ *
108
+ * @param value - The value to check.
109
+ * @returns Whether the value is a {@link CaipReference}.
110
+ */
111
+ export declare function isCaipReference(value: unknown): value is CaipReference;
112
+ /**
113
+ * Check if the given value is a {@link CaipAccountId}.
114
+ *
115
+ * @param value - The value to check.
116
+ * @returns Whether the value is a {@link CaipAccountId}.
117
+ */
118
+ export declare function isCaipAccountId(value: unknown): value is CaipAccountId;
119
+ /**
120
+ * Check if a value is a {@link CaipAccountAddress}.
121
+ *
122
+ * @param value - The value to validate.
123
+ * @returns True if the value is a valid {@link CaipAccountAddress}.
124
+ */
125
+ export declare function isCaipAccountAddress(value: unknown): value is CaipAccountAddress;
126
+ /**
127
+ * Check if the given value is a {@link CaipAssetNamespace}.
128
+ *
129
+ * @param value - The value to check.
130
+ * @returns Whether the value is a {@link CaipAssetNamespace}.
131
+ */
132
+ export declare function isCaipAssetNamespace(value: unknown): value is CaipAssetNamespace;
133
+ /**
134
+ * Check if the given value is a {@link CaipAssetReference}.
135
+ *
136
+ * @param value - The value to check.
137
+ * @returns Whether the value is a {@link CaipAssetReference}.
138
+ */
139
+ export declare function isCaipAssetReference(value: unknown): value is CaipAssetReference;
140
+ /**
141
+ * Check if the given value is a {@link CaipTokenId}.
142
+ *
143
+ * @param value - The value to check.
144
+ * @returns Whether the value is a {@link CaipTokenId}.
145
+ */
146
+ export declare function isCaipTokenId(value: unknown): value is CaipTokenId;
147
+ /**
148
+ * Check if the given value is a {@link CaipAssetType}.
149
+ *
150
+ * @param value - The value to check.
151
+ * @returns Whether the value is a {@link CaipAssetType}.
152
+ */
153
+ export declare function isCaipAssetType(value: unknown): value is CaipAssetType;
154
+ /**
155
+ * Check if the given value is a {@link CaipAssetId}.
156
+ *
157
+ * @param value - The value to check.
158
+ * @returns Whether the value is a {@link CaipAssetId}.
159
+ */
160
+ export declare function isCaipAssetId(value: unknown): value is CaipAssetId;
161
+ /**
162
+ * Parse a CAIP-2 chain ID to an object containing the namespace and reference.
163
+ * This validates the CAIP-2 chain ID before parsing it.
164
+ *
165
+ * @param caipChainId - The CAIP-2 chain ID to validate and parse.
166
+ * @returns The parsed CAIP-2 chain ID.
167
+ */
168
+ export declare function parseCaipChainId(caipChainId: CaipChainId): {
169
+ namespace: CaipNamespace;
170
+ reference: CaipReference;
171
+ };
172
+ /**
173
+ * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.
174
+ * This validates the CAIP-10 account ID before parsing it.
175
+ *
176
+ * @param caipAccountId - The CAIP-10 account ID to validate and parse.
177
+ * @returns The parsed CAIP-10 account ID.
178
+ */
179
+ export declare function parseCaipAccountId(caipAccountId: CaipAccountId): {
180
+ address: CaipAccountAddress;
181
+ chainId: CaipChainId;
182
+ chain: {
183
+ namespace: CaipNamespace;
184
+ reference: CaipReference;
185
+ };
186
+ };
187
+ /**
188
+ * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,
189
+ * asset namespace, and asset reference
190
+ *
191
+ * This validates the CAIP-19 asset type before parsing it.
192
+ *
193
+ * @param caipAssetType - The CAIP-19 asset type to validate and parse.
194
+ * @returns The parsed CAIP-19 asset type.
195
+ */
196
+ export declare function parseCaipAssetType(caipAssetType: CaipAssetType): {
197
+ assetNamespace: CaipAssetNamespace;
198
+ assetReference: CaipAssetReference;
199
+ chainId: CaipChainId;
200
+ chain: {
201
+ namespace: CaipNamespace;
202
+ reference: CaipReference;
203
+ };
204
+ };
205
+ /**
206
+ * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,
207
+ * asset namespace, asset reference, and token ID.
208
+ *
209
+ * This validates the CAIP-19 asset ID before parsing it.
210
+ *
211
+ * @param caipAssetId - The CAIP-19 asset ID to validate and parse.
212
+ * @returns The parsed CAIP-19 asset ID.
213
+ */
214
+ export declare function parseCaipAssetId(caipAssetId: CaipAssetId): {
215
+ assetNamespace: CaipAssetNamespace;
216
+ assetReference: CaipAssetReference;
217
+ tokenId: CaipTokenId;
218
+ chainId: CaipChainId;
219
+ chain: {
220
+ namespace: CaipNamespace;
221
+ reference: CaipReference;
222
+ };
223
+ };
224
+ /**
225
+ * Chain ID as defined per the CAIP-2
226
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.
227
+ *
228
+ * It defines a way to uniquely identify any blockchain in a human-readable
229
+ * way.
230
+ *
231
+ * @param namespace - The standard (ecosystem) of similar blockchains.
232
+ * @param reference - Identify of a blockchain within a given namespace.
233
+ * @throws {@link Error}
234
+ * This exception is thrown if the inputs does not comply with the CAIP-2
235
+ * syntax specification
236
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.
237
+ * @returns A CAIP chain ID.
238
+ */
239
+ export declare function toCaipChainId(namespace: CaipNamespace, reference: CaipReference): CaipChainId;
240
+ /**
241
+ * Account ID as defined per the CAIP-10
242
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.
243
+ *
244
+ * It defines a way to uniquely identify any blockchain account in a human-readable
245
+ * way.
246
+ *
247
+ * @param namespace - The standard (ecosystem) of similar blockchains.
248
+ * @param reference - Identity of a blockchain within a given namespace.
249
+ * @param accountAddress - The address of the blockchain account.
250
+ * @throws {@link Error}
251
+ * This exception is thrown if the inputs do not comply with the CAIP-10
252
+ * syntax specification
253
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.
254
+ * @returns A CAIP account ID.
255
+ */
256
+ export declare function toCaipAccountId(namespace: CaipNamespace, reference: CaipReference, accountAddress: CaipAccountAddress): CaipAccountId;
257
+ /**
258
+ * Asset Type as defined per the CAIP-19
259
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.
260
+ *
261
+ * It defines a way to uniquely identify any blockchain asset in a human-readable
262
+ * way.
263
+ *
264
+ * @param namespace - The standard (ecosystem) of similar blockchains.
265
+ * @param reference - Identity of a blockchain within a given namespace.
266
+ * @param assetNamespace - The namespace domain of an asset.
267
+ * @param assetReference - The identity of an asset within a given namespace.
268
+ * @throws {@link Error}
269
+ * This exception is thrown if the inputs do not comply with the CAIP-19
270
+ * syntax specification
271
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.
272
+ * @returns A CAIP asset type.
273
+ */
274
+ export declare function toCaipAssetType(namespace: CaipNamespace, reference: CaipReference, assetNamespace: CaipAssetNamespace, assetReference: CaipAssetReference): CaipAssetType;
275
+ /**
276
+ * Asset ID as defined per the CAIP-19
277
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.
278
+ *
279
+ * It defines a way to uniquely identify any blockchain asset in a human-readable
280
+ * way.
281
+ *
282
+ * @param namespace - The standard (ecosystem) of similar blockchains.
283
+ * @param reference - Identity of a blockchain within a given namespace.
284
+ * @param assetNamespace - The namespace domain of an asset.
285
+ * @param assetReference - The identity of an asset within a given namespace.
286
+ * @param tokenId - The unique identifier for an addressable asset of a given type.
287
+ * @throws {@link Error}
288
+ * This exception is thrown if the inputs do not comply with the CAIP-19
289
+ * syntax specification
290
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.
291
+ * @returns A CAIP asset ID.
292
+ */
293
+ export declare function toCaipAssetId(namespace: CaipNamespace, reference: CaipReference, assetNamespace: CaipAssetNamespace, assetReference: CaipAssetReference, tokenId: CaipTokenId): CaipAssetId;
294
+ //# sourceMappingURL=caip-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip-types.d.ts","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAInD,eAAO,MAAM,mBAAmB,QACqC,CAAC;AAEtE,eAAO,MAAM,oBAAoB,QAAsB,CAAC;AAExD,eAAO,MAAM,oBAAoB,QAA2B,CAAC;AAE7D,eAAO,MAAM,qBAAqB,QACwF,CAAC;AAE3H,eA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AO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE;QAAE,SAAS,EAAE,aAAa,CAAC;QAAC,SAAS,EAAE,aAAa,CAAA;KAAE,CAAC;CAC/D,CAgBA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,aAAa,GACvB,WAAW,CAcb;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,aAAa,EACxB,cAAc,EAAE,kBAAkB,GACjC,aAAa,CAoBf;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,aAAa,EACxB,cAAc,EAAE,kBAAkB,EAClC,cAAc,EAAE,kBAAkB,GACjC,aAAa,CA0Bf;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,aAAa,EACxB,cAAc,EAAE,kBAAkB,EAClC,cAAc,EAAE,kBAAkB,EAClC,OAAO,EAAE,WAAW,GACnB,WAAW,CAgCb"}
@@ -0,0 +1,369 @@
1
+ import { definePattern } from './superstruct.js';
2
+ export const CAIP_CHAIN_ID_REGEX = /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;
3
+ export const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;
4
+ export const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;
5
+ export const CAIP_ACCOUNT_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;
6
+ export const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;
7
+ export const CAIP_ASSET_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;
8
+ export const CAIP_ASSET_REFERENCE_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;
9
+ export const CAIP_TOKEN_ID_REGEX = /^[-.%a-zA-Z0-9]{1,78}$/u;
10
+ export const CAIP_ASSET_TYPE_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;
11
+ export const CAIP_ASSET_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;
12
+ const CAIP_ASSET_TYPE_OR_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})(\/(?<tokenId>[-.%a-zA-Z0-9]{1,78}))?$/u;
13
+ /**
14
+ * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
15
+ */
16
+ export const CaipChainIdStruct = definePattern('CaipChainId', CAIP_CHAIN_ID_REGEX);
17
+ /**
18
+ * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.
19
+ */
20
+ export const CaipNamespaceStruct = definePattern('CaipNamespace', CAIP_NAMESPACE_REGEX);
21
+ /**
22
+ * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.
23
+ */
24
+ export const CaipReferenceStruct = definePattern('CaipReference', CAIP_REFERENCE_REGEX);
25
+ /**
26
+ * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.
27
+ */
28
+ export const CaipAccountIdStruct = definePattern('CaipAccountId', CAIP_ACCOUNT_ID_REGEX);
29
+ /**
30
+ * A CAIP-10 account address, i.e., the third part of the CAIP account ID.
31
+ */
32
+ export const CaipAccountAddressStruct = definePattern('CaipAccountAddress', CAIP_ACCOUNT_ADDRESS_REGEX);
33
+ /**
34
+ * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.
35
+ */
36
+ export const CaipAssetNamespaceStruct = definePattern('CaipAssetNamespace', CAIP_ASSET_NAMESPACE_REGEX);
37
+ /**
38
+ * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.
39
+ */
40
+ export const CaipAssetReferenceStruct = definePattern('CaipAssetReference', CAIP_ASSET_REFERENCE_REGEX);
41
+ /**
42
+ * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type
43
+ */
44
+ export const CaipTokenIdStruct = definePattern('CaipTokenId', CAIP_TOKEN_ID_REGEX);
45
+ /**
46
+ * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
47
+ */
48
+ export const CaipAssetTypeStruct = definePattern('CaipAssetType', CAIP_ASSET_TYPE_REGEX);
49
+ /**
50
+ * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
51
+ */
52
+ export const CaipAssetIdStruct = definePattern('CaipAssetId', CAIP_ASSET_ID_REGEX);
53
+ /**
54
+ * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.
55
+ */
56
+ export const CaipAssetTypeOrIdStruct = definePattern('CaipAssetTypeOrId', CAIP_ASSET_TYPE_OR_ID_REGEX);
57
+ /** Known CAIP namespaces. */
58
+ export var KnownCaipNamespace;
59
+ (function (KnownCaipNamespace) {
60
+ /** BIP-122 (Bitcoin) compatible chains. */
61
+ KnownCaipNamespace["Bip122"] = "bip122";
62
+ /** Solana compatible chains */
63
+ KnownCaipNamespace["Solana"] = "solana";
64
+ /** Stellar compatible chains */
65
+ KnownCaipNamespace["Stellar"] = "stellar";
66
+ /** Tron compatible chains */
67
+ KnownCaipNamespace["Tron"] = "tron";
68
+ /** EIP-155 compatible chains. */
69
+ KnownCaipNamespace["Eip155"] = "eip155";
70
+ KnownCaipNamespace["Wallet"] = "wallet";
71
+ })(KnownCaipNamespace || (KnownCaipNamespace = {}));
72
+ /**
73
+ * Check if the given value is a {@link CaipChainId}.
74
+ *
75
+ * @param value - The value to check.
76
+ * @returns Whether the value is a {@link CaipChainId}.
77
+ */
78
+ export function isCaipChainId(value) {
79
+ return typeof value === 'string' && CAIP_CHAIN_ID_REGEX.test(value);
80
+ }
81
+ /**
82
+ * Check if the given value is a {@link CaipNamespace}.
83
+ *
84
+ * @param value - The value to check.
85
+ * @returns Whether the value is a {@link CaipNamespace}.
86
+ */
87
+ export function isCaipNamespace(value) {
88
+ return typeof value === 'string' && CAIP_NAMESPACE_REGEX.test(value);
89
+ }
90
+ /**
91
+ * Check if the given value is a {@link CaipReference}.
92
+ *
93
+ * @param value - The value to check.
94
+ * @returns Whether the value is a {@link CaipReference}.
95
+ */
96
+ export function isCaipReference(value) {
97
+ return typeof value === 'string' && CAIP_REFERENCE_REGEX.test(value);
98
+ }
99
+ /**
100
+ * Check if the given value is a {@link CaipAccountId}.
101
+ *
102
+ * @param value - The value to check.
103
+ * @returns Whether the value is a {@link CaipAccountId}.
104
+ */
105
+ export function isCaipAccountId(value) {
106
+ return typeof value === 'string' && CAIP_ACCOUNT_ID_REGEX.test(value);
107
+ }
108
+ /**
109
+ * Check if a value is a {@link CaipAccountAddress}.
110
+ *
111
+ * @param value - The value to validate.
112
+ * @returns True if the value is a valid {@link CaipAccountAddress}.
113
+ */
114
+ export function isCaipAccountAddress(value) {
115
+ return typeof value === 'string' && CAIP_ACCOUNT_ADDRESS_REGEX.test(value);
116
+ }
117
+ /**
118
+ * Check if the given value is a {@link CaipAssetNamespace}.
119
+ *
120
+ * @param value - The value to check.
121
+ * @returns Whether the value is a {@link CaipAssetNamespace}.
122
+ */
123
+ export function isCaipAssetNamespace(value) {
124
+ return typeof value === 'string' && CAIP_ASSET_NAMESPACE_REGEX.test(value);
125
+ }
126
+ /**
127
+ * Check if the given value is a {@link CaipAssetReference}.
128
+ *
129
+ * @param value - The value to check.
130
+ * @returns Whether the value is a {@link CaipAssetReference}.
131
+ */
132
+ export function isCaipAssetReference(value) {
133
+ return typeof value === 'string' && CAIP_ASSET_REFERENCE_REGEX.test(value);
134
+ }
135
+ /**
136
+ * Check if the given value is a {@link CaipTokenId}.
137
+ *
138
+ * @param value - The value to check.
139
+ * @returns Whether the value is a {@link CaipTokenId}.
140
+ */
141
+ export function isCaipTokenId(value) {
142
+ return typeof value === 'string' && CAIP_TOKEN_ID_REGEX.test(value);
143
+ }
144
+ /**
145
+ * Check if the given value is a {@link CaipAssetType}.
146
+ *
147
+ * @param value - The value to check.
148
+ * @returns Whether the value is a {@link CaipAssetType}.
149
+ */
150
+ export function isCaipAssetType(value) {
151
+ return typeof value === 'string' && CAIP_ASSET_TYPE_REGEX.test(value);
152
+ }
153
+ /**
154
+ * Check if the given value is a {@link CaipAssetId}.
155
+ *
156
+ * @param value - The value to check.
157
+ * @returns Whether the value is a {@link CaipAssetId}.
158
+ */
159
+ export function isCaipAssetId(value) {
160
+ return typeof value === 'string' && CAIP_ASSET_ID_REGEX.test(value);
161
+ }
162
+ /**
163
+ * Parse a CAIP-2 chain ID to an object containing the namespace and reference.
164
+ * This validates the CAIP-2 chain ID before parsing it.
165
+ *
166
+ * @param caipChainId - The CAIP-2 chain ID to validate and parse.
167
+ * @returns The parsed CAIP-2 chain ID.
168
+ */
169
+ export function parseCaipChainId(caipChainId) {
170
+ const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);
171
+ if (!match?.groups) {
172
+ throw new Error('Invalid CAIP chain ID.');
173
+ }
174
+ return {
175
+ namespace: match.groups.namespace,
176
+ reference: match.groups.reference,
177
+ };
178
+ }
179
+ /**
180
+ * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.
181
+ * This validates the CAIP-10 account ID before parsing it.
182
+ *
183
+ * @param caipAccountId - The CAIP-10 account ID to validate and parse.
184
+ * @returns The parsed CAIP-10 account ID.
185
+ */
186
+ export function parseCaipAccountId(caipAccountId) {
187
+ const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);
188
+ if (!match?.groups) {
189
+ throw new Error('Invalid CAIP account ID.');
190
+ }
191
+ return {
192
+ address: match.groups.accountAddress,
193
+ chainId: match.groups.chainId,
194
+ chain: {
195
+ namespace: match.groups.namespace,
196
+ reference: match.groups.reference,
197
+ },
198
+ };
199
+ }
200
+ /**
201
+ * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,
202
+ * asset namespace, and asset reference
203
+ *
204
+ * This validates the CAIP-19 asset type before parsing it.
205
+ *
206
+ * @param caipAssetType - The CAIP-19 asset type to validate and parse.
207
+ * @returns The parsed CAIP-19 asset type.
208
+ */
209
+ export function parseCaipAssetType(caipAssetType) {
210
+ const match = CAIP_ASSET_TYPE_REGEX.exec(caipAssetType);
211
+ if (!match?.groups) {
212
+ throw new Error('Invalid CAIP asset type.');
213
+ }
214
+ return {
215
+ assetNamespace: match.groups.assetNamespace,
216
+ assetReference: match.groups.assetReference,
217
+ chainId: match.groups.chainId,
218
+ chain: {
219
+ namespace: match.groups.namespace,
220
+ reference: match.groups.reference,
221
+ },
222
+ };
223
+ }
224
+ /**
225
+ * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,
226
+ * asset namespace, asset reference, and token ID.
227
+ *
228
+ * This validates the CAIP-19 asset ID before parsing it.
229
+ *
230
+ * @param caipAssetId - The CAIP-19 asset ID to validate and parse.
231
+ * @returns The parsed CAIP-19 asset ID.
232
+ */
233
+ export function parseCaipAssetId(caipAssetId) {
234
+ const match = CAIP_ASSET_ID_REGEX.exec(caipAssetId);
235
+ if (!match?.groups) {
236
+ throw new Error('Invalid CAIP asset ID.');
237
+ }
238
+ return {
239
+ assetNamespace: match.groups.assetNamespace,
240
+ assetReference: match.groups.assetReference,
241
+ tokenId: match.groups.tokenId,
242
+ chainId: match.groups.chainId,
243
+ chain: {
244
+ namespace: match.groups.namespace,
245
+ reference: match.groups.reference,
246
+ },
247
+ };
248
+ }
249
+ /**
250
+ * Chain ID as defined per the CAIP-2
251
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.
252
+ *
253
+ * It defines a way to uniquely identify any blockchain in a human-readable
254
+ * way.
255
+ *
256
+ * @param namespace - The standard (ecosystem) of similar blockchains.
257
+ * @param reference - Identify of a blockchain within a given namespace.
258
+ * @throws {@link Error}
259
+ * This exception is thrown if the inputs does not comply with the CAIP-2
260
+ * syntax specification
261
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.
262
+ * @returns A CAIP chain ID.
263
+ */
264
+ export function toCaipChainId(namespace, reference) {
265
+ if (!isCaipNamespace(namespace)) {
266
+ throw new Error(`Invalid "namespace", must match: ${CAIP_NAMESPACE_REGEX.toString()}`);
267
+ }
268
+ if (!isCaipReference(reference)) {
269
+ throw new Error(`Invalid "reference", must match: ${CAIP_REFERENCE_REGEX.toString()}`);
270
+ }
271
+ return `${namespace}:${reference}`;
272
+ }
273
+ /**
274
+ * Account ID as defined per the CAIP-10
275
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.
276
+ *
277
+ * It defines a way to uniquely identify any blockchain account in a human-readable
278
+ * way.
279
+ *
280
+ * @param namespace - The standard (ecosystem) of similar blockchains.
281
+ * @param reference - Identity of a blockchain within a given namespace.
282
+ * @param accountAddress - The address of the blockchain account.
283
+ * @throws {@link Error}
284
+ * This exception is thrown if the inputs do not comply with the CAIP-10
285
+ * syntax specification
286
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.
287
+ * @returns A CAIP account ID.
288
+ */
289
+ export function toCaipAccountId(namespace, reference, accountAddress) {
290
+ if (!isCaipNamespace(namespace)) {
291
+ throw new Error(`Invalid "namespace", must match: ${CAIP_NAMESPACE_REGEX.toString()}`);
292
+ }
293
+ if (!isCaipReference(reference)) {
294
+ throw new Error(`Invalid "reference", must match: ${CAIP_REFERENCE_REGEX.toString()}`);
295
+ }
296
+ if (!isCaipAccountAddress(accountAddress)) {
297
+ throw new Error(`Invalid "accountAddress", must match: ${CAIP_ACCOUNT_ADDRESS_REGEX.toString()}`);
298
+ }
299
+ return `${namespace}:${reference}:${accountAddress}`;
300
+ }
301
+ /**
302
+ * Asset Type as defined per the CAIP-19
303
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.
304
+ *
305
+ * It defines a way to uniquely identify any blockchain asset in a human-readable
306
+ * way.
307
+ *
308
+ * @param namespace - The standard (ecosystem) of similar blockchains.
309
+ * @param reference - Identity of a blockchain within a given namespace.
310
+ * @param assetNamespace - The namespace domain of an asset.
311
+ * @param assetReference - The identity of an asset within a given namespace.
312
+ * @throws {@link Error}
313
+ * This exception is thrown if the inputs do not comply with the CAIP-19
314
+ * syntax specification
315
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.
316
+ * @returns A CAIP asset type.
317
+ */
318
+ export function toCaipAssetType(namespace, reference, assetNamespace, assetReference) {
319
+ if (!isCaipNamespace(namespace)) {
320
+ throw new Error(`Invalid "namespace", must match: ${CAIP_NAMESPACE_REGEX.toString()}`);
321
+ }
322
+ if (!isCaipReference(reference)) {
323
+ throw new Error(`Invalid "reference", must match: ${CAIP_REFERENCE_REGEX.toString()}`);
324
+ }
325
+ if (!isCaipAssetNamespace(assetNamespace)) {
326
+ throw new Error(`Invalid "assetNamespace", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`);
327
+ }
328
+ if (!isCaipAssetReference(assetReference)) {
329
+ throw new Error(`Invalid "assetReference", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`);
330
+ }
331
+ return `${namespace}:${reference}/${assetNamespace}:${assetReference}`;
332
+ }
333
+ /**
334
+ * Asset ID as defined per the CAIP-19
335
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.
336
+ *
337
+ * It defines a way to uniquely identify any blockchain asset in a human-readable
338
+ * way.
339
+ *
340
+ * @param namespace - The standard (ecosystem) of similar blockchains.
341
+ * @param reference - Identity of a blockchain within a given namespace.
342
+ * @param assetNamespace - The namespace domain of an asset.
343
+ * @param assetReference - The identity of an asset within a given namespace.
344
+ * @param tokenId - The unique identifier for an addressable asset of a given type.
345
+ * @throws {@link Error}
346
+ * This exception is thrown if the inputs do not comply with the CAIP-19
347
+ * syntax specification
348
+ * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.
349
+ * @returns A CAIP asset ID.
350
+ */
351
+ export function toCaipAssetId(namespace, reference, assetNamespace, assetReference, tokenId) {
352
+ if (!isCaipNamespace(namespace)) {
353
+ throw new Error(`Invalid "namespace", must match: ${CAIP_NAMESPACE_REGEX.toString()}`);
354
+ }
355
+ if (!isCaipReference(reference)) {
356
+ throw new Error(`Invalid "reference", must match: ${CAIP_REFERENCE_REGEX.toString()}`);
357
+ }
358
+ if (!isCaipAssetNamespace(assetNamespace)) {
359
+ throw new Error(`Invalid "assetNamespace", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`);
360
+ }
361
+ if (!isCaipAssetReference(assetReference)) {
362
+ throw new Error(`Invalid "assetReference", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`);
363
+ }
364
+ if (!isCaipTokenId(tokenId)) {
365
+ throw new Error(`Invalid "tokenId", must match: ${CAIP_TOKEN_ID_REGEX.toString()}`);
366
+ }
367
+ return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;
368
+ }
369
+ //# sourceMappingURL=caip-types.js.map