Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@mysten/payment-kit

Package Overview
Dependencies
Maintainers
13
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mysten/payment-kit - npm Package Compare versions

Comparing version
0.1.3
to
0.1.4
+1
-1
dist/calls.d.mts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"calls.d.mts","names":[],"sources":["../src/calls.ts"],"sourcesContent":[],"mappings":";;;;UA0BiB,qBAAA;iBACD;;AADC,cAIJ,eAAA,CAJyB;EAIzB,CAAA,OAAA;EAGS,WAAA,CAAA,OAAA,EAAA,qBAAA;EAYc;;;;;;;;EAyDsB,sBAAA,EAAA,CAAA,OAAA,EAzDtB,6BAyDsB,EAAA,GAAA,CAAA,EAAA,EAzDO,yBAAA,CAAA,WAyDP,EAAA,GAzDO,yBAAA,CAAA,iBAyDP;EAAA;;;;;;;;EA2CxB,uBAAA,EAAA,CAAA,OAAA,EAtEG,8BAsEH,EAAA,GAAA,CAAA,EAAA,EAtEiC,yBAAA,CAAA,WAsEjC,EAAA,GAtEiC,yBAAA,CAAA,iBAsEjC;EAAA;;;;;;;;EA0BT,cAAA,EAAA,CAAA;IAAA;EAAA,CAAA,EArEY,qBAqEZ,EAAA,GAAA,CAAA,EAAA,EArEiC,yBAAA,CAAA,WAqEjC,EAAA,GArEiC,yBAAA,CAAA,iBAqEjC;EAAA;;;;;;;;EA0BD,gCAAA,EAAA,CAAA;IAAA,YAAA;IAAA,UAAA;IAAA,uBAAA;IAAA;EAAA,CAAA,EAzEpB,iCAyEoB,EAAA,GAAA,CAAA,EAAA,EAzEa,yBAAA,CAAA,WAyEb,EAAA,GAzEa,yBAAA,CAAA,iBAyEb;EAAA;;;;;;;;;;;;;KA/CpB,wCAA8B,yBAAA,CAAA,gBAAA,yBAAA,CAAA;;;;;;;;;;;;;;KA0B9B,qCAA2B,yBAAA,CAAA,gBAAA,yBAAA,C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A,WAAA,KAAA,yBAAA,CAAA,iBAAA;AAAA"}

@@ -1,1 +0,1 @@

{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"sourcesContent":[],"mappings":";;;;;;iBAsBgB;;AAAhB,CAAA;;AAAA,CAAA,CAAA,EAAgB;EAAwC,IAAA,MAAA;qBAGnC,sBAAiB;;AAAjB,cAMR,gBAAA,CANQ;EAAiB,CAAA,OAAA;EAAA,KAAA,EAU9B,eAV8B;EAMzB,EAAA,EAKR,sBALwB;EAIrB,WAAA,CAAA,OAAA,EAGc,uBAHd;EACH;;;;;;;;;4BAqCM,0BACP,QAAQ"}
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;iBAsBgB,UAAA,2BAAA,CAAA;EAAwC;AAAA;;;;qBAGnC,iBAAA,KAAiB,gBAAA;AAAA;AAAA,cAMzB,gBAAA;EAAA;EAIZ,KAAA,EAAO,eAAA;EACP,EAAA,EAAI,sBAAA;cAEQ,OAAA,EAAS,uBAAA;EAbgB;;;;;;;;;EA+C/B,gBAAA,CACL,OAAA,EAAS,uBAAA,GACP,OAAA,CAAQ,wBAAA;;;;;AA3CZ;;;;;EAoFC,qBAAA,CAAsB,YAAA;AAAA"}
//#region src/constants.d.ts
declare const DEFAULT_REGISTRY_NAME = "default-payment-registry";

@@ -4,0 +3,0 @@ declare const SUI_PAYMENT_KIT_PROTOCOL = "sui:pay";

@@ -1,1 +0,1 @@

{"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"sourcesContent":[],"mappings":";;cAiBa,qBAAA;cAEA,wBAAA"}
{"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";cAiBa,qBAAA;AAAA,cAEA,wBAAA"}

@@ -1,1 +0,1 @@

{"version":3,"file":"error.d.mts","names":[],"sources":["../src/error.ts"],"sourcesContent":[],"mappings":";cAGa,qBAAA,SAA8B,KAAA;AAE9B,cAAA,kBAAA,SAA2B,qBAAA,CAAqB"}
{"version":3,"file":"error.d.mts","names":[],"sources":["../src/error.ts"],"mappings":";cAGa,qBAAA,SAA8B,KAAA;AAAA,cAE9B,kBAAA,SAA2B,qBAAA"}

@@ -1,1 +0,1 @@

{"version":3,"file":"transactions.d.mts","names":[],"sources":["../src/transactions.ts"],"sourcesContent":[],"mappings":";;;;;UAeiB,6BAAA;SACT;AADR;AAIa,cAAA,sBAAA,CAAsB;EAGb,CAAA,OAAA;EAYW,WAAA,CAAA,OAAA,EAZX,6BAYW;EAA6B;;;;;;;;EA4DQ,sBAAA,CAAA,OAAA,EA5DrC,6BA4DqC,CAAA,EA5DR,WA4DQ;EAevC;;;;;;;;mCA5DG,iCAA8B;;;;;;;;;0BAevC,wBAAqB;;;;;;;;;4CAeH,oCAAiC;;;;;;;;;yCAepC,iCAA8B;;;;;;;;;gCAevC,8BAA2B;;;;;;;;;+BAe5B,6BAA0B"}
{"version":3,"file":"transactions.d.mts","names":[],"sources":["../src/transactions.ts"],"mappings":";;;;;UAeiB,6BAAA;EAChB,KAAA,EAAO,eAAA;AAAA;AAAA,cAGK,sBAAA;EAAA;cAGA,OAAA,EAAS,6BAAA;EANC;AAGvB;;;;;;;EAeC,sBAAA,CAAuB,OAAA,EAAS,6BAAA,GAA6B,WAAA;EA8BrC;;;;;;;;EAfxB,uBAAA,CAAwB,OAAA,EAAS,8BAAA,GAA8B,WAAA;EA2ER;;;;;;;;EA5DvD,cAAA,CAAe,OAAA,EAAS,qBAAA,GAAqB,WAAA;EA9BtB;;;;;;;;EA6CvB,gCAAA,CAAiC,OAAA,EAAS,iCAAA,GAAiC,WAAA;EAf9B;;;;;;;;EA8B7C,6BAAA,CAA8B,OAAA,EAAS,8BAAA,GAA8B,WAAA;EAerE;;;;;;;;EAAA,oBAAA,CAAqB,OAAA,EAAS,2BAAA,GAA2B,WAAA;EAeF;;;;;;;;EAAvD,mBAAA,CAAoB,OAAA,EAAS,0BAAA,GAA0B,WAAA;AAAA"}

@@ -1,1 +0,1 @@

{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;KAMY,uBAAA;;EAAA,WAAA,EAAA,MAAA;AAKZ,CAAA;AAEiB,UAFA,0BAAA,SAAmC,iBAGjB,CAAA,CAGnC;AAIY,UARK,uBAAA,CAUb;EAEQ,MAAA,EAXH,0BAWiB;AAO1B;AAEiB,KAjBL,QAAA,GAiBK;EAML,YAAA,CAAA,EAAA,MAAA;EAKA,UAAA,CAAA,EAAA,KAAA;AAEZ,CAAA,GAAY;EAIA,YAAA,CAAA,EAAA,KAAA;EAIA,UAAA,EAAA,MAAA;AAIZ,CAAA;AAIY,KA1CA,mBAAA,GA0C0B;EAK1B,UAAA,EAAA,MAAA;IA7CR;KAEQ,cAAA;;;;;;KAOA,uBAAA,GAA0B,iBAAiB;UAEtC,wBAAA;;;;;KAML,8BAAA;;eAEE;IACV;KAEQ,6BAAA,GAAgC,iCAAiC;KAEjE,qBAAA;;;KAIA,iCAAA;;IAER;KAEQ,8BAAA;;IAER;KAEQ,2BAAA;;IAER;KAEQ,0BAAA;;IAER,iBACH;KAEW,gBAAA;;;;;;;;IAQR,QAAQ"}
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;KAMY,uBAAA;EACX,SAAA;EACA,WAAA;AAAA;AAAA,UAGgB,0BAAA,SAAmC,iBAAA;AAAA,UAEnC,uBAAA;EAChB,MAAA,EAAQ,0BAAA;AAAA;AAAA,KAGG,QAAA;EACP,YAAA;EAAuB,UAAA;AAAA;EACvB,YAAA;EAAsB,UAAA;AAAA;AAAA,KAEf,mBAAA;EACX,UAAA;AAAA,IACG,QAAA;AAAA,KAEQ,cAAA;EACX,QAAA;EACA,KAAA;EACA,MAAA;EACA,QAAA;AAAA;AAAA,KAGW,uBAAA,GAA0B,cAAA,GAAiB,QAAA;AAAA,UAEtC,wBAAA;EAChB,GAAA;EACA,wBAAA;EACA,mBAAA;AAAA;AAAA,KAGW,8BAAA;EACX,MAAA;EACA,UAAA,GAAa,iBAAA;AAAA,IACV,cAAA;AAAA,KAEQ,6BAAA,GAAgC,8BAAA,GAAiC,QAAA;AAAA,KAEjE,qBAAA;EACX,YAAA;AAAA;AAAA,KAGW,iCAAA;EACX,uBAAA;AAAA,IACG,mBAAA;AAAA,KAEQ,8BAAA;EACX,oBAAA;AAAA,IACG,mBAAA;AAAA,KAEQ,2BAAA;EACX,QAAA;AAAA,IACG,mBAAA;AAAA,KAEQ,0BAAA;EACX,QAAA;AAAA,IACG,cAAA,GACH,QAAA;AAAA,KAEW,gBAAA;EACX,eAAA;EACA,MAAA;EACA,QAAA;EACA,KAAA;EACA,KAAA;EACA,OAAA;EACA,OAAA;AAAA,IACG,OAAA,CAAQ,QAAA"}
import { PaymentUriParams } from "./types.mjs";
//#region src/uri.d.ts
/**

@@ -6,0 +5,0 @@ * Create a payment transaction URI from the given parameters.

@@ -1,1 +0,1 @@

{"version":3,"file":"uri.d.mts","names":[],"sources":["../src/uri.ts"],"sourcesContent":[],"mappings":";;;;;;AAmCA;AAiEA;;;;;;;;;;;;cAjEa,sCAAuC;;;;;;;;;;cAiEvC,6CAA4C"}
{"version":3,"file":"uri.d.mts","names":[],"sources":["../src/uri.ts"],"mappings":";;;;;AAmCA;;;;;AAiEA;;;;;;;;cAjEa,2BAAA,GAA+B,MAAA,EAAQ,gBAAA;;;;;;;;;;cAiEvC,0BAAA,GAA8B,GAAA,aAAc,gBAAA"}

@@ -83,3 +83,3 @@ import { PaymentKitUriError } from "./error.mjs";

message: params.get("message") ?? void 0,
iconUrl: params.get("icon") ?? void 0
iconUrl: params.get("iconUrl") ?? void 0
};

@@ -86,0 +86,0 @@ if (registryId) return {

@@ -1,1 +0,1 @@

{"version":3,"file":"uri.mjs","names":[],"sources":["../src/uri.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidNamedType, isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui/utils';\nimport type { PaymentUriParams } from './types.js';\nimport { PaymentKitUriError } from './error.js';\nimport { SUI_PAYMENT_KIT_PROTOCOL } from './constants.js';\n\nconst isValidNonce = (nonce: string) => {\n\treturn nonce.length <= 36;\n};\n\nconst isValidAmount = (amount: bigint) => {\n\treturn amount > 0n;\n};\n\nconst isValidCoinType = (coinType: string) => {\n\treturn isValidNamedType(coinType);\n};\n\n/**\n * Create a payment transaction URI from the given parameters.\n * Returns the constructed URI string.\n *\n * @example\n * ```ts\n * const uri = createPaymentTransactionUri({\n * receiverAddress: \"0x...\",\n * amount: \"10000000\", (0.01 SUI)\n * coinType: \"0x2::sui::SUI\",\n * nonce: <nonce>,\n * registryName: \"my-registry\"\n * });\n * ```\n */\nexport const createPaymentTransactionUri = (params: PaymentUriParams): string => {\n\tconst { receiverAddress, amount, coinType, nonce, registryId, registryName } = params;\n\n\tconst uri = new URL(SUI_PAYMENT_KIT_PROTOCOL);\n\n\tif (isValidSuiAddress(receiverAddress)) {\n\t\turi.searchParams.append('receiver', receiverAddress);\n\t} else {\n\t\tthrow new PaymentKitUriError('Invalid Sui address');\n\t}\n\n\tif (isValidAmount(amount)) {\n\t\turi.searchParams.append('amount', amount.toString());\n\t} else {\n\t\tthrow new PaymentKitUriError('Amount must be a positive numeric string');\n\t}\n\n\tif (isValidCoinType(coinType)) {\n\t\turi.searchParams.append('coinType', coinType);\n\t} else {\n\t\tthrow new PaymentKitUriError('Invalid Coin Type');\n\t}\n\n\tif (isValidNonce(nonce)) {\n\t\turi.searchParams.append('nonce', nonce);\n\t} else {\n\t\tthrow new PaymentKitUriError('Nonce length exceeds maximum of 36 characters');\n\t}\n\n\tif (registryId) {\n\t\tif (isValidSuiObjectId(registryId)) {\n\t\t\turi.searchParams.append('registry', registryId);\n\t\t} else {\n\t\t\tthrow new PaymentKitUriError('Invalid Sui Object Id for Registry Id');\n\t\t}\n\t}\n\n\tif (registryName) {\n\t\turi.searchParams.append('registry', registryName);\n\t}\n\n\tif (params.label) {\n\t\turi.searchParams.append('label', params.label);\n\t}\n\n\tif (params.message) {\n\t\turi.searchParams.append('message', params.message);\n\t}\n\n\tif (params.iconUrl) {\n\t\turi.searchParams.append('iconUrl', params.iconUrl);\n\t}\n\n\treturn uri.toString();\n};\n\n/**\n * Parse a payment transaction URI into its components.\n * Returns the parsed payment URI parameters.\n *\n * @example\n * ```ts\n * const params = parsePaymentTransactionUri(\"sui:0x...?amount=1000000&coinType=0x...&nonce=...\");\n * ```\n */\nexport const parsePaymentTransactionUri = (uri: string): PaymentUriParams => {\n\tif (!uri.startsWith(SUI_PAYMENT_KIT_PROTOCOL + '?')) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Must start with sui:pay?');\n\t}\n\n\tconst url = new URL(uri);\n\n\t// Extract query parameters\n\tconst params = url.searchParams;\n\tconst receiver = params.get('receiver');\n\tconst amount = params.get('amount');\n\tconst coinType = params.get('coinType');\n\tconst nonce = params.get('nonce');\n\n\t// Amount and CoinType are required\n\tif (!receiver || !amount || !coinType || !nonce) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Missing required parameters');\n\t}\n\n\t// Validate the receiver address\n\tif (!isValidSuiAddress(receiver)) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Receiver address is not valid');\n\t}\n\n\tif (!isValidCoinType(coinType)) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Coin Type is not valid');\n\t}\n\n\tif (!isValidNonce(nonce)) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Nonce length exceeds maximum of 36 characters');\n\t}\n\n\t// Validate amount is a valid numeric string (int or float) and positive\n\tconst bigIntAmount = BigInt(amount);\n\tif (!isValidAmount(bigIntAmount)) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Amount must be a positive number');\n\t}\n\n\t// Extract optional registry parameter\n\tconst registry = params.get('registry') ?? undefined;\n\n\t// Determine if registry is an ID or name\n\tlet registryId: string | undefined;\n\tlet registryName: string | undefined;\n\n\tif (registry) {\n\t\tif (isValidSuiObjectId(registry)) {\n\t\t\tregistryId = registry;\n\t\t} else {\n\t\t\tregistryName = registry;\n\t\t}\n\t}\n\n\tconst baseParams = {\n\t\treceiverAddress: receiver,\n\t\tamount: bigIntAmount,\n\t\tcoinType,\n\t\tnonce: nonce,\n\t\tlabel: params.get('label') ?? undefined,\n\t\tmessage: params.get('message') ?? undefined,\n\t\ticonUrl: params.get('icon') ?? undefined,\n\t};\n\n\tif (registryId) {\n\t\treturn { ...baseParams, registryId };\n\t}\n\n\treturn { ...baseParams, registryName };\n};\n"],"mappings":";;;;;AAQA,MAAM,gBAAgB,UAAkB;AACvC,QAAO,MAAM,UAAU;;AAGxB,MAAM,iBAAiB,WAAmB;AACzC,QAAO,SAAS;;AAGjB,MAAM,mBAAmB,aAAqB;AAC7C,QAAO,iBAAiB,SAAS;;;;;;;;;;;;;;;;;AAkBlC,MAAa,+BAA+B,WAAqC;CAChF,MAAM,EAAE,iBAAiB,QAAQ,UAAU,OAAO,YAAY,iBAAiB;CAE/E,MAAM,MAAM,IAAI,IAAI,yBAAyB;AAE7C,KAAI,kBAAkB,gBAAgB,CACrC,KAAI,aAAa,OAAO,YAAY,gBAAgB;KAEpD,OAAM,IAAI,mBAAmB,sBAAsB;AAGpD,KAAI,cAAc,OAAO,CACxB,KAAI,aAAa,OAAO,UAAU,OAAO,UAAU,CAAC;KAEpD,OAAM,IAAI,mBAAmB,2CAA2C;AAGzE,KAAI,gBAAgB,SAAS,CAC5B,KAAI,aAAa,OAAO,YAAY,SAAS;KAE7C,OAAM,IAAI,mBAAmB,oBAAoB;AAGlD,KAAI,aAAa,MAAM,CACtB,KAAI,aAAa,OAAO,SAAS,MAAM;KAEvC,OAAM,IAAI,mBAAmB,gDAAgD;AAG9E,KAAI,WACH,KAAI,mBAAmB,WAAW,CACjC,KAAI,aAAa,OAAO,YAAY,WAAW;KAE/C,OAAM,IAAI,mBAAmB,wCAAwC;AAIvE,KAAI,aACH,KAAI,aAAa,OAAO,YAAY,aAAa;AAGlD,KAAI,OAAO,MAC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EAAY;EAAY;AAGrC,QAAO;EAAE,GAAG;EAAY;EAAc"}
{"version":3,"file":"uri.mjs","names":[],"sources":["../src/uri.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidNamedType, isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui/utils';\nimport type { PaymentUriParams } from './types.js';\nimport { PaymentKitUriError } from './error.js';\nimport { SUI_PAYMENT_KIT_PROTOCOL } from './constants.js';\n\nconst isValidNonce = (nonce: string) => {\n\treturn nonce.length <= 36;\n};\n\nconst isValidAmount = (amount: bigint) => {\n\treturn amount > 0n;\n};\n\nconst isValidCoinType = (coinType: string) => {\n\treturn isValidNamedType(coinType);\n};\n\n/**\n * Create a payment transaction URI from the given parameters.\n * Returns the constructed URI string.\n *\n * @example\n * ```ts\n * const uri = createPaymentTransactionUri({\n * receiverAddress: \"0x...\",\n * amount: \"10000000\", (0.01 SUI)\n * coinType: \"0x2::sui::SUI\",\n * nonce: <nonce>,\n * registryName: \"my-registry\"\n * });\n * ```\n */\nexport const createPaymentTransactionUri = (params: PaymentUriParams): string => {\n\tconst { receiverAddress, amount, coinType, nonce, registryId, registryName } = params;\n\n\tconst uri = new URL(SUI_PAYMENT_KIT_PROTOCOL);\n\n\tif (isValidSuiAddress(receiverAddress)) {\n\t\turi.searchParams.append('receiver', receiverAddress);\n\t} else {\n\t\tthrow new PaymentKitUriError('Invalid Sui address');\n\t}\n\n\tif (isValidAmount(amount)) {\n\t\turi.searchParams.append('amount', amount.toString());\n\t} else {\n\t\tthrow new PaymentKitUriError('Amount must be a positive numeric string');\n\t}\n\n\tif (isValidCoinType(coinType)) {\n\t\turi.searchParams.append('coinType', coinType);\n\t} else {\n\t\tthrow new PaymentKitUriError('Invalid Coin Type');\n\t}\n\n\tif (isValidNonce(nonce)) {\n\t\turi.searchParams.append('nonce', nonce);\n\t} else {\n\t\tthrow new PaymentKitUriError('Nonce length exceeds maximum of 36 characters');\n\t}\n\n\tif (registryId) {\n\t\tif (isValidSuiObjectId(registryId)) {\n\t\t\turi.searchParams.append('registry', registryId);\n\t\t} else {\n\t\t\tthrow new PaymentKitUriError('Invalid Sui Object Id for Registry Id');\n\t\t}\n\t}\n\n\tif (registryName) {\n\t\turi.searchParams.append('registry', registryName);\n\t}\n\n\tif (params.label) {\n\t\turi.searchParams.append('label', params.label);\n\t}\n\n\tif (params.message) {\n\t\turi.searchParams.append('message', params.message);\n\t}\n\n\tif (params.iconUrl) {\n\t\turi.searchParams.append('iconUrl', params.iconUrl);\n\t}\n\n\treturn uri.toString();\n};\n\n/**\n * Parse a payment transaction URI into its components.\n * Returns the parsed payment URI parameters.\n *\n * @example\n * ```ts\n * const params = parsePaymentTransactionUri(\"sui:0x...?amount=1000000&coinType=0x...&nonce=...\");\n * ```\n */\nexport const parsePaymentTransactionUri = (uri: string): PaymentUriParams => {\n\tif (!uri.startsWith(SUI_PAYMENT_KIT_PROTOCOL + '?')) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Must start with sui:pay?');\n\t}\n\n\tconst url = new URL(uri);\n\n\t// Extract query parameters\n\tconst params = url.searchParams;\n\tconst receiver = params.get('receiver');\n\tconst amount = params.get('amount');\n\tconst coinType = params.get('coinType');\n\tconst nonce = params.get('nonce');\n\n\t// Amount and CoinType are required\n\tif (!receiver || !amount || !coinType || !nonce) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Missing required parameters');\n\t}\n\n\t// Validate the receiver address\n\tif (!isValidSuiAddress(receiver)) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Receiver address is not valid');\n\t}\n\n\tif (!isValidCoinType(coinType)) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Coin Type is not valid');\n\t}\n\n\tif (!isValidNonce(nonce)) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Nonce length exceeds maximum of 36 characters');\n\t}\n\n\t// Validate amount is a valid numeric string (int or float) and positive\n\tconst bigIntAmount = BigInt(amount);\n\tif (!isValidAmount(bigIntAmount)) {\n\t\tthrow new PaymentKitUriError('Invalid URI: Amount must be a positive number');\n\t}\n\n\t// Extract optional registry parameter\n\tconst registry = params.get('registry') ?? undefined;\n\n\t// Determine if registry is an ID or name\n\tlet registryId: string | undefined;\n\tlet registryName: string | undefined;\n\n\tif (registry) {\n\t\tif (isValidSuiObjectId(registry)) {\n\t\t\tregistryId = registry;\n\t\t} else {\n\t\t\tregistryName = registry;\n\t\t}\n\t}\n\n\tconst baseParams = {\n\t\treceiverAddress: receiver,\n\t\tamount: bigIntAmount,\n\t\tcoinType,\n\t\tnonce: nonce,\n\t\tlabel: params.get('label') ?? undefined,\n\t\tmessage: params.get('message') ?? undefined,\n\t\ticonUrl: params.get('iconUrl') ?? undefined,\n\t};\n\n\tif (registryId) {\n\t\treturn { ...baseParams, registryId };\n\t}\n\n\treturn { ...baseParams, registryName };\n};\n"],"mappings":";;;;;AAQA,MAAM,gBAAgB,UAAkB;AACvC,QAAO,MAAM,UAAU;;AAGxB,MAAM,iBAAiB,WAAmB;AACzC,QAAO,SAAS;;AAGjB,MAAM,mBAAmB,aAAqB;AAC7C,QAAO,iBAAiB,SAAS;;;;;;;;;;;;;;;;;AAkBlC,MAAa,+BAA+B,WAAqC;CAChF,MAAM,EAAE,iBAAiB,QAAQ,UAAU,OAAO,YAAY,iBAAiB;CAE/E,MAAM,MAAM,IAAI,IAAI,yBAAyB;AAE7C,KAAI,kBAAkB,gBAAgB,CACrC,KAAI,aAAa,OAAO,YAAY,gBAAgB;KAEpD,OAAM,IAAI,mBAAmB,sBAAsB;AAGpD,KAAI,cAAc,OAAO,CACxB,KAAI,aAAa,OAAO,UAAU,OAAO,UAAU,CAAC;KAEpD,OAAM,IAAI,mBAAmB,2CAA2C;AAGzE,KAAI,gBAAgB,SAAS,CAC5B,KAAI,aAAa,OAAO,YAAY,SAAS;KAE7C,OAAM,IAAI,mBAAmB,oBAAoB;AAGlD,KAAI,aAAa,MAAM,CACtB,KAAI,aAAa,OAAO,SAAS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Aa;KAEb,gBAAe;CAIjB,MAAM,aAAa;EAClB,iBAAiB;EACjB,QAAQ;EACR;EACO;EACP,OAAO,OAAO,IAAI,QAAQ,IAAI;EAC9B,SAAS,OAAO,IAAI,UAAU,IAAI;EAClC,SAAS,OAAO,IAAI,UAAU,IAAI;EAClC;AAED,KAAI,WACH,QAAO;EAAE,GAAG;EAAY;EAAY;AAGrC,QAAO;EAAE,GAAG;EAAY;EAAc"}
{
"name": "@mysten/payment-kit",
"version": "0.1.3",
"version": "0.1.4",
"private": false,

@@ -32,7 +32,8 @@ "description": "Sui Payment Kit",

"typescript": "^5.9.3",
"vitest": "^4.0.17",
"@mysten/codegen": "^0.8.3"
},
"dependencies": {
"@mysten/bcs": "^2.0.3",
"@mysten/sui": "^2.8.0"
"@mysten/sui": "^2.13.3",
"@mysten/bcs": "^2.0.3"
},

@@ -49,4 +50,6 @@ "scripts": {

"lint": "pnpm run oxlint:check && pnpm run prettier:check",
"lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix"
"lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix",
"test": "vitest run",
"vitest": "vitest"
}
}