@metamask/chain-api
Advanced tools
| import { | ||
| definePattern | ||
| } from "./chunk-GIDWNBZF.mjs"; | ||
| // src/types.ts | ||
| var StringNumberStruct = definePattern( | ||
| "StringNumber", | ||
| /^[0-9]+(\.[0-9]+)?$/u | ||
| ); | ||
| export { | ||
| StringNumberStruct | ||
| }; | ||
| //# sourceMappingURL=chunk-CGK6CF33.mjs.map |
| {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Infer } from '@metamask/superstruct';\n\nimport type { CaipAssetType } from './caip-types';\nimport { definePattern } from './superstruct';\n\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^[0-9]+(\\.[0-9]+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n\n/**\n * Result object for assets balances.\n */\nexport type BalancesResult = {\n balances: Record<string, Record<CaipAssetType, { amount: StringNumber }>>;\n};\n"],"mappings":";;;;;AAKO,IAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AACF;","names":[]} |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkIZ77AXT7js = require('./chunk-IZ77AXT7.js'); | ||
| // src/rpc-handler.ts | ||
| var _superstruct = require('@metamask/superstruct'); | ||
| var _utils = require('@metamask/utils'); | ||
| var ChainRpcMethod = /* @__PURE__ */ ((ChainRpcMethod2) => { | ||
| ChainRpcMethod2["GetBalances"] = "chain_getBalances"; | ||
| return ChainRpcMethod2; | ||
| })(ChainRpcMethod || {}); | ||
| async function handleChainRequest(chain, request) { | ||
| _superstruct.assert.call(void 0, request, _utils.JsonRpcRequestStruct); | ||
| switch (request.method) { | ||
| case "chain_getBalances" /* GetBalances */: { | ||
| _superstruct.assert.call(void 0, request, _chunkIZ77AXT7js.GetBalancesRequestStruct); | ||
| return chain.getBalances( | ||
| request.params.scope, | ||
| request.params.accounts, | ||
| request.params.assets | ||
| ); | ||
| } | ||
| default: | ||
| throw new MethodNotSupportedError(request.method); | ||
| } | ||
| } | ||
| function isChainRpcMethod(method) { | ||
| return Object.values(ChainRpcMethod).includes(method); | ||
| } | ||
| exports.ChainRpcMethod = ChainRpcMethod; exports.handleChainRequest = handleChainRequest; exports.isChainRpcMethod = isChainRpcMethod; | ||
| //# sourceMappingURL=chunk-CMZV35YP.js.map |
| {"version":3,"sources":["../src/rpc-handler.ts"],"names":["ChainRpcMethod"],"mappings":";;;;;AAAA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AAS9B,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,iBAAc;AADJ,SAAAA;AAAA,GAAA;AAkBZ,eAAsB,mBACpB,OACA,SACsB;AAItB,SAAO,SAAS,oBAAoB;AAEpC,UAAQ,QAAQ,QAAQ;AAAA,IACtB,KAAK,uCAA4B;AAC/B,aAAO,SAAS,wBAAwB;AAExC,aAAO,MAAM;AAAA,QACX,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,MACjB;AAAA,IACF;AAAA,IAEA;AACE,YAAM,IAAI,wBAAwB,QAAQ,MAAM;AAAA,EACpD;AACF;AAQO,SAAS,iBAAiB,QAAyB;AACxD,SAAO,OAAO,OAAO,cAAc,EAAE,SAAS,MAAwB;AACxE","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport { JsonRpcRequestStruct } from '@metamask/utils';\nimport type { Json, JsonRpcRequest, CaipChainId } from '@metamask/utils';\n\nimport type { Chain } from './api';\nimport { GetBalancesRequestStruct } from './rpc-types';\n\n/**\n * Chain RPC methods.\n */\nexport enum ChainRpcMethod {\n GetBalances = 'chain_getBalances',\n}\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport declare class MethodNotSupportedError extends Error {\n constructor(method: string);\n}\n\n/**\n * Handles a chain JSON-RPC request.\n *\n * @param chain - Chain instance.\n * @param request - Chain JSON-RPC request.\n * @returns A promise that resolves to the chain's method response.\n */\nexport async function handleChainRequest(\n chain: Chain,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case ChainRpcMethod.GetBalances: {\n assert(request, GetBalancesRequestStruct);\n\n return chain.getBalances(\n request.params.scope as CaipChainId,\n request.params.accounts,\n request.params.assets,\n );\n }\n\n default:\n throw new MethodNotSupportedError(request.method);\n }\n}\n\n/**\n * Check if a method is a chain RPC method.\n *\n * @param method - Method to check.\n * @returns Whether the method is a chain RPC method.\n */\nexport function isChainRpcMethod(method: string): boolean {\n return Object.values(ChainRpcMethod).includes(method as ChainRpcMethod);\n}\n"]} |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/caip-types.ts | ||
| var _superstruct = require('@metamask/superstruct'); | ||
| var 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; | ||
| var 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; | ||
| var 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; | ||
| var CaipAssetTypeStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_ASSET_TYPE_REGEX); | ||
| var CaipAssetIdStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_ASSET_ID_REGEX); | ||
| var CaipAssetTypeOrIdStruct = _superstruct.pattern.call(void 0, | ||
| _superstruct.string.call(void 0, ), | ||
| CAIP_ASSET_TYPE_OR_ID_REGEX | ||
| ); | ||
| function isCaipAssetType(value) { | ||
| return _superstruct.is.call(void 0, value, CaipAssetTypeStruct); | ||
| } | ||
| function isCaipAssetId(value) { | ||
| return _superstruct.is.call(void 0, value, CaipAssetIdStruct); | ||
| } | ||
| function isCaipAssetTypeOrId(value) { | ||
| return _superstruct.is.call(void 0, value, CaipAssetTypeOrIdStruct); | ||
| } | ||
| exports.CAIP_ASSET_TYPE_REGEX = CAIP_ASSET_TYPE_REGEX; exports.CAIP_ASSET_ID_REGEX = CAIP_ASSET_ID_REGEX; exports.CAIP_ASSET_TYPE_OR_ID_REGEX = CAIP_ASSET_TYPE_OR_ID_REGEX; exports.CaipAssetTypeStruct = CaipAssetTypeStruct; exports.CaipAssetIdStruct = CaipAssetIdStruct; exports.CaipAssetTypeOrIdStruct = CaipAssetTypeOrIdStruct; exports.isCaipAssetType = isCaipAssetType; exports.isCaipAssetId = isCaipAssetId; exports.isCaipAssetTypeOrId = isCaipAssetTypeOrId; | ||
| //# sourceMappingURL=chunk-FUNHCXU2.js.map |
| {"version":3,"sources":["../src/caip-types.ts"],"names":[],"mappings":";AACA,SAAS,IAAI,QAAQ,eAAe;AAE7B,IAAM,wBACX;AAEK,IAAM,sBACX;AAEK,IAAM,8BACX;AAKK,IAAM,sBAAsB,QAAQ,OAAO,GAAG,qBAAqB;AAMnE,IAAM,oBAAoB,QAAQ,OAAO,GAAG,mBAAmB;AAM/D,IAAM,0BAA0B;AAAA,EACrC,OAAO;AAAA,EACP;AACF;AASO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,cAAc,OAAsC;AAClE,SAAO,GAAG,OAAO,iBAAiB;AACpC;AAQO,SAAS,oBAAoB,OAAsC;AACxE,SAAO,GAAG,OAAO,uBAAuB;AAC1C","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { is, string, pattern } from '@metamask/superstruct';\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<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;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<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;\n\nexport const CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<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;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset type identifier.\n */\nexport const CaipAssetTypeStruct = pattern(string(), CAIP_ASSET_TYPE_REGEX);\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID identifier.\n */\nexport const CaipAssetIdStruct = pattern(string(), CAIP_ASSET_ID_REGEX);\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = pattern(\n string(),\n CAIP_ASSET_TYPE_OR_ID_REGEX,\n);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetTypeOrId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetTypeOrId}.\n */\nexport function isCaipAssetTypeOrId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetTypeOrIdStruct);\n}\n"]} |
| // src/superstruct.ts | ||
| import { define } from "@metamask/superstruct"; | ||
| function definePattern(name, pattern) { | ||
| return define( | ||
| name, | ||
| (value) => typeof value === "string" && pattern.test(value) | ||
| ); | ||
| } | ||
| export { | ||
| definePattern | ||
| }; | ||
| //# sourceMappingURL=chunk-GIDWNBZF.mjs.map |
| {"version":3,"sources":["../src/superstruct.ts"],"sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { define } from '@metamask/superstruct';\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n"],"mappings":";AACA,SAAS,cAAc;AAehB,SAAS,cACd,MACA,SACsB;AACtB,SAAO;AAAA,IACL;AAAA,IACA,CAAC,UACC,OAAO,UAAU,YAAY,QAAQ,KAAK,KAAK;AAAA,EACnD;AACF;","names":[]} |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkFUNHCXU2js = require('./chunk-FUNHCXU2.js'); | ||
| var _chunkJKMEWU6Jjs = require('./chunk-JKMEWU6J.js'); | ||
| // src/rpc-types.ts | ||
| var _superstruct = require('@metamask/superstruct'); | ||
| var _utils = require('@metamask/utils'); | ||
| var AmountStruct = _superstruct.object.call(void 0, { | ||
| amount: _chunkJKMEWU6Jjs.StringNumberStruct | ||
| }); | ||
| var CommonHeader = { | ||
| jsonrpc: _superstruct.literal.call(void 0, "2.0"), | ||
| id: _superstruct.union.call(void 0, [_superstruct.string.call(void 0, ), _superstruct.number.call(void 0, ), _superstruct.literal.call(void 0, null)]) | ||
| }; | ||
| var GetBalancesRequestStruct = _superstruct.object.call(void 0, { | ||
| ...CommonHeader, | ||
| method: _superstruct.literal.call(void 0, "chain_getBalances"), | ||
| params: _superstruct.object.call(void 0, { | ||
| scope: _utils.CaipChainIdStruct, | ||
| accounts: _superstruct.array.call(void 0, _superstruct.string.call(void 0, )), | ||
| assets: _superstruct.array.call(void 0, _chunkFUNHCXU2js.CaipAssetTypeOrIdStruct) | ||
| }) | ||
| }); | ||
| var GetBalancesResponseStruct = _superstruct.object.call(void 0, { | ||
| balances: _superstruct.record.call(void 0, _superstruct.string.call(void 0, ), _superstruct.record.call(void 0, _chunkFUNHCXU2js.CaipAssetTypeOrIdStruct, AmountStruct)) | ||
| }); | ||
| exports.AmountStruct = AmountStruct; exports.GetBalancesRequestStruct = GetBalancesRequestStruct; exports.GetBalancesResponseStruct = GetBalancesResponseStruct; | ||
| //# sourceMappingURL=chunk-IZ77AXT7.js.map |
| {"version":3,"sources":["../src/rpc-types.ts"],"names":[],"mappings":";;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAK3B,IAAM,eAAe,OAAO;AAAA,EACjC,QAAQ;AACV,CAAC;AAED,IAAM,eAAe;AAAA,EACnB,SAAS,QAAQ,KAAK;AAAA,EACtB,IAAI,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,QAAQ,IAAI,CAAC,CAAC;AAC/C;AAKO,IAAM,2BAA2B,OAAO;AAAA,EAC7C,GAAG;AAAA,EACH,QAAQ,QAAQ,mBAAmB;AAAA,EACnC,QAAQ,OAAO;AAAA,IACb,OAAO;AAAA,IACP,UAAU,MAAM,OAAO,CAAC;AAAA,IACxB,QAAQ,MAAM,uBAAuB;AAAA,EACvC,CAAC;AACH,CAAC;AAIM,IAAM,4BAA4B,OAAO;AAAA,EAC9C,UAAU,OAAO,OAAO,GAAG,OAAO,yBAAyB,YAAY,CAAC;AAC1E,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n record,\n array,\n union,\n string,\n number,\n object,\n literal,\n} from '@metamask/superstruct';\nimport { CaipChainIdStruct } from '@metamask/utils';\n\nimport { CaipAssetTypeOrIdStruct } from './caip-types';\nimport { StringNumberStruct } from './types';\n\nexport const AmountStruct = object({\n amount: StringNumberStruct,\n});\n\nconst CommonHeader = {\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n};\n\n// ----------------------------------------------------------------------------\n// Get balances\n\nexport const GetBalancesRequestStruct = object({\n ...CommonHeader,\n method: literal('chain_getBalances'),\n params: object({\n scope: CaipChainIdStruct,\n accounts: array(string()),\n assets: array(CaipAssetTypeOrIdStruct),\n }),\n});\n\nexport type GetBalancesRequest = Infer<typeof GetBalancesRequestStruct>;\n\nexport const GetBalancesResponseStruct = object({\n balances: record(string(), record(CaipAssetTypeOrIdStruct, AmountStruct)),\n});\n\nexport type GetBalancesResponse = Infer<typeof GetBalancesResponseStruct>;\n"]} |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkJYVEPTYAjs = require('./chunk-JYVEPTYA.js'); | ||
| // src/types.ts | ||
| var StringNumberStruct = _chunkJYVEPTYAjs.definePattern.call(void 0, | ||
| "StringNumber", | ||
| /^[0-9]+(\.[0-9]+)?$/u | ||
| ); | ||
| exports.StringNumberStruct = StringNumberStruct; | ||
| //# sourceMappingURL=chunk-JKMEWU6J.js.map |
| {"version":3,"sources":["../src/types.ts"],"names":[],"mappings":";;;;;AAKO,IAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AACF","sourcesContent":["import type { Infer } from '@metamask/superstruct';\n\nimport type { CaipAssetType } from './caip-types';\nimport { definePattern } from './superstruct';\n\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^[0-9]+(\\.[0-9]+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n\n/**\n * Result object for assets balances.\n */\nexport type BalancesResult = {\n balances: Record<string, Record<CaipAssetType, { amount: StringNumber }>>;\n};\n"]} |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/superstruct.ts | ||
| var _superstruct = require('@metamask/superstruct'); | ||
| function definePattern(name, pattern) { | ||
| return _superstruct.define.call(void 0, | ||
| name, | ||
| (value) => typeof value === "string" && pattern.test(value) | ||
| ); | ||
| } | ||
| exports.definePattern = definePattern; | ||
| //# sourceMappingURL=chunk-JYVEPTYA.js.map |
| {"version":3,"sources":["../src/superstruct.ts"],"names":[],"mappings":";AACA,SAAS,cAAc;AAehB,SAAS,cACd,MACA,SACsB;AACtB,SAAO;AAAA,IACL;AAAA,IACA,CAAC,UACC,OAAO,UAAU,YAAY,QAAQ,KAAK,KAAK;AAAA,EACnD;AACF","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { define } from '@metamask/superstruct';\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n"]} |
| import { | ||
| GetBalancesRequestStruct | ||
| } from "./chunk-TMBZ25QJ.mjs"; | ||
| // src/rpc-handler.ts | ||
| import { assert } from "@metamask/superstruct"; | ||
| import { JsonRpcRequestStruct } from "@metamask/utils"; | ||
| var ChainRpcMethod = /* @__PURE__ */ ((ChainRpcMethod2) => { | ||
| ChainRpcMethod2["GetBalances"] = "chain_getBalances"; | ||
| return ChainRpcMethod2; | ||
| })(ChainRpcMethod || {}); | ||
| async function handleChainRequest(chain, request) { | ||
| assert(request, JsonRpcRequestStruct); | ||
| switch (request.method) { | ||
| case "chain_getBalances" /* GetBalances */: { | ||
| assert(request, GetBalancesRequestStruct); | ||
| return chain.getBalances( | ||
| request.params.scope, | ||
| request.params.accounts, | ||
| request.params.assets | ||
| ); | ||
| } | ||
| default: | ||
| throw new MethodNotSupportedError(request.method); | ||
| } | ||
| } | ||
| function isChainRpcMethod(method) { | ||
| return Object.values(ChainRpcMethod).includes(method); | ||
| } | ||
| export { | ||
| ChainRpcMethod, | ||
| handleChainRequest, | ||
| isChainRpcMethod | ||
| }; | ||
| //# sourceMappingURL=chunk-PU6NILFK.mjs.map |
| {"version":3,"sources":["../src/rpc-handler.ts"],"sourcesContent":["import { assert } from '@metamask/superstruct';\nimport { JsonRpcRequestStruct } from '@metamask/utils';\nimport type { Json, JsonRpcRequest, CaipChainId } from '@metamask/utils';\n\nimport type { Chain } from './api';\nimport { GetBalancesRequestStruct } from './rpc-types';\n\n/**\n * Chain RPC methods.\n */\nexport enum ChainRpcMethod {\n GetBalances = 'chain_getBalances',\n}\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport declare class MethodNotSupportedError extends Error {\n constructor(method: string);\n}\n\n/**\n * Handles a chain JSON-RPC request.\n *\n * @param chain - Chain instance.\n * @param request - Chain JSON-RPC request.\n * @returns A promise that resolves to the chain's method response.\n */\nexport async function handleChainRequest(\n chain: Chain,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case ChainRpcMethod.GetBalances: {\n assert(request, GetBalancesRequestStruct);\n\n return chain.getBalances(\n request.params.scope as CaipChainId,\n request.params.accounts,\n request.params.assets,\n );\n }\n\n default:\n throw new MethodNotSupportedError(request.method);\n }\n}\n\n/**\n * Check if a method is a chain RPC method.\n *\n * @param method - Method to check.\n * @returns Whether the method is a chain RPC method.\n */\nexport function isChainRpcMethod(method: string): boolean {\n return Object.values(ChainRpcMethod).includes(method as ChainRpcMethod);\n}\n"],"mappings":";;;;;AAAA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AAS9B,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,iBAAc;AADJ,SAAAA;AAAA,GAAA;AAkBZ,eAAsB,mBACpB,OACA,SACsB;AAItB,SAAO,SAAS,oBAAoB;AAEpC,UAAQ,QAAQ,QAAQ;AAAA,IACtB,KAAK,uCAA4B;AAC/B,aAAO,SAAS,wBAAwB;AAExC,aAAO,MAAM;AAAA,QACX,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,MACjB;AAAA,IACF;AAAA,IAEA;AACE,YAAM,IAAI,wBAAwB,QAAQ,MAAM;AAAA,EACpD;AACF;AAQO,SAAS,iBAAiB,QAAyB;AACxD,SAAO,OAAO,OAAO,cAAc,EAAE,SAAS,MAAwB;AACxE;","names":["ChainRpcMethod"]} |
| // src/caip-types.ts | ||
| import { is, string, pattern } from "@metamask/superstruct"; | ||
| var 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; | ||
| var 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; | ||
| var 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; | ||
| var CaipAssetTypeStruct = pattern(string(), CAIP_ASSET_TYPE_REGEX); | ||
| var CaipAssetIdStruct = pattern(string(), CAIP_ASSET_ID_REGEX); | ||
| var CaipAssetTypeOrIdStruct = pattern( | ||
| string(), | ||
| CAIP_ASSET_TYPE_OR_ID_REGEX | ||
| ); | ||
| function isCaipAssetType(value) { | ||
| return is(value, CaipAssetTypeStruct); | ||
| } | ||
| function isCaipAssetId(value) { | ||
| return is(value, CaipAssetIdStruct); | ||
| } | ||
| function isCaipAssetTypeOrId(value) { | ||
| return is(value, CaipAssetTypeOrIdStruct); | ||
| } | ||
| export { | ||
| CAIP_ASSET_TYPE_REGEX, | ||
| CAIP_ASSET_ID_REGEX, | ||
| CAIP_ASSET_TYPE_OR_ID_REGEX, | ||
| CaipAssetTypeStruct, | ||
| CaipAssetIdStruct, | ||
| CaipAssetTypeOrIdStruct, | ||
| isCaipAssetType, | ||
| isCaipAssetId, | ||
| isCaipAssetTypeOrId | ||
| }; | ||
| //# sourceMappingURL=chunk-PZGXE4AQ.mjs.map |
| {"version":3,"sources":["../src/caip-types.ts"],"sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { is, string, pattern } from '@metamask/superstruct';\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<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;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<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;\n\nexport const CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<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;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset type identifier.\n */\nexport const CaipAssetTypeStruct = pattern(string(), CAIP_ASSET_TYPE_REGEX);\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID identifier.\n */\nexport const CaipAssetIdStruct = pattern(string(), CAIP_ASSET_ID_REGEX);\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = pattern(\n string(),\n CAIP_ASSET_TYPE_OR_ID_REGEX,\n);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetTypeOrId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetTypeOrId}.\n */\nexport function isCaipAssetTypeOrId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetTypeOrIdStruct);\n}\n"],"mappings":";AACA,SAAS,IAAI,QAAQ,eAAe;AAE7B,IAAM,wBACX;AAEK,IAAM,sBACX;AAEK,IAAM,8BACX;AAKK,IAAM,sBAAsB,QAAQ,OAAO,GAAG,qBAAqB;AAMnE,IAAM,oBAAoB,QAAQ,OAAO,GAAG,mBAAmB;AAM/D,IAAM,0BAA0B;AAAA,EACrC,OAAO;AAAA,EACP;AACF;AASO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,cAAc,OAAsC;AAClE,SAAO,GAAG,OAAO,iBAAiB;AACpC;AAQO,SAAS,oBAAoB,OAAsC;AACxE,SAAO,GAAG,OAAO,uBAAuB;AAC1C;","names":[]} |
| import { | ||
| CaipAssetTypeOrIdStruct | ||
| } from "./chunk-PZGXE4AQ.mjs"; | ||
| import { | ||
| StringNumberStruct | ||
| } from "./chunk-CGK6CF33.mjs"; | ||
| // src/rpc-types.ts | ||
| import { | ||
| record, | ||
| array, | ||
| union, | ||
| string, | ||
| number, | ||
| object, | ||
| literal | ||
| } from "@metamask/superstruct"; | ||
| import { CaipChainIdStruct } from "@metamask/utils"; | ||
| var AmountStruct = object({ | ||
| amount: StringNumberStruct | ||
| }); | ||
| var CommonHeader = { | ||
| jsonrpc: literal("2.0"), | ||
| id: union([string(), number(), literal(null)]) | ||
| }; | ||
| var GetBalancesRequestStruct = object({ | ||
| ...CommonHeader, | ||
| method: literal("chain_getBalances"), | ||
| params: object({ | ||
| scope: CaipChainIdStruct, | ||
| accounts: array(string()), | ||
| assets: array(CaipAssetTypeOrIdStruct) | ||
| }) | ||
| }); | ||
| var GetBalancesResponseStruct = object({ | ||
| balances: record(string(), record(CaipAssetTypeOrIdStruct, AmountStruct)) | ||
| }); | ||
| export { | ||
| AmountStruct, | ||
| GetBalancesRequestStruct, | ||
| GetBalancesResponseStruct | ||
| }; | ||
| //# sourceMappingURL=chunk-TMBZ25QJ.mjs.map |
| {"version":3,"sources":["../src/rpc-types.ts"],"sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n record,\n array,\n union,\n string,\n number,\n object,\n literal,\n} from '@metamask/superstruct';\nimport { CaipChainIdStruct } from '@metamask/utils';\n\nimport { CaipAssetTypeOrIdStruct } from './caip-types';\nimport { StringNumberStruct } from './types';\n\nexport const AmountStruct = object({\n amount: StringNumberStruct,\n});\n\nconst CommonHeader = {\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n};\n\n// ----------------------------------------------------------------------------\n// Get balances\n\nexport const GetBalancesRequestStruct = object({\n ...CommonHeader,\n method: literal('chain_getBalances'),\n params: object({\n scope: CaipChainIdStruct,\n accounts: array(string()),\n assets: array(CaipAssetTypeOrIdStruct),\n }),\n});\n\nexport type GetBalancesRequest = Infer<typeof GetBalancesRequestStruct>;\n\nexport const GetBalancesResponseStruct = object({\n balances: record(string(), record(CaipAssetTypeOrIdStruct, AmountStruct)),\n});\n\nexport type GetBalancesResponse = Infer<typeof GetBalancesResponseStruct>;\n"],"mappings":";;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAK3B,IAAM,eAAe,OAAO;AAAA,EACjC,QAAQ;AACV,CAAC;AAED,IAAM,eAAe;AAAA,EACnB,SAAS,QAAQ,KAAK;AAAA,EACtB,IAAI,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,QAAQ,IAAI,CAAC,CAAC;AAC/C;AAKO,IAAM,2BAA2B,OAAO;AAAA,EAC7C,GAAG;AAAA,EACH,QAAQ,QAAQ,mBAAmB;AAAA,EACnC,QAAQ,OAAO;AAAA,IACb,OAAO;AAAA,IACP,UAAU,MAAM,OAAO,CAAC;AAAA,IACxB,QAAQ,MAAM,uBAAuB;AAAA,EACvC,CAAC;AACH,CAAC;AAIM,IAAM,4BAA4B,OAAO;AAAA,EAC9C,UAAU,OAAO,OAAO,GAAG,OAAO,yBAAyB,YAAY,CAAC;AAC1E,CAAC;","names":[]} |
+13
-1
@@ -10,2 +10,13 @@ # Changelog | ||
| ## [0.1.0] | ||
| ### Changed | ||
| - Bump `@metamask/utils` from `^8.4.0` to `^9.0.0`. ([#5](https://github.com/MetaMask/accounts-chain-api/pull/5)) | ||
| ### Fixed | ||
| - Replace `superstruct` with ESM-compatible `@metamask/superstruct` `^3.1.0`. ([#5](https://github.com/MetaMask/accounts-chain-api/pull/5)) | ||
| - This fixes the issue of this package being unusable by any TypeScript project that uses `Node16` or `NodeNext` as its `moduleResolution` option. | ||
| ## [0.0.1] | ||
@@ -17,3 +28,4 @@ | ||
| [Unreleased]: https://github.com/MetaMask/chain-api/compare/v0.0.1...HEAD | ||
| [Unreleased]: https://github.com/MetaMask/chain-api/compare/v0.1.0...HEAD | ||
| [0.1.0]: https://github.com/MetaMask/chain-api/compare/v0.0.1...v0.1.0 | ||
| [0.0.1]: https://github.com/MetaMask/chain-api/releases/tag/v0.0.1 |
@@ -11,3 +11,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkJNI5ZQDXjs = require('./chunk-JNI5ZQDX.js'); | ||
| var _chunkFUNHCXU2js = require('./chunk-FUNHCXU2.js'); | ||
@@ -23,3 +23,3 @@ | ||
| exports.CAIP_ASSET_ID_REGEX = _chunkJNI5ZQDXjs.CAIP_ASSET_ID_REGEX; exports.CAIP_ASSET_TYPE_OR_ID_REGEX = _chunkJNI5ZQDXjs.CAIP_ASSET_TYPE_OR_ID_REGEX; exports.CAIP_ASSET_TYPE_REGEX = _chunkJNI5ZQDXjs.CAIP_ASSET_TYPE_REGEX; exports.CaipAssetIdStruct = _chunkJNI5ZQDXjs.CaipAssetIdStruct; exports.CaipAssetTypeOrIdStruct = _chunkJNI5ZQDXjs.CaipAssetTypeOrIdStruct; exports.CaipAssetTypeStruct = _chunkJNI5ZQDXjs.CaipAssetTypeStruct; exports.isCaipAssetId = _chunkJNI5ZQDXjs.isCaipAssetId; exports.isCaipAssetType = _chunkJNI5ZQDXjs.isCaipAssetType; exports.isCaipAssetTypeOrId = _chunkJNI5ZQDXjs.isCaipAssetTypeOrId; | ||
| exports.CAIP_ASSET_ID_REGEX = _chunkFUNHCXU2js.CAIP_ASSET_ID_REGEX; exports.CAIP_ASSET_TYPE_OR_ID_REGEX = _chunkFUNHCXU2js.CAIP_ASSET_TYPE_OR_ID_REGEX; exports.CAIP_ASSET_TYPE_REGEX = _chunkFUNHCXU2js.CAIP_ASSET_TYPE_REGEX; exports.CaipAssetIdStruct = _chunkFUNHCXU2js.CaipAssetIdStruct; exports.CaipAssetTypeOrIdStruct = _chunkFUNHCXU2js.CaipAssetTypeOrIdStruct; exports.CaipAssetTypeStruct = _chunkFUNHCXU2js.CaipAssetTypeStruct; exports.isCaipAssetId = _chunkFUNHCXU2js.isCaipAssetId; exports.isCaipAssetType = _chunkFUNHCXU2js.isCaipAssetType; exports.isCaipAssetTypeOrId = _chunkFUNHCXU2js.isCaipAssetTypeOrId; | ||
| //# sourceMappingURL=caip-types.js.map |
@@ -11,3 +11,3 @@ import { | ||
| isCaipAssetTypeOrId | ||
| } from "./chunk-Y33T5W46.mjs"; | ||
| } from "./chunk-PZGXE4AQ.mjs"; | ||
| export { | ||
@@ -14,0 +14,0 @@ CAIP_ASSET_ID_REGEX, |
+6
-6
@@ -6,3 +6,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-4MAA3KLV.js'); | ||
| var _chunkYHSUFBASjs = require('./chunk-YHSUFBAS.js'); | ||
| var _chunkCMZV35YPjs = require('./chunk-CMZV35YP.js'); | ||
@@ -12,3 +12,3 @@ | ||
| var _chunk5TYRSDVJjs = require('./chunk-5TYRSDVJ.js'); | ||
| var _chunkIZ77AXT7js = require('./chunk-IZ77AXT7.js'); | ||
@@ -24,7 +24,7 @@ | ||
| var _chunkJNI5ZQDXjs = require('./chunk-JNI5ZQDX.js'); | ||
| var _chunkFUNHCXU2js = require('./chunk-FUNHCXU2.js'); | ||
| var _chunkJ5UWEAM3js = require('./chunk-J5UWEAM3.js'); | ||
| require('./chunk-W446WQXY.js'); | ||
| var _chunkJKMEWU6Jjs = require('./chunk-JKMEWU6J.js'); | ||
| require('./chunk-JYVEPTYA.js'); | ||
@@ -47,3 +47,3 @@ | ||
| exports.AmountStruct = _chunk5TYRSDVJjs.AmountStruct; exports.CAIP_ASSET_ID_REGEX = _chunkJNI5ZQDXjs.CAIP_ASSET_ID_REGEX; exports.CAIP_ASSET_TYPE_OR_ID_REGEX = _chunkJNI5ZQDXjs.CAIP_ASSET_TYPE_OR_ID_REGEX; exports.CAIP_ASSET_TYPE_REGEX = _chunkJNI5ZQDXjs.CAIP_ASSET_TYPE_REGEX; exports.CaipAssetIdStruct = _chunkJNI5ZQDXjs.CaipAssetIdStruct; exports.CaipAssetTypeOrIdStruct = _chunkJNI5ZQDXjs.CaipAssetTypeOrIdStruct; exports.CaipAssetTypeStruct = _chunkJNI5ZQDXjs.CaipAssetTypeStruct; exports.ChainRpcMethod = _chunkYHSUFBASjs.ChainRpcMethod; exports.GetBalancesRequestStruct = _chunk5TYRSDVJjs.GetBalancesRequestStruct; exports.GetBalancesResponseStruct = _chunk5TYRSDVJjs.GetBalancesResponseStruct; exports.StringNumberStruct = _chunkJ5UWEAM3js.StringNumberStruct; exports.handleChainRequest = _chunkYHSUFBASjs.handleChainRequest; exports.isCaipAssetId = _chunkJNI5ZQDXjs.isCaipAssetId; exports.isCaipAssetType = _chunkJNI5ZQDXjs.isCaipAssetType; exports.isCaipAssetTypeOrId = _chunkJNI5ZQDXjs.isCaipAssetTypeOrId; exports.isChainRpcMethod = _chunkYHSUFBASjs.isChainRpcMethod; | ||
| exports.AmountStruct = _chunkIZ77AXT7js.AmountStruct; exports.CAIP_ASSET_ID_REGEX = _chunkFUNHCXU2js.CAIP_ASSET_ID_REGEX; exports.CAIP_ASSET_TYPE_OR_ID_REGEX = _chunkFUNHCXU2js.CAIP_ASSET_TYPE_OR_ID_REGEX; exports.CAIP_ASSET_TYPE_REGEX = _chunkFUNHCXU2js.CAIP_ASSET_TYPE_REGEX; exports.CaipAssetIdStruct = _chunkFUNHCXU2js.CaipAssetIdStruct; exports.CaipAssetTypeOrIdStruct = _chunkFUNHCXU2js.CaipAssetTypeOrIdStruct; exports.CaipAssetTypeStruct = _chunkFUNHCXU2js.CaipAssetTypeStruct; exports.ChainRpcMethod = _chunkCMZV35YPjs.ChainRpcMethod; exports.GetBalancesRequestStruct = _chunkIZ77AXT7js.GetBalancesRequestStruct; exports.GetBalancesResponseStruct = _chunkIZ77AXT7js.GetBalancesResponseStruct; exports.StringNumberStruct = _chunkJKMEWU6Jjs.StringNumberStruct; exports.handleChainRequest = _chunkCMZV35YPjs.handleChainRequest; exports.isCaipAssetId = _chunkFUNHCXU2js.isCaipAssetId; exports.isCaipAssetType = _chunkFUNHCXU2js.isCaipAssetType; exports.isCaipAssetTypeOrId = _chunkFUNHCXU2js.isCaipAssetTypeOrId; exports.isChainRpcMethod = _chunkCMZV35YPjs.isChainRpcMethod; | ||
| //# sourceMappingURL=index.js.map |
+5
-5
@@ -6,3 +6,3 @@ import "./chunk-GYJMRBUB.mjs"; | ||
| isChainRpcMethod | ||
| } from "./chunk-OB7ZHYEO.mjs"; | ||
| } from "./chunk-PU6NILFK.mjs"; | ||
| import { | ||
@@ -12,3 +12,3 @@ AmountStruct, | ||
| GetBalancesResponseStruct | ||
| } from "./chunk-LJHB3G6D.mjs"; | ||
| } from "./chunk-TMBZ25QJ.mjs"; | ||
| import { | ||
@@ -24,7 +24,7 @@ CAIP_ASSET_ID_REGEX, | ||
| isCaipAssetTypeOrId | ||
| } from "./chunk-Y33T5W46.mjs"; | ||
| } from "./chunk-PZGXE4AQ.mjs"; | ||
| import { | ||
| StringNumberStruct | ||
| } from "./chunk-HWAV6IUV.mjs"; | ||
| import "./chunk-KPMRSMOC.mjs"; | ||
| } from "./chunk-CGK6CF33.mjs"; | ||
| import "./chunk-GIDWNBZF.mjs"; | ||
| export { | ||
@@ -31,0 +31,0 @@ AmountStruct, |
@@ -5,7 +5,7 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkYHSUFBASjs = require('./chunk-YHSUFBAS.js'); | ||
| require('./chunk-5TYRSDVJ.js'); | ||
| require('./chunk-JNI5ZQDX.js'); | ||
| require('./chunk-J5UWEAM3.js'); | ||
| require('./chunk-W446WQXY.js'); | ||
| var _chunkCMZV35YPjs = require('./chunk-CMZV35YP.js'); | ||
| require('./chunk-IZ77AXT7.js'); | ||
| require('./chunk-FUNHCXU2.js'); | ||
| require('./chunk-JKMEWU6J.js'); | ||
| require('./chunk-JYVEPTYA.js'); | ||
@@ -15,3 +15,3 @@ | ||
| exports.ChainRpcMethod = _chunkYHSUFBASjs.ChainRpcMethod; exports.handleChainRequest = _chunkYHSUFBASjs.handleChainRequest; exports.isChainRpcMethod = _chunkYHSUFBASjs.isChainRpcMethod; | ||
| exports.ChainRpcMethod = _chunkCMZV35YPjs.ChainRpcMethod; exports.handleChainRequest = _chunkCMZV35YPjs.handleChainRequest; exports.isChainRpcMethod = _chunkCMZV35YPjs.isChainRpcMethod; | ||
| //# sourceMappingURL=rpc-handler.js.map |
@@ -5,7 +5,7 @@ import { | ||
| isChainRpcMethod | ||
| } from "./chunk-OB7ZHYEO.mjs"; | ||
| import "./chunk-LJHB3G6D.mjs"; | ||
| import "./chunk-Y33T5W46.mjs"; | ||
| import "./chunk-HWAV6IUV.mjs"; | ||
| import "./chunk-KPMRSMOC.mjs"; | ||
| } from "./chunk-PU6NILFK.mjs"; | ||
| import "./chunk-TMBZ25QJ.mjs"; | ||
| import "./chunk-PZGXE4AQ.mjs"; | ||
| import "./chunk-CGK6CF33.mjs"; | ||
| import "./chunk-GIDWNBZF.mjs"; | ||
| export { | ||
@@ -12,0 +12,0 @@ ChainRpcMethod, |
@@ -5,6 +5,6 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5TYRSDVJjs = require('./chunk-5TYRSDVJ.js'); | ||
| require('./chunk-JNI5ZQDX.js'); | ||
| require('./chunk-J5UWEAM3.js'); | ||
| require('./chunk-W446WQXY.js'); | ||
| var _chunkIZ77AXT7js = require('./chunk-IZ77AXT7.js'); | ||
| require('./chunk-FUNHCXU2.js'); | ||
| require('./chunk-JKMEWU6J.js'); | ||
| require('./chunk-JYVEPTYA.js'); | ||
@@ -14,3 +14,3 @@ | ||
| exports.AmountStruct = _chunk5TYRSDVJjs.AmountStruct; exports.GetBalancesRequestStruct = _chunk5TYRSDVJjs.GetBalancesRequestStruct; exports.GetBalancesResponseStruct = _chunk5TYRSDVJjs.GetBalancesResponseStruct; | ||
| exports.AmountStruct = _chunkIZ77AXT7js.AmountStruct; exports.GetBalancesRequestStruct = _chunkIZ77AXT7js.GetBalancesRequestStruct; exports.GetBalancesResponseStruct = _chunkIZ77AXT7js.GetBalancesResponseStruct; | ||
| //# sourceMappingURL=rpc-types.js.map |
@@ -5,6 +5,6 @@ import { | ||
| GetBalancesResponseStruct | ||
| } from "./chunk-LJHB3G6D.mjs"; | ||
| import "./chunk-Y33T5W46.mjs"; | ||
| import "./chunk-HWAV6IUV.mjs"; | ||
| import "./chunk-KPMRSMOC.mjs"; | ||
| } from "./chunk-TMBZ25QJ.mjs"; | ||
| import "./chunk-PZGXE4AQ.mjs"; | ||
| import "./chunk-CGK6CF33.mjs"; | ||
| import "./chunk-GIDWNBZF.mjs"; | ||
| export { | ||
@@ -11,0 +11,0 @@ AmountStruct, |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkW446WQXYjs = require('./chunk-W446WQXY.js'); | ||
| var _chunkJYVEPTYAjs = require('./chunk-JYVEPTYA.js'); | ||
| exports.definePattern = _chunkW446WQXYjs.definePattern; | ||
| exports.definePattern = _chunkJYVEPTYAjs.definePattern; | ||
| //# sourceMappingURL=superstruct.js.map |
| import { | ||
| definePattern | ||
| } from "./chunk-KPMRSMOC.mjs"; | ||
| } from "./chunk-GIDWNBZF.mjs"; | ||
| export { | ||
@@ -5,0 +5,0 @@ definePattern |
+3
-3
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkJ5UWEAM3js = require('./chunk-J5UWEAM3.js'); | ||
| require('./chunk-W446WQXY.js'); | ||
| var _chunkJKMEWU6Jjs = require('./chunk-JKMEWU6J.js'); | ||
| require('./chunk-JYVEPTYA.js'); | ||
| exports.StringNumberStruct = _chunkJ5UWEAM3js.StringNumberStruct; | ||
| exports.StringNumberStruct = _chunkJKMEWU6Jjs.StringNumberStruct; | ||
| //# sourceMappingURL=types.js.map |
+2
-2
| import { | ||
| StringNumberStruct | ||
| } from "./chunk-HWAV6IUV.mjs"; | ||
| import "./chunk-KPMRSMOC.mjs"; | ||
| } from "./chunk-CGK6CF33.mjs"; | ||
| import "./chunk-GIDWNBZF.mjs"; | ||
| export { | ||
@@ -6,0 +6,0 @@ StringNumberStruct |
@@ -1,2 +0,2 @@ | ||
| import type { Infer } from 'superstruct'; | ||
| import type { Infer } from '@metamask/superstruct'; | ||
| export declare const CAIP_ASSET_TYPE_REGEX: RegExp; | ||
@@ -8,3 +8,3 @@ export declare const CAIP_ASSET_ID_REGEX: RegExp; | ||
| */ | ||
| export declare const CaipAssetTypeStruct: import("superstruct").Struct<string, null>; | ||
| export declare const CaipAssetTypeStruct: import("@metamask/superstruct").Struct<string, null>; | ||
| export declare type CaipAssetType = Infer<typeof CaipAssetTypeStruct>; | ||
@@ -14,3 +14,3 @@ /** | ||
| */ | ||
| export declare const CaipAssetIdStruct: import("superstruct").Struct<string, null>; | ||
| export declare const CaipAssetIdStruct: import("@metamask/superstruct").Struct<string, null>; | ||
| export declare type CaipAssetId = Infer<typeof CaipAssetIdStruct>; | ||
@@ -20,3 +20,3 @@ /** | ||
| */ | ||
| export declare const CaipAssetTypeOrIdStruct: import("superstruct").Struct<string, null>; | ||
| export declare const CaipAssetTypeOrIdStruct: import("@metamask/superstruct").Struct<string, null>; | ||
| export declare type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>; | ||
@@ -23,0 +23,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"caip-types.d.ts","sourceRoot":"","sources":["../../src/caip-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,eAAO,MAAM,qBAAqB,QAC2H,CAAC;AAE9J,eAAO,MAAM,mBAAmB,QAC+J,CAAC;AAEhM,eAAO,MAAM,2BAA2B,QAC0J,CAAC;AAEnM;;GAEG;AACH,eAAO,MAAM,mBAAmB,4CAA2C,CAAC;AAC5E,oBAAY,aAAa,GAAG,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,iBAAiB,4CAAyC,CAAC;AACxE,oBAAY,WAAW,GAAG,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,uBAAuB,4CAGnC,CAAC;AACF,oBAAY,iBAAiB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEtE;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAExE"} | ||
| {"version":3,"file":"caip-types.d.ts","sourceRoot":"","sources":["../../src/caip-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGnD,eAAO,MAAM,qBAAqB,QAC2H,CAAC;AAE9J,eAAO,MAAM,mBAAmB,QAC+J,CAAC;AAEhM,eAAO,MAAM,2BAA2B,QAC0J,CAAC;AAEnM;;GAEG;AACH,eAAO,MAAM,mBAAmB,sDAA2C,CAAC;AAC5E,oBAAY,aAAa,GAAG,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,iBAAiB,sDAAyC,CAAC;AACxE,oBAAY,WAAW,GAAG,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,uBAAuB,sDAGnC,CAAC;AACF,oBAAY,iBAAiB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEtE;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAExE"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"rpc-handler.d.ts","sourceRoot":"","sources":["../../src/rpc-handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAe,MAAM,iBAAiB,CAAC;AAGzE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAGnC;;GAEG;AACH,oBAAY,cAAc;IACxB,WAAW,sBAAsB;CAClC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,KAAK;gBAC5C,MAAM,EAAE,MAAM;CAC3B;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAoBtB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAExD"} | ||
| {"version":3,"file":"rpc-handler.d.ts","sourceRoot":"","sources":["../../src/rpc-handler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAe,MAAM,iBAAiB,CAAC;AAEzE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAGnC;;GAEG;AACH,oBAAY,cAAc;IACxB,WAAW,sBAAsB;CAClC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,KAAK;gBAC5C,MAAM,EAAE,MAAM;CAC3B;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAoBtB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAExD"} |
@@ -1,8 +0,8 @@ | ||
| import type { Infer } from 'superstruct'; | ||
| export declare const AmountStruct: import("superstruct").Struct<{ | ||
| import type { Infer } from '@metamask/superstruct'; | ||
| export declare const AmountStruct: import("@metamask/superstruct").Struct<{ | ||
| amount: string; | ||
| }, { | ||
| amount: import("superstruct").Struct<string, null>; | ||
| amount: import("@metamask/superstruct").Struct<string, null>; | ||
| }>; | ||
| export declare const GetBalancesRequestStruct: import("superstruct").Struct<{ | ||
| export declare const GetBalancesRequestStruct: import("@metamask/superstruct").Struct<{ | ||
| id: string | number | null; | ||
@@ -17,4 +17,4 @@ method: "chain_getBalances"; | ||
| }, { | ||
| method: import("superstruct").Struct<"chain_getBalances", "chain_getBalances">; | ||
| params: import("superstruct").Struct<{ | ||
| method: import("@metamask/superstruct").Struct<"chain_getBalances", "chain_getBalances">; | ||
| params: import("@metamask/superstruct").Struct<{ | ||
| scope: string; | ||
@@ -24,11 +24,11 @@ accounts: string[]; | ||
| }, { | ||
| scope: import("superstruct").Struct<string, null>; | ||
| accounts: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>; | ||
| assets: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>; | ||
| scope: import("@metamask/superstruct").Struct<string, null>; | ||
| accounts: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>; | ||
| assets: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>; | ||
| }>; | ||
| jsonrpc: import("superstruct").Struct<"2.0", "2.0">; | ||
| id: import("superstruct").Struct<string | number | null, null>; | ||
| jsonrpc: import("@metamask/superstruct").Struct<"2.0", "2.0">; | ||
| id: import("@metamask/superstruct").Struct<string | number | null, null>; | ||
| }>; | ||
| export declare type GetBalancesRequest = Infer<typeof GetBalancesRequestStruct>; | ||
| export declare const GetBalancesResponseStruct: import("superstruct").Struct<{ | ||
| export declare const GetBalancesResponseStruct: import("@metamask/superstruct").Struct<{ | ||
| balances: Record<string, Record<string, { | ||
@@ -38,3 +38,3 @@ amount: string; | ||
| }, { | ||
| balances: import("superstruct").Struct<Record<string, Record<string, { | ||
| balances: import("@metamask/superstruct").Struct<Record<string, Record<string, { | ||
| amount: string; | ||
@@ -41,0 +41,0 @@ }>>, null>; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"rpc-types.d.ts","sourceRoot":"","sources":["../../src/rpc-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAczC,eAAO,MAAM,YAAY;;;;EAEvB,CAAC;AAUH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;EAQnC,CAAC;AAEH,oBAAY,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAExE,eAAO,MAAM,yBAAyB;;;;;;;;EAEpC,CAAC;AAEH,oBAAY,mBAAmB,GAAG,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC"} | ||
| {"version":3,"file":"rpc-types.d.ts","sourceRoot":"","sources":["../../src/rpc-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAenD,eAAO,MAAM,YAAY;;;;EAEvB,CAAC;AAUH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;EAQnC,CAAC;AAEH,oBAAY,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAExE,eAAO,MAAM,yBAAyB;;;;;;;;EAEpC,CAAC;AAEH,oBAAY,mBAAmB,GAAG,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC"} |
@@ -1,2 +0,2 @@ | ||
| import type { Struct } from 'superstruct'; | ||
| import type { Struct } from '@metamask/superstruct'; | ||
| /** | ||
@@ -3,0 +3,0 @@ * Defines a new string-struct matching a regular expression. |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"superstruct.d.ts","sourceRoot":"","sources":["../../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAMtB"} | ||
| {"version":3,"file":"superstruct.d.ts","sourceRoot":"","sources":["../../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAMtB"} |
@@ -1,4 +0,4 @@ | ||
| import type { Infer } from 'superstruct'; | ||
| import type { Infer } from '@metamask/superstruct'; | ||
| import type { CaipAssetType } from './caip-types'; | ||
| export declare const StringNumberStruct: import("superstruct").Struct<string, null>; | ||
| export declare const StringNumberStruct: import("@metamask/superstruct").Struct<string, null>; | ||
| export declare type StringNumber = Infer<typeof StringNumberStruct>; | ||
@@ -5,0 +5,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,eAAO,MAAM,kBAAkB,4CAG9B,CAAC;AACF,oBAAY,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5D;;GAEG;AACH,oBAAY,cAAc,GAAG;IAC3B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE;QAAE,MAAM,EAAE,YAAY,CAAA;KAAE,CAAC,CAAC,CAAC;CAC3E,CAAC"} | ||
| {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,eAAO,MAAM,kBAAkB,sDAG9B,CAAC;AACF,oBAAY,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5D;;GAEG;AACH,oBAAY,cAAc,GAAG;IAC3B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE;QAAE,MAAM,EAAE,YAAY,CAAA;KAAE,CAAC,CAAC,CAAC;CAC3E,CAAC"} |
+3
-6
| { | ||
| "name": "@metamask/chain-api", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "The MetaMask chain-agnostic API", | ||
@@ -43,8 +43,5 @@ "homepage": "https://github.com/MetaMask/chain-api#readme", | ||
| }, | ||
| "resolutions": { | ||
| "superstruct@^1.0.3": "1.0.3" | ||
| }, | ||
| "dependencies": { | ||
| "@metamask/utils": "^8.4.0", | ||
| "superstruct": "1.0.3" | ||
| "@metamask/superstruct": "^3.1.0", | ||
| "@metamask/utils": "^9.0.0" | ||
| }, | ||
@@ -51,0 +48,0 @@ "devDependencies": { |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkJNI5ZQDXjs = require('./chunk-JNI5ZQDX.js'); | ||
| var _chunkJ5UWEAM3js = require('./chunk-J5UWEAM3.js'); | ||
| // src/rpc-types.ts | ||
| var _utils = require('@metamask/utils'); | ||
| var _superstruct = require('superstruct'); | ||
| var AmountStruct = _superstruct.object.call(void 0, { | ||
| amount: _chunkJ5UWEAM3js.StringNumberStruct | ||
| }); | ||
| var CommonHeader = { | ||
| jsonrpc: _superstruct.literal.call(void 0, "2.0"), | ||
| id: _superstruct.union.call(void 0, [_superstruct.string.call(void 0, ), _superstruct.number.call(void 0, ), _superstruct.literal.call(void 0, null)]) | ||
| }; | ||
| var GetBalancesRequestStruct = _superstruct.object.call(void 0, { | ||
| ...CommonHeader, | ||
| method: _superstruct.literal.call(void 0, "chain_getBalances"), | ||
| params: _superstruct.object.call(void 0, { | ||
| scope: _utils.CaipChainIdStruct, | ||
| accounts: _superstruct.array.call(void 0, _superstruct.string.call(void 0, )), | ||
| assets: _superstruct.array.call(void 0, _chunkJNI5ZQDXjs.CaipAssetTypeOrIdStruct) | ||
| }) | ||
| }); | ||
| var GetBalancesResponseStruct = _superstruct.object.call(void 0, { | ||
| balances: _superstruct.record.call(void 0, _superstruct.string.call(void 0, ), _superstruct.record.call(void 0, _chunkJNI5ZQDXjs.CaipAssetTypeOrIdStruct, AmountStruct)) | ||
| }); | ||
| exports.AmountStruct = AmountStruct; exports.GetBalancesRequestStruct = GetBalancesRequestStruct; exports.GetBalancesResponseStruct = GetBalancesResponseStruct; | ||
| //# sourceMappingURL=chunk-5TYRSDVJ.js.map |
| {"version":3,"sources":["../src/rpc-types.ts"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,yBAAyB;AAElC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKA,IAAM,eAAe,OAAO;AAAA,EACjC,QAAQ;AACV,CAAC;AAED,IAAM,eAAe;AAAA,EACnB,SAAS,QAAQ,KAAK;AAAA,EACtB,IAAI,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,QAAQ,IAAI,CAAC,CAAC;AAC/C;AAKO,IAAM,2BAA2B,OAAO;AAAA,EAC7C,GAAG;AAAA,EACH,QAAQ,QAAQ,mBAAmB;AAAA,EACnC,QAAQ,OAAO;AAAA,IACb,OAAO;AAAA,IACP,UAAU,MAAM,OAAO,CAAC;AAAA,IACxB,QAAQ,MAAM,uBAAuB;AAAA,EACvC,CAAC;AACH,CAAC;AAIM,IAAM,4BAA4B,OAAO;AAAA,EAC9C,UAAU,OAAO,OAAO,GAAG,OAAO,yBAAyB,YAAY,CAAC;AAC1E,CAAC","sourcesContent":["import { CaipChainIdStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n record,\n array,\n union,\n string,\n number,\n object,\n literal,\n} from 'superstruct';\n\nimport { CaipAssetTypeOrIdStruct } from './caip-types';\nimport { StringNumberStruct } from './types';\n\nexport const AmountStruct = object({\n amount: StringNumberStruct,\n});\n\nconst CommonHeader = {\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n};\n\n// ----------------------------------------------------------------------------\n// Get balances\n\nexport const GetBalancesRequestStruct = object({\n ...CommonHeader,\n method: literal('chain_getBalances'),\n params: object({\n scope: CaipChainIdStruct,\n accounts: array(string()),\n assets: array(CaipAssetTypeOrIdStruct),\n }),\n});\n\nexport type GetBalancesRequest = Infer<typeof GetBalancesRequestStruct>;\n\nexport const GetBalancesResponseStruct = object({\n balances: record(string(), record(CaipAssetTypeOrIdStruct, AmountStruct)),\n});\n\nexport type GetBalancesResponse = Infer<typeof GetBalancesResponseStruct>;\n"]} |
| import { | ||
| definePattern | ||
| } from "./chunk-KPMRSMOC.mjs"; | ||
| // src/types.ts | ||
| var StringNumberStruct = definePattern( | ||
| "StringNumber", | ||
| /^[0-9]+(\.[0-9]+)?$/u | ||
| ); | ||
| export { | ||
| StringNumberStruct | ||
| }; | ||
| //# sourceMappingURL=chunk-HWAV6IUV.mjs.map |
| {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\n\nimport type { CaipAssetType } from './caip-types';\nimport { definePattern } from './superstruct';\n\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^[0-9]+(\\.[0-9]+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n\n/**\n * Result object for assets balances.\n */\nexport type BalancesResult = {\n balances: Record<string, Record<CaipAssetType, { amount: StringNumber }>>;\n};\n"],"mappings":";;;;;AAKO,IAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AACF;","names":[]} |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkW446WQXYjs = require('./chunk-W446WQXY.js'); | ||
| // src/types.ts | ||
| var StringNumberStruct = _chunkW446WQXYjs.definePattern.call(void 0, | ||
| "StringNumber", | ||
| /^[0-9]+(\.[0-9]+)?$/u | ||
| ); | ||
| exports.StringNumberStruct = StringNumberStruct; | ||
| //# sourceMappingURL=chunk-J5UWEAM3.js.map |
| {"version":3,"sources":["../src/types.ts"],"names":[],"mappings":";;;;;AAKO,IAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AACF","sourcesContent":["import type { Infer } from 'superstruct';\n\nimport type { CaipAssetType } from './caip-types';\nimport { definePattern } from './superstruct';\n\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^[0-9]+(\\.[0-9]+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n\n/**\n * Result object for assets balances.\n */\nexport type BalancesResult = {\n balances: Record<string, Record<CaipAssetType, { amount: StringNumber }>>;\n};\n"]} |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/caip-types.ts | ||
| var _superstruct = require('superstruct'); | ||
| var 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; | ||
| var 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; | ||
| var 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; | ||
| var CaipAssetTypeStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_ASSET_TYPE_REGEX); | ||
| var CaipAssetIdStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_ASSET_ID_REGEX); | ||
| var CaipAssetTypeOrIdStruct = _superstruct.pattern.call(void 0, | ||
| _superstruct.string.call(void 0, ), | ||
| CAIP_ASSET_TYPE_OR_ID_REGEX | ||
| ); | ||
| function isCaipAssetType(value) { | ||
| return _superstruct.is.call(void 0, value, CaipAssetTypeStruct); | ||
| } | ||
| function isCaipAssetId(value) { | ||
| return _superstruct.is.call(void 0, value, CaipAssetIdStruct); | ||
| } | ||
| function isCaipAssetTypeOrId(value) { | ||
| return _superstruct.is.call(void 0, value, CaipAssetTypeOrIdStruct); | ||
| } | ||
| exports.CAIP_ASSET_TYPE_REGEX = CAIP_ASSET_TYPE_REGEX; exports.CAIP_ASSET_ID_REGEX = CAIP_ASSET_ID_REGEX; exports.CAIP_ASSET_TYPE_OR_ID_REGEX = CAIP_ASSET_TYPE_OR_ID_REGEX; exports.CaipAssetTypeStruct = CaipAssetTypeStruct; exports.CaipAssetIdStruct = CaipAssetIdStruct; exports.CaipAssetTypeOrIdStruct = CaipAssetTypeOrIdStruct; exports.isCaipAssetType = isCaipAssetType; exports.isCaipAssetId = isCaipAssetId; exports.isCaipAssetTypeOrId = isCaipAssetTypeOrId; | ||
| //# sourceMappingURL=chunk-JNI5ZQDX.js.map |
| {"version":3,"sources":["../src/caip-types.ts"],"names":[],"mappings":";AACA,SAAS,IAAI,QAAQ,eAAe;AAE7B,IAAM,wBACX;AAEK,IAAM,sBACX;AAEK,IAAM,8BACX;AAKK,IAAM,sBAAsB,QAAQ,OAAO,GAAG,qBAAqB;AAMnE,IAAM,oBAAoB,QAAQ,OAAO,GAAG,mBAAmB;AAM/D,IAAM,0BAA0B;AAAA,EACrC,OAAO;AAAA,EACP;AACF;AASO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,cAAc,OAAsC;AAClE,SAAO,GAAG,OAAO,iBAAiB;AACpC;AAQO,SAAS,oBAAoB,OAAsC;AACxE,SAAO,GAAG,OAAO,uBAAuB;AAC1C","sourcesContent":["import type { Infer } from 'superstruct';\nimport { is, string, pattern } from 'superstruct';\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<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;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<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;\n\nexport const CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<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;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset type identifier.\n */\nexport const CaipAssetTypeStruct = pattern(string(), CAIP_ASSET_TYPE_REGEX);\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID identifier.\n */\nexport const CaipAssetIdStruct = pattern(string(), CAIP_ASSET_ID_REGEX);\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = pattern(\n string(),\n CAIP_ASSET_TYPE_OR_ID_REGEX,\n);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetTypeOrId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetTypeOrId}.\n */\nexport function isCaipAssetTypeOrId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetTypeOrIdStruct);\n}\n"]} |
| // src/superstruct.ts | ||
| import { define } from "superstruct"; | ||
| function definePattern(name, pattern) { | ||
| return define( | ||
| name, | ||
| (value) => typeof value === "string" && pattern.test(value) | ||
| ); | ||
| } | ||
| export { | ||
| definePattern | ||
| }; | ||
| //# sourceMappingURL=chunk-KPMRSMOC.mjs.map |
| {"version":3,"sources":["../src/superstruct.ts"],"sourcesContent":["import type { Struct } from 'superstruct';\nimport { define } from 'superstruct';\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n"],"mappings":";AACA,SAAS,cAAc;AAehB,SAAS,cACd,MACA,SACsB;AACtB,SAAO;AAAA,IACL;AAAA,IACA,CAAC,UACC,OAAO,UAAU,YAAY,QAAQ,KAAK,KAAK;AAAA,EACnD;AACF;","names":[]} |
| import { | ||
| CaipAssetTypeOrIdStruct | ||
| } from "./chunk-Y33T5W46.mjs"; | ||
| import { | ||
| StringNumberStruct | ||
| } from "./chunk-HWAV6IUV.mjs"; | ||
| // src/rpc-types.ts | ||
| import { CaipChainIdStruct } from "@metamask/utils"; | ||
| import { | ||
| record, | ||
| array, | ||
| union, | ||
| string, | ||
| number, | ||
| object, | ||
| literal | ||
| } from "superstruct"; | ||
| var AmountStruct = object({ | ||
| amount: StringNumberStruct | ||
| }); | ||
| var CommonHeader = { | ||
| jsonrpc: literal("2.0"), | ||
| id: union([string(), number(), literal(null)]) | ||
| }; | ||
| var GetBalancesRequestStruct = object({ | ||
| ...CommonHeader, | ||
| method: literal("chain_getBalances"), | ||
| params: object({ | ||
| scope: CaipChainIdStruct, | ||
| accounts: array(string()), | ||
| assets: array(CaipAssetTypeOrIdStruct) | ||
| }) | ||
| }); | ||
| var GetBalancesResponseStruct = object({ | ||
| balances: record(string(), record(CaipAssetTypeOrIdStruct, AmountStruct)) | ||
| }); | ||
| export { | ||
| AmountStruct, | ||
| GetBalancesRequestStruct, | ||
| GetBalancesResponseStruct | ||
| }; | ||
| //# sourceMappingURL=chunk-LJHB3G6D.mjs.map |
| {"version":3,"sources":["../src/rpc-types.ts"],"sourcesContent":["import { CaipChainIdStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n record,\n array,\n union,\n string,\n number,\n object,\n literal,\n} from 'superstruct';\n\nimport { CaipAssetTypeOrIdStruct } from './caip-types';\nimport { StringNumberStruct } from './types';\n\nexport const AmountStruct = object({\n amount: StringNumberStruct,\n});\n\nconst CommonHeader = {\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n};\n\n// ----------------------------------------------------------------------------\n// Get balances\n\nexport const GetBalancesRequestStruct = object({\n ...CommonHeader,\n method: literal('chain_getBalances'),\n params: object({\n scope: CaipChainIdStruct,\n accounts: array(string()),\n assets: array(CaipAssetTypeOrIdStruct),\n }),\n});\n\nexport type GetBalancesRequest = Infer<typeof GetBalancesRequestStruct>;\n\nexport const GetBalancesResponseStruct = object({\n balances: record(string(), record(CaipAssetTypeOrIdStruct, AmountStruct)),\n});\n\nexport type GetBalancesResponse = Infer<typeof GetBalancesResponseStruct>;\n"],"mappings":";;;;;;;;AAAA,SAAS,yBAAyB;AAElC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKA,IAAM,eAAe,OAAO;AAAA,EACjC,QAAQ;AACV,CAAC;AAED,IAAM,eAAe;AAAA,EACnB,SAAS,QAAQ,KAAK;AAAA,EACtB,IAAI,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,QAAQ,IAAI,CAAC,CAAC;AAC/C;AAKO,IAAM,2BAA2B,OAAO;AAAA,EAC7C,GAAG;AAAA,EACH,QAAQ,QAAQ,mBAAmB;AAAA,EACnC,QAAQ,OAAO;AAAA,IACb,OAAO;AAAA,IACP,UAAU,MAAM,OAAO,CAAC;AAAA,IACxB,QAAQ,MAAM,uBAAuB;AAAA,EACvC,CAAC;AACH,CAAC;AAIM,IAAM,4BAA4B,OAAO;AAAA,EAC9C,UAAU,OAAO,OAAO,GAAG,OAAO,yBAAyB,YAAY,CAAC;AAC1E,CAAC;","names":[]} |
| import { | ||
| GetBalancesRequestStruct | ||
| } from "./chunk-LJHB3G6D.mjs"; | ||
| // src/rpc-handler.ts | ||
| import { JsonRpcRequestStruct } from "@metamask/utils"; | ||
| import { assert } from "superstruct"; | ||
| var ChainRpcMethod = /* @__PURE__ */ ((ChainRpcMethod2) => { | ||
| ChainRpcMethod2["GetBalances"] = "chain_getBalances"; | ||
| return ChainRpcMethod2; | ||
| })(ChainRpcMethod || {}); | ||
| async function handleChainRequest(chain, request) { | ||
| assert(request, JsonRpcRequestStruct); | ||
| switch (request.method) { | ||
| case "chain_getBalances" /* GetBalances */: { | ||
| assert(request, GetBalancesRequestStruct); | ||
| return chain.getBalances( | ||
| request.params.scope, | ||
| request.params.accounts, | ||
| request.params.assets | ||
| ); | ||
| } | ||
| default: | ||
| throw new MethodNotSupportedError(request.method); | ||
| } | ||
| } | ||
| function isChainRpcMethod(method) { | ||
| return Object.values(ChainRpcMethod).includes(method); | ||
| } | ||
| export { | ||
| ChainRpcMethod, | ||
| handleChainRequest, | ||
| isChainRpcMethod | ||
| }; | ||
| //# sourceMappingURL=chunk-OB7ZHYEO.mjs.map |
| {"version":3,"sources":["../src/rpc-handler.ts"],"sourcesContent":["import { JsonRpcRequestStruct } from '@metamask/utils';\nimport type { Json, JsonRpcRequest, CaipChainId } from '@metamask/utils';\nimport { assert } from 'superstruct';\n\nimport type { Chain } from './api';\nimport { GetBalancesRequestStruct } from './rpc-types';\n\n/**\n * Chain RPC methods.\n */\nexport enum ChainRpcMethod {\n GetBalances = 'chain_getBalances',\n}\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport declare class MethodNotSupportedError extends Error {\n constructor(method: string);\n}\n\n/**\n * Handles a chain JSON-RPC request.\n *\n * @param chain - Chain instance.\n * @param request - Chain JSON-RPC request.\n * @returns A promise that resolves to the chain's method response.\n */\nexport async function handleChainRequest(\n chain: Chain,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case ChainRpcMethod.GetBalances: {\n assert(request, GetBalancesRequestStruct);\n\n return chain.getBalances(\n request.params.scope as CaipChainId,\n request.params.accounts,\n request.params.assets,\n );\n }\n\n default:\n throw new MethodNotSupportedError(request.method);\n }\n}\n\n/**\n * Check if a method is a chain RPC method.\n *\n * @param method - Method to check.\n * @returns Whether the method is a chain RPC method.\n */\nexport function isChainRpcMethod(method: string): boolean {\n return Object.values(ChainRpcMethod).includes(method as ChainRpcMethod);\n}\n"],"mappings":";;;;;AAAA,SAAS,4BAA4B;AAErC,SAAS,cAAc;AAQhB,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,iBAAc;AADJ,SAAAA;AAAA,GAAA;AAkBZ,eAAsB,mBACpB,OACA,SACsB;AAItB,SAAO,SAAS,oBAAoB;AAEpC,UAAQ,QAAQ,QAAQ;AAAA,IACtB,KAAK,uCAA4B;AAC/B,aAAO,SAAS,wBAAwB;AAExC,aAAO,MAAM;AAAA,QACX,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,MACjB;AAAA,IACF;AAAA,IAEA;AACE,YAAM,IAAI,wBAAwB,QAAQ,MAAM;AAAA,EACpD;AACF;AAQO,SAAS,iBAAiB,QAAyB;AACxD,SAAO,OAAO,OAAO,cAAc,EAAE,SAAS,MAAwB;AACxE;","names":["ChainRpcMethod"]} |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/superstruct.ts | ||
| var _superstruct = require('superstruct'); | ||
| function definePattern(name, pattern) { | ||
| return _superstruct.define.call(void 0, | ||
| name, | ||
| (value) => typeof value === "string" && pattern.test(value) | ||
| ); | ||
| } | ||
| exports.definePattern = definePattern; | ||
| //# sourceMappingURL=chunk-W446WQXY.js.map |
| {"version":3,"sources":["../src/superstruct.ts"],"names":[],"mappings":";AACA,SAAS,cAAc;AAehB,SAAS,cACd,MACA,SACsB;AACtB,SAAO;AAAA,IACL;AAAA,IACA,CAAC,UACC,OAAO,UAAU,YAAY,QAAQ,KAAK,KAAK;AAAA,EACnD;AACF","sourcesContent":["import type { Struct } from 'superstruct';\nimport { define } from 'superstruct';\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n"]} |
| // src/caip-types.ts | ||
| import { is, string, pattern } from "superstruct"; | ||
| var 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; | ||
| var 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; | ||
| var 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; | ||
| var CaipAssetTypeStruct = pattern(string(), CAIP_ASSET_TYPE_REGEX); | ||
| var CaipAssetIdStruct = pattern(string(), CAIP_ASSET_ID_REGEX); | ||
| var CaipAssetTypeOrIdStruct = pattern( | ||
| string(), | ||
| CAIP_ASSET_TYPE_OR_ID_REGEX | ||
| ); | ||
| function isCaipAssetType(value) { | ||
| return is(value, CaipAssetTypeStruct); | ||
| } | ||
| function isCaipAssetId(value) { | ||
| return is(value, CaipAssetIdStruct); | ||
| } | ||
| function isCaipAssetTypeOrId(value) { | ||
| return is(value, CaipAssetTypeOrIdStruct); | ||
| } | ||
| export { | ||
| CAIP_ASSET_TYPE_REGEX, | ||
| CAIP_ASSET_ID_REGEX, | ||
| CAIP_ASSET_TYPE_OR_ID_REGEX, | ||
| CaipAssetTypeStruct, | ||
| CaipAssetIdStruct, | ||
| CaipAssetTypeOrIdStruct, | ||
| isCaipAssetType, | ||
| isCaipAssetId, | ||
| isCaipAssetTypeOrId | ||
| }; | ||
| //# sourceMappingURL=chunk-Y33T5W46.mjs.map |
| {"version":3,"sources":["../src/caip-types.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { is, string, pattern } from 'superstruct';\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<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;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<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;\n\nexport const CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<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;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset type identifier.\n */\nexport const CaipAssetTypeStruct = pattern(string(), CAIP_ASSET_TYPE_REGEX);\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID identifier.\n */\nexport const CaipAssetIdStruct = pattern(string(), CAIP_ASSET_ID_REGEX);\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = pattern(\n string(),\n CAIP_ASSET_TYPE_OR_ID_REGEX,\n);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetTypeOrId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetTypeOrId}.\n */\nexport function isCaipAssetTypeOrId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetTypeOrIdStruct);\n}\n"],"mappings":";AACA,SAAS,IAAI,QAAQ,eAAe;AAE7B,IAAM,wBACX;AAEK,IAAM,sBACX;AAEK,IAAM,8BACX;AAKK,IAAM,sBAAsB,QAAQ,OAAO,GAAG,qBAAqB;AAMnE,IAAM,oBAAoB,QAAQ,OAAO,GAAG,mBAAmB;AAM/D,IAAM,0BAA0B;AAAA,EACrC,OAAO;AAAA,EACP;AACF;AASO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,cAAc,OAAsC;AAClE,SAAO,GAAG,OAAO,iBAAiB;AACpC;AAQO,SAAS,oBAAoB,OAAsC;AACxE,SAAO,GAAG,OAAO,uBAAuB;AAC1C;","names":[]} |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5TYRSDVJjs = require('./chunk-5TYRSDVJ.js'); | ||
| // src/rpc-handler.ts | ||
| var _utils = require('@metamask/utils'); | ||
| var _superstruct = require('superstruct'); | ||
| var ChainRpcMethod = /* @__PURE__ */ ((ChainRpcMethod2) => { | ||
| ChainRpcMethod2["GetBalances"] = "chain_getBalances"; | ||
| return ChainRpcMethod2; | ||
| })(ChainRpcMethod || {}); | ||
| async function handleChainRequest(chain, request) { | ||
| _superstruct.assert.call(void 0, request, _utils.JsonRpcRequestStruct); | ||
| switch (request.method) { | ||
| case "chain_getBalances" /* GetBalances */: { | ||
| _superstruct.assert.call(void 0, request, _chunk5TYRSDVJjs.GetBalancesRequestStruct); | ||
| return chain.getBalances( | ||
| request.params.scope, | ||
| request.params.accounts, | ||
| request.params.assets | ||
| ); | ||
| } | ||
| default: | ||
| throw new MethodNotSupportedError(request.method); | ||
| } | ||
| } | ||
| function isChainRpcMethod(method) { | ||
| return Object.values(ChainRpcMethod).includes(method); | ||
| } | ||
| exports.ChainRpcMethod = ChainRpcMethod; exports.handleChainRequest = handleChainRequest; exports.isChainRpcMethod = isChainRpcMethod; | ||
| //# sourceMappingURL=chunk-YHSUFBAS.js.map |
| {"version":3,"sources":["../src/rpc-handler.ts"],"names":["ChainRpcMethod"],"mappings":";;;;;AAAA,SAAS,4BAA4B;AAErC,SAAS,cAAc;AAQhB,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,iBAAc;AADJ,SAAAA;AAAA,GAAA;AAkBZ,eAAsB,mBACpB,OACA,SACsB;AAItB,SAAO,SAAS,oBAAoB;AAEpC,UAAQ,QAAQ,QAAQ;AAAA,IACtB,KAAK,uCAA4B;AAC/B,aAAO,SAAS,wBAAwB;AAExC,aAAO,MAAM;AAAA,QACX,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,MACjB;AAAA,IACF;AAAA,IAEA;AACE,YAAM,IAAI,wBAAwB,QAAQ,MAAM;AAAA,EACpD;AACF;AAQO,SAAS,iBAAiB,QAAyB;AACxD,SAAO,OAAO,OAAO,cAAc,EAAE,SAAS,MAAwB;AACxE","sourcesContent":["import { JsonRpcRequestStruct } from '@metamask/utils';\nimport type { Json, JsonRpcRequest, CaipChainId } from '@metamask/utils';\nimport { assert } from 'superstruct';\n\nimport type { Chain } from './api';\nimport { GetBalancesRequestStruct } from './rpc-types';\n\n/**\n * Chain RPC methods.\n */\nexport enum ChainRpcMethod {\n GetBalances = 'chain_getBalances',\n}\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport declare class MethodNotSupportedError extends Error {\n constructor(method: string);\n}\n\n/**\n * Handles a chain JSON-RPC request.\n *\n * @param chain - Chain instance.\n * @param request - Chain JSON-RPC request.\n * @returns A promise that resolves to the chain's method response.\n */\nexport async function handleChainRequest(\n chain: Chain,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case ChainRpcMethod.GetBalances: {\n assert(request, GetBalancesRequestStruct);\n\n return chain.getBalances(\n request.params.scope as CaipChainId,\n request.params.accounts,\n request.params.assets,\n );\n }\n\n default:\n throw new MethodNotSupportedError(request.method);\n }\n}\n\n/**\n * Check if a method is a chain RPC method.\n *\n * @param method - Method to check.\n * @returns Whether the method is a chain RPC method.\n */\nexport function isChainRpcMethod(method: string): boolean {\n return Object.values(ChainRpcMethod).includes(method as ChainRpcMethod);\n}\n"]} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
51834
1.83%1
Infinity%+ Added
+ Added
- Removed
- Removed
- Removed
Updated