@mysten/payment-kit 0.0.20 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/calls.d.mts +101 -0
- package/dist/calls.d.mts.map +1 -0
- package/dist/calls.mjs +91 -0
- package/dist/calls.mjs.map +1 -0
- package/dist/client.d.mts +43 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +86 -0
- package/dist/client.mjs.map +1 -0
- package/dist/constants.d.mts +7 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +18 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/contracts/payment_kit/config.mjs +25 -0
- package/dist/contracts/payment_kit/config.mjs.map +1 -0
- package/dist/contracts/payment_kit/deps/std/type_name.mjs +17 -0
- package/dist/contracts/payment_kit/deps/std/type_name.mjs.map +1 -0
- package/dist/contracts/payment_kit/deps/sui/vec_map.mjs +37 -0
- package/dist/contracts/payment_kit/deps/sui/vec_map.mjs.map +1 -0
- package/dist/contracts/payment_kit/payment_kit.mjs +241 -0
- package/dist/contracts/payment_kit/payment_kit.mjs.map +1 -0
- package/dist/contracts/utils/index.mjs +120 -0
- package/dist/contracts/utils/index.mjs.map +1 -0
- package/dist/error.d.mts +6 -0
- package/dist/error.d.mts.map +1 -0
- package/dist/error.mjs +7 -0
- package/dist/error.mjs.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +6 -0
- package/dist/transactions.d.mts +78 -0
- package/dist/transactions.d.mts.map +1 -0
- package/dist/transactions.mjs +104 -0
- package/dist/transactions.mjs.map +1 -0
- package/dist/types.d.mts +66 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/{esm/uri.d.ts → uri.d.mts} +9 -3
- package/dist/uri.d.mts.map +1 -0
- package/dist/uri.mjs +97 -0
- package/dist/uri.mjs.map +1 -0
- package/dist/utils.mjs +12 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +14 -16
- package/dist/cjs/calls.d.ts +0 -71
- package/dist/cjs/calls.js +0 -207
- package/dist/cjs/calls.js.map +0 -7
- package/dist/cjs/client.d.ts +0 -36
- package/dist/cjs/client.js +0 -123
- package/dist/cjs/client.js.map +0 -7
- package/dist/cjs/constants.d.ts +0 -11
- package/dist/cjs/constants.js +0 -40
- package/dist/cjs/constants.js.map +0 -7
- package/dist/cjs/contracts/payment_kit/config.d.ts +0 -14
- package/dist/cjs/contracts/payment_kit/config.js +0 -50
- package/dist/cjs/contracts/payment_kit/config.js.map +0 -7
- package/dist/cjs/contracts/payment_kit/deps/std/type_name.d.ts +0 -14
- package/dist/cjs/contracts/payment_kit/deps/std/type_name.js +0 -42
- package/dist/cjs/contracts/payment_kit/deps/std/type_name.js.map +0 -7
- package/dist/cjs/contracts/payment_kit/deps/sui/object.d.ts +0 -5
- package/dist/cjs/contracts/payment_kit/deps/sui/object.js +0 -33
- package/dist/cjs/contracts/payment_kit/deps/sui/object.js.map +0 -7
- package/dist/cjs/contracts/payment_kit/deps/sui/vec_map.d.ts +0 -27
- package/dist/cjs/contracts/payment_kit/deps/sui/vec_map.js +0 -45
- package/dist/cjs/contracts/payment_kit/deps/sui/vec_map.js.map +0 -7
- package/dist/cjs/contracts/payment_kit/payment_kit.d.ts +0 -233
- package/dist/cjs/contracts/payment_kit/payment_kit.js +0 -252
- package/dist/cjs/contracts/payment_kit/payment_kit.js.map +0 -7
- package/dist/cjs/contracts/utils/index.d.ts +0 -12
- package/dist/cjs/contracts/utils/index.js +0 -151
- package/dist/cjs/contracts/utils/index.js.map +0 -7
- package/dist/cjs/error.d.ts +0 -4
- package/dist/cjs/error.js +0 -29
- package/dist/cjs/error.js.map +0 -7
- package/dist/cjs/index.d.ts +0 -5
- package/dist/cjs/index.js +0 -35
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/package.json +0 -5
- package/dist/cjs/transactions.d.ts +0 -73
- package/dist/cjs/transactions.js +0 -131
- package/dist/cjs/transactions.js.map +0 -7
- package/dist/cjs/types.d.ts +0 -62
- package/dist/cjs/types.js +0 -17
- package/dist/cjs/types.js.map +0 -7
- package/dist/cjs/uri.d.ts +0 -27
- package/dist/cjs/uri.js +0 -131
- package/dist/cjs/uri.js.map +0 -7
- package/dist/cjs/utils.d.ts +0 -1
- package/dist/cjs/utils.js +0 -34
- package/dist/cjs/utils.js.map +0 -7
- package/dist/esm/calls.d.ts +0 -71
- package/dist/esm/calls.js +0 -196
- package/dist/esm/calls.js.map +0 -7
- package/dist/esm/client.d.ts +0 -36
- package/dist/esm/client.js +0 -106
- package/dist/esm/client.js.map +0 -7
- package/dist/esm/constants.d.ts +0 -11
- package/dist/esm/constants.js +0 -20
- package/dist/esm/constants.js.map +0 -7
- package/dist/esm/contracts/payment_kit/config.d.ts +0 -14
- package/dist/esm/contracts/payment_kit/config.js +0 -20
- package/dist/esm/contracts/payment_kit/config.js.map +0 -7
- package/dist/esm/contracts/payment_kit/deps/std/type_name.d.ts +0 -14
- package/dist/esm/contracts/payment_kit/deps/std/type_name.js +0 -22
- package/dist/esm/contracts/payment_kit/deps/std/type_name.js.map +0 -7
- package/dist/esm/contracts/payment_kit/deps/sui/object.d.ts +0 -5
- package/dist/esm/contracts/payment_kit/deps/sui/object.js +0 -13
- package/dist/esm/contracts/payment_kit/deps/sui/object.js.map +0 -7
- package/dist/esm/contracts/payment_kit/deps/sui/vec_map.d.ts +0 -27
- package/dist/esm/contracts/payment_kit/deps/sui/vec_map.js +0 -25
- package/dist/esm/contracts/payment_kit/deps/sui/vec_map.js.map +0 -7
- package/dist/esm/contracts/payment_kit/payment_kit.d.ts +0 -233
- package/dist/esm/contracts/payment_kit/payment_kit.js +0 -222
- package/dist/esm/contracts/payment_kit/payment_kit.js.map +0 -7
- package/dist/esm/contracts/utils/index.d.ts +0 -12
- package/dist/esm/contracts/utils/index.js +0 -131
- package/dist/esm/contracts/utils/index.js.map +0 -7
- package/dist/esm/error.d.ts +0 -4
- package/dist/esm/error.js +0 -9
- package/dist/esm/error.js.map +0 -7
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.js +0 -15
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/package.json +0 -5
- package/dist/esm/transactions.d.ts +0 -73
- package/dist/esm/transactions.js +0 -111
- package/dist/esm/transactions.js.map +0 -7
- package/dist/esm/types.d.ts +0 -62
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -7
- package/dist/esm/uri.js +0 -111
- package/dist/esm/uri.js.map +0 -7
- package/dist/esm/utils.d.ts +0 -1
- package/dist/esm/utils.js +0 -14
- package/dist/esm/utils.js.map +0 -7
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { TransactionResult } from "@mysten/sui/transactions";
|
|
2
|
+
import { ClientWithCoreApi } from "@mysten/sui/client";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type PaymentKitPackageConfig = {
|
|
6
|
+
packageId: string;
|
|
7
|
+
namespaceId: string;
|
|
8
|
+
};
|
|
9
|
+
interface PaymentKitCompatibleClient extends ClientWithCoreApi {}
|
|
10
|
+
interface PaymentKitClientOptions {
|
|
11
|
+
client: PaymentKitCompatibleClient;
|
|
12
|
+
}
|
|
13
|
+
type Registry = {
|
|
14
|
+
registryName?: string;
|
|
15
|
+
registryId?: never;
|
|
16
|
+
} | {
|
|
17
|
+
registryName?: never;
|
|
18
|
+
registryId: string;
|
|
19
|
+
};
|
|
20
|
+
type RegistryAndAdminCap = {
|
|
21
|
+
adminCapId: string;
|
|
22
|
+
} & Registry;
|
|
23
|
+
type PaymentKeyArgs = {
|
|
24
|
+
coinType: string;
|
|
25
|
+
nonce: string;
|
|
26
|
+
amount: number | bigint;
|
|
27
|
+
receiver: string;
|
|
28
|
+
};
|
|
29
|
+
type GetPaymentRecordOptions = PaymentKeyArgs & Registry;
|
|
30
|
+
interface GetPaymentRecordResponse {
|
|
31
|
+
key: string;
|
|
32
|
+
paymentTransactionDigest: string | null;
|
|
33
|
+
epochAtTimeOfRecord: string;
|
|
34
|
+
}
|
|
35
|
+
type ProcessEphemeralPaymentOptions = {
|
|
36
|
+
sender: string;
|
|
37
|
+
sourceCoin?: TransactionResult;
|
|
38
|
+
} & PaymentKeyArgs;
|
|
39
|
+
type ProcessRegistryPaymentOptions = ProcessEphemeralPaymentOptions & Registry;
|
|
40
|
+
type CreateRegistryOptions = {
|
|
41
|
+
registryName: string;
|
|
42
|
+
};
|
|
43
|
+
type SetEpochExpirationDurationOptions = {
|
|
44
|
+
epochExpirationDuration: number | bigint;
|
|
45
|
+
} & RegistryAndAdminCap;
|
|
46
|
+
type SetRegistryManagedFundsOptions = {
|
|
47
|
+
registryManagedFunds: boolean;
|
|
48
|
+
} & RegistryAndAdminCap;
|
|
49
|
+
type WithdrawFromRegistryOptions = {
|
|
50
|
+
coinType: string;
|
|
51
|
+
} & RegistryAndAdminCap;
|
|
52
|
+
type DeletePaymentRecordOptions = {
|
|
53
|
+
coinType: string;
|
|
54
|
+
} & PaymentKeyArgs & Registry;
|
|
55
|
+
type PaymentUriParams = {
|
|
56
|
+
receiverAddress: string;
|
|
57
|
+
amount: bigint;
|
|
58
|
+
coinType: string;
|
|
59
|
+
nonce: string;
|
|
60
|
+
label?: string;
|
|
61
|
+
message?: string;
|
|
62
|
+
iconUrl?: string;
|
|
63
|
+
} & Partial<Registry>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { CreateRegistryOptions, DeletePaymentRecordOptions, GetPaymentRecordOptions, GetPaymentRecordResponse, PaymentKitClientOptions, PaymentKitCompatibleClient, PaymentKitPackageConfig, PaymentUriParams, ProcessEphemeralPaymentOptions, ProcessRegistryPaymentOptions, SetEpochExpirationDurationOptions, SetRegistryManagedFundsOptions, WithdrawFromRegistryOptions };
|
|
66
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PaymentUriParams } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/uri.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Create a payment transaction URI from the given parameters.
|
|
4
7
|
* Returns the constructed URI string.
|
|
@@ -14,7 +17,7 @@ import type { PaymentUriParams } from './types.js';
|
|
|
14
17
|
* });
|
|
15
18
|
* ```
|
|
16
19
|
*/
|
|
17
|
-
|
|
20
|
+
declare const createPaymentTransactionUri: (params: PaymentUriParams) => string;
|
|
18
21
|
/**
|
|
19
22
|
* Parse a payment transaction URI into its components.
|
|
20
23
|
* Returns the parsed payment URI parameters.
|
|
@@ -24,4 +27,7 @@ export declare const createPaymentTransactionUri: (params: PaymentUriParams) =>
|
|
|
24
27
|
* const params = parsePaymentTransactionUri("sui:0x...?amount=1000000&coinType=0x...&nonce=...");
|
|
25
28
|
* ```
|
|
26
29
|
*/
|
|
27
|
-
|
|
30
|
+
declare const parsePaymentTransactionUri: (uri: string) => PaymentUriParams;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createPaymentTransactionUri, parsePaymentTransactionUri };
|
|
33
|
+
//# sourceMappingURL=uri.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uri.d.mts","names":[],"sources":["../src/uri.ts"],"sourcesContent":[],"mappings":";;;;;;AAmCA;AAiEA;;;;;;;;;;;;cAjEa,sCAAuC;;;;;;;;;;cAiEvC,6CAA4C"}
|
package/dist/uri.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PaymentKitUriError } from "./error.mjs";
|
|
2
|
+
import { SUI_PAYMENT_KIT_PROTOCOL } from "./constants.mjs";
|
|
3
|
+
import { isValidNamedType, isValidSuiAddress, isValidSuiObjectId } from "@mysten/sui/utils";
|
|
4
|
+
|
|
5
|
+
//#region src/uri.ts
|
|
6
|
+
const isValidNonce = (nonce) => {
|
|
7
|
+
return nonce.length <= 36;
|
|
8
|
+
};
|
|
9
|
+
const isValidAmount = (amount) => {
|
|
10
|
+
return amount > 0n;
|
|
11
|
+
};
|
|
12
|
+
const isValidCoinType = (coinType) => {
|
|
13
|
+
return isValidNamedType(coinType);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Create a payment transaction URI from the given parameters.
|
|
17
|
+
* Returns the constructed URI string.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const uri = createPaymentTransactionUri({
|
|
22
|
+
* receiverAddress: "0x...",
|
|
23
|
+
* amount: "10000000", (0.01 SUI)
|
|
24
|
+
* coinType: "0x2::sui::SUI",
|
|
25
|
+
* nonce: <nonce>,
|
|
26
|
+
* registryName: "my-registry"
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const createPaymentTransactionUri = (params) => {
|
|
31
|
+
const { receiverAddress, amount, coinType, nonce, registryId, registryName } = params;
|
|
32
|
+
const uri = new URL(SUI_PAYMENT_KIT_PROTOCOL);
|
|
33
|
+
if (isValidSuiAddress(receiverAddress)) uri.searchParams.append("receiver", receiverAddress);
|
|
34
|
+
else throw new PaymentKitUriError("Invalid Sui address");
|
|
35
|
+
if (isValidAmount(amount)) uri.searchParams.append("amount", amount.toString());
|
|
36
|
+
else throw new PaymentKitUriError("Amount must be a positive numeric string");
|
|
37
|
+
if (isValidCoinType(coinType)) uri.searchParams.append("coinType", coinType);
|
|
38
|
+
else throw new PaymentKitUriError("Invalid Coin Type");
|
|
39
|
+
if (isValidNonce(nonce)) uri.searchParams.append("nonce", nonce);
|
|
40
|
+
else throw new PaymentKitUriError("Nonce length exceeds maximum of 36 characters");
|
|
41
|
+
if (registryId) if (isValidSuiObjectId(registryId)) uri.searchParams.append("registry", registryId);
|
|
42
|
+
else throw new PaymentKitUriError("Invalid Sui Object Id for Registry Id");
|
|
43
|
+
if (registryName) uri.searchParams.append("registry", registryName);
|
|
44
|
+
if (params.label) uri.searchParams.append("label", params.label);
|
|
45
|
+
if (params.message) uri.searchParams.append("message", params.message);
|
|
46
|
+
if (params.iconUrl) uri.searchParams.append("iconUrl", params.iconUrl);
|
|
47
|
+
return uri.toString();
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Parse a payment transaction URI into its components.
|
|
51
|
+
* Returns the parsed payment URI parameters.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const params = parsePaymentTransactionUri("sui:0x...?amount=1000000&coinType=0x...&nonce=...");
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
const parsePaymentTransactionUri = (uri) => {
|
|
59
|
+
if (!uri.startsWith(SUI_PAYMENT_KIT_PROTOCOL + "?")) throw new PaymentKitUriError("Invalid URI: Must start with sui:pay?");
|
|
60
|
+
const params = new URL(uri).searchParams;
|
|
61
|
+
const receiver = params.get("receiver");
|
|
62
|
+
const amount = params.get("amount");
|
|
63
|
+
const coinType = params.get("coinType");
|
|
64
|
+
const nonce = params.get("nonce");
|
|
65
|
+
if (!receiver || !amount || !coinType || !nonce) throw new PaymentKitUriError("Invalid URI: Missing required parameters");
|
|
66
|
+
if (!isValidSuiAddress(receiver)) throw new PaymentKitUriError("Invalid URI: Receiver address is not valid");
|
|
67
|
+
if (!isValidCoinType(coinType)) throw new PaymentKitUriError("Invalid URI: Coin Type is not valid");
|
|
68
|
+
if (!isValidNonce(nonce)) throw new PaymentKitUriError("Invalid URI: Nonce length exceeds maximum of 36 characters");
|
|
69
|
+
const bigIntAmount = BigInt(amount);
|
|
70
|
+
if (!isValidAmount(bigIntAmount)) throw new PaymentKitUriError("Invalid URI: Amount must be a positive number");
|
|
71
|
+
const registry = params.get("registry") ?? void 0;
|
|
72
|
+
let registryId;
|
|
73
|
+
let registryName;
|
|
74
|
+
if (registry) if (isValidSuiObjectId(registry)) registryId = registry;
|
|
75
|
+
else registryName = registry;
|
|
76
|
+
const baseParams = {
|
|
77
|
+
receiverAddress: receiver,
|
|
78
|
+
amount: bigIntAmount,
|
|
79
|
+
coinType,
|
|
80
|
+
nonce,
|
|
81
|
+
label: params.get("label") ?? void 0,
|
|
82
|
+
message: params.get("message") ?? void 0,
|
|
83
|
+
iconUrl: params.get("icon") ?? void 0
|
|
84
|
+
};
|
|
85
|
+
if (registryId) return {
|
|
86
|
+
...baseParams,
|
|
87
|
+
registryId
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
...baseParams,
|
|
91
|
+
registryName
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { createPaymentTransactionUri, parsePaymentTransactionUri };
|
|
97
|
+
//# sourceMappingURL=uri.mjs.map
|
package/dist/uri.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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,MACV,KAAI,aAAa,OAAO,SAAS,OAAO,MAAM;AAG/C,KAAI,OAAO,QACV,KAAI,aAAa,OAAO,WAAW,OAAO,QAAQ;AAGnD,KAAI,OAAO,QACV,KAAI,aAAa,OAAO,WAAW,OAAO,QAAQ;AAGnD,QAAO,IAAI,UAAU;;;;;;;;;;;AAYtB,MAAa,8BAA8B,QAAkC;AAC5E,KAAI,CAAC,IAAI,WAAW,2BAA2B,IAAI,CAClD,OAAM,IAAI,mBAAmB,wCAAwC;CAMtE,MAAM,SAHM,IAAI,IAAI,IAAI,CAGL;CACnB,MAAM,WAAW,OAAO,IAAI,WAAW;CACvC,MAAM,SAAS,OAAO,IAAI,SAAS;CACnC,MAAM,WAAW,OAAO,IAAI,WAAW;CACvC,MAAM,QAAQ,OAAO,IAAI,QAAQ;AAGjC,KAAI,CAAC,YAAY,CAAC,UAAU,CAAC,YAAY,CAAC,MACzC,OAAM,IAAI,mBAAmB,2CAA2C;AAIzE,KAAI,CAAC,kBAAkB,SAAS,CAC/B,OAAM,IAAI,mBAAmB,6CAA6C;AAG3E,KAAI,CAAC,gBAAgB,SAAS,CAC7B,OAAM,IAAI,mBAAmB,sCAAsC;AAGpE,KAAI,CAAC,aAAa,MAAM,CACvB,OAAM,IAAI,mBAAmB,6DAA6D;CAI3F,MAAM,eAAe,OAAO,OAAO;AACnC,KAAI,CAAC,cAAc,aAAa,CAC/B,OAAM,IAAI,mBAAmB,gDAAgD;CAI9E,MAAM,WAAW,OAAO,IAAI,WAAW,IAAI;CAG3C,IAAI;CACJ,IAAI;AAEJ,KAAI,SACH,KAAI,mBAAmB,SAAS,CAC/B,cAAa;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,OAAO,IAAI;EAC/B;AAED,KAAI,WACH,QAAO;EAAE,GAAG;EAAY;EAAY;AAGrC,QAAO;EAAE,GAAG;EAAY;EAAc"}
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DEFAULT_REGISTRY_NAME } from "./constants.mjs";
|
|
2
|
+
import { deriveObjectID } from "@mysten/sui/utils";
|
|
3
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
4
|
+
|
|
5
|
+
//#region src/utils.ts
|
|
6
|
+
const getRegistryIdFromName = (registryName = DEFAULT_REGISTRY_NAME, namespaceId) => {
|
|
7
|
+
return deriveObjectID(namespaceId, "0x1::ascii::String", bcs.String.serialize(registryName).toBytes());
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { getRegistryIdFromName };
|
|
12
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport { deriveObjectID } from '@mysten/sui/utils';\nimport { DEFAULT_REGISTRY_NAME } from './constants.js';\n\nexport const getRegistryIdFromName = (\n\tregistryName: string = DEFAULT_REGISTRY_NAME,\n\tnamespaceId: string,\n) => {\n\treturn deriveObjectID(\n\t\tnamespaceId,\n\t\t'0x1::ascii::String',\n\t\tbcs.String.serialize(registryName).toBytes(),\n\t);\n};\n"],"mappings":";;;;;AAOA,MAAa,yBACZ,eAAuB,uBACvB,gBACI;AACJ,QAAO,eACN,aACA,sBACA,IAAI,OAAO,UAAU,aAAa,CAAC,SAAS,CAC5C"}
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mysten/payment-kit",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Sui Payment Kit",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"author": "Mysten Labs <build@mystenlabs.com>",
|
|
8
|
-
"type": "
|
|
9
|
-
"main": "./dist/
|
|
10
|
-
"
|
|
11
|
-
"types": "./dist/cjs/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
12
11
|
"exports": {
|
|
13
12
|
".": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
13
|
+
"types": "./dist/index.d.mts",
|
|
14
|
+
"import": "./dist/index.mjs"
|
|
16
15
|
}
|
|
17
16
|
},
|
|
18
17
|
"sideEffects": false,
|
|
@@ -28,22 +27,21 @@
|
|
|
28
27
|
},
|
|
29
28
|
"devDependencies": {
|
|
30
29
|
"typescript": "^5.9.3",
|
|
31
|
-
"@mysten/
|
|
32
|
-
"@mysten/codegen": "0.5.13"
|
|
30
|
+
"@mysten/codegen": "^0.6.0"
|
|
33
31
|
},
|
|
34
32
|
"dependencies": {
|
|
35
|
-
"@mysten/bcs": "
|
|
36
|
-
"@mysten/sui": "
|
|
33
|
+
"@mysten/bcs": "^2.0.0",
|
|
34
|
+
"@mysten/sui": "^2.0.0"
|
|
37
35
|
},
|
|
38
36
|
"scripts": {
|
|
39
37
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
40
|
-
"build": "
|
|
38
|
+
"build": "rm -rf dist && tsc --noEmit && tsdown",
|
|
41
39
|
"codegen": "sui-ts-codegen generate && pnpm lint:fix",
|
|
42
40
|
"prettier:check": "prettier -c --ignore-unknown .",
|
|
43
41
|
"prettier:fix": "prettier -w --ignore-unknown .",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"lint": "pnpm run
|
|
47
|
-
"lint:fix": "pnpm run
|
|
42
|
+
"oxlint:check": "oxlint .",
|
|
43
|
+
"oxlint:fix": "oxlint --fix",
|
|
44
|
+
"lint": "pnpm run oxlint:check && pnpm run prettier:check",
|
|
45
|
+
"lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix"
|
|
48
46
|
}
|
|
49
47
|
}
|
package/dist/cjs/calls.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { CreateRegistryOptions, DeletePaymentRecordOptions, PaymentKitPackageConfig, ProcessEphemeralPaymentOptions, ProcessRegistryPaymentOptions, SetEpochExpirationDurationOptions, SetRegistryManagedFundsOptions, WithdrawFromRegistryOptions } from './types.js';
|
|
2
|
-
export interface PaymentKitCallOptions {
|
|
3
|
-
packageConfig: PaymentKitPackageConfig;
|
|
4
|
-
}
|
|
5
|
-
export declare class PaymentKitCalls {
|
|
6
|
-
#private;
|
|
7
|
-
constructor(options: PaymentKitCallOptions);
|
|
8
|
-
/**
|
|
9
|
-
* Creates a `processRegistryPayment` transaction
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* tx.add(lient.paymentKit.call.processRegistryPayment({ nonce, coinType, sender, amount, receiver, registryName }));
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
processRegistryPayment: (options: ProcessRegistryPaymentOptions) => (tx: import("@mysten/sui/transactions").Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
17
|
-
/**
|
|
18
|
-
* Creates a `processRegistryPayment` transaction
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* tx.add(client.paymentKit.call.processEphemeralPayment({ nonce, coinType, sender, amount, receiver }));
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
processEphemeralPayment: (options: ProcessEphemeralPaymentOptions) => (tx: import("@mysten/sui/transactions").Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
26
|
-
/**
|
|
27
|
-
* Creates a `createRegistry` transaction
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* tx.add(client.paymentKit.call.createRegistry(registryName));
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
createRegistry: ({ registryName }: CreateRegistryOptions) => (tx: import("@mysten/sui/transactions").Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
35
|
-
/**
|
|
36
|
-
* Creates a `setConfigEpochExpirationDuration` transaction
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* tx.add(client.paymentKit.call.setConfigEpochExpirationDuration({registryName, epochExpirationDuration, adminCapId}));
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
setConfigEpochExpirationDuration: ({ registryName, registryId, epochExpirationDuration, adminCapId, }: SetEpochExpirationDurationOptions) => (tx: import("@mysten/sui/transactions").Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
44
|
-
/**
|
|
45
|
-
* Creates a `setConfigRegistryManagedFunds` transaction
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* tx.add(client.paymentKit.call.setConfigRegistryManagedFunds({registryName, registryManagedFunds, adminCapId}));
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
setConfigRegistryManagedFunds: ({ registryName, registryId, registryManagedFunds, adminCapId, }: SetRegistryManagedFundsOptions) => (tx: import("@mysten/sui/transactions").Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
53
|
-
/**
|
|
54
|
-
* Creates a `withdrawFromRegistry` transaction
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```ts
|
|
58
|
-
* tx.add(client.paymentKit.call.withdrawFromRegistry({coinType, registryName, adminCapId}));
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
withdrawFromRegistry: ({ coinType, registryName, registryId, adminCapId, }: WithdrawFromRegistryOptions) => (tx: import("@mysten/sui/transactions").Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
62
|
-
/**
|
|
63
|
-
* Creates a `deletePaymentRecord` transaction
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* tx.add(client.paymentKit.call.deletePaymentRecord({coinType, nonce, amount, receiver, registryName}));
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
deletePaymentRecord: ({ coinType, nonce, amount, receiver, registryName, registryId, }: DeletePaymentRecordOptions) => (tx: import("@mysten/sui/transactions").Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
71
|
-
}
|
package/dist/cjs/calls.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __typeError = (msg) => {
|
|
7
|
-
throw TypeError(msg);
|
|
8
|
-
};
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
-
var calls_exports = {};
|
|
27
|
-
__export(calls_exports, {
|
|
28
|
-
PaymentKitCalls: () => PaymentKitCalls
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(calls_exports);
|
|
31
|
-
var import_transactions = require("@mysten/sui/transactions");
|
|
32
|
-
var import_payment_kit = require("./contracts/payment_kit/payment_kit.js");
|
|
33
|
-
var import_utils = require("./utils.js");
|
|
34
|
-
var _packageConfig;
|
|
35
|
-
class PaymentKitCalls {
|
|
36
|
-
constructor(options) {
|
|
37
|
-
__privateAdd(this, _packageConfig);
|
|
38
|
-
/**
|
|
39
|
-
* Creates a `processRegistryPayment` transaction
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```ts
|
|
43
|
-
* tx.add(lient.paymentKit.call.processRegistryPayment({ nonce, coinType, sender, amount, receiver, registryName }));
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
this.processRegistryPayment = (options) => {
|
|
47
|
-
const { nonce, coinType, amount, receiver, sourceCoin, registryName, registryId } = options;
|
|
48
|
-
const registryIdToUse = registryId ?? (0, import_utils.getRegistryIdFromName)(registryName, __privateGet(this, _packageConfig).namespaceId);
|
|
49
|
-
return (0, import_payment_kit.processRegistryPayment)({
|
|
50
|
-
arguments: {
|
|
51
|
-
registry: registryIdToUse,
|
|
52
|
-
nonce,
|
|
53
|
-
paymentAmount: amount,
|
|
54
|
-
coin: sourceCoin ?? (0, import_transactions.coinWithBalance)({
|
|
55
|
-
type: coinType,
|
|
56
|
-
balance: amount
|
|
57
|
-
}),
|
|
58
|
-
receiver
|
|
59
|
-
},
|
|
60
|
-
typeArguments: [coinType]
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Creates a `processRegistryPayment` transaction
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* tx.add(client.paymentKit.call.processEphemeralPayment({ nonce, coinType, sender, amount, receiver }));
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
this.processEphemeralPayment = (options) => {
|
|
72
|
-
const { nonce, coinType, amount, receiver, sourceCoin } = options;
|
|
73
|
-
return (0, import_payment_kit.processEphemeralPayment)({
|
|
74
|
-
arguments: {
|
|
75
|
-
nonce,
|
|
76
|
-
paymentAmount: amount,
|
|
77
|
-
coin: sourceCoin ?? (0, import_transactions.coinWithBalance)({
|
|
78
|
-
type: coinType,
|
|
79
|
-
balance: amount
|
|
80
|
-
}),
|
|
81
|
-
receiver
|
|
82
|
-
},
|
|
83
|
-
typeArguments: [coinType]
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Creates a `createRegistry` transaction
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```ts
|
|
91
|
-
* tx.add(client.paymentKit.call.createRegistry(registryName));
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
this.createRegistry = ({ registryName }) => {
|
|
95
|
-
return (0, import_payment_kit.createRegistry)({
|
|
96
|
-
arguments: {
|
|
97
|
-
namespace: __privateGet(this, _packageConfig).namespaceId,
|
|
98
|
-
name: registryName
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Creates a `setConfigEpochExpirationDuration` transaction
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```ts
|
|
107
|
-
* tx.add(client.paymentKit.call.setConfigEpochExpirationDuration({registryName, epochExpirationDuration, adminCapId}));
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
this.setConfigEpochExpirationDuration = ({
|
|
111
|
-
registryName,
|
|
112
|
-
registryId,
|
|
113
|
-
epochExpirationDuration,
|
|
114
|
-
adminCapId
|
|
115
|
-
}) => {
|
|
116
|
-
const registryIdToUse = registryId ?? (0, import_utils.getRegistryIdFromName)(registryName, __privateGet(this, _packageConfig).namespaceId);
|
|
117
|
-
return (0, import_payment_kit.setConfigEpochExpirationDuration)({
|
|
118
|
-
arguments: {
|
|
119
|
-
registry: registryIdToUse,
|
|
120
|
-
epochExpirationDuration,
|
|
121
|
-
cap: adminCapId
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Creates a `setConfigRegistryManagedFunds` transaction
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* tx.add(client.paymentKit.call.setConfigRegistryManagedFunds({registryName, registryManagedFunds, adminCapId}));
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
this.setConfigRegistryManagedFunds = ({
|
|
134
|
-
registryName,
|
|
135
|
-
registryId,
|
|
136
|
-
registryManagedFunds,
|
|
137
|
-
adminCapId
|
|
138
|
-
}) => {
|
|
139
|
-
const registryIdToUse = registryId ?? (0, import_utils.getRegistryIdFromName)(registryName, __privateGet(this, _packageConfig).namespaceId);
|
|
140
|
-
return (0, import_payment_kit.setConfigRegistryManagedFunds)({
|
|
141
|
-
arguments: {
|
|
142
|
-
registry: registryIdToUse,
|
|
143
|
-
registryManagedFunds,
|
|
144
|
-
cap: adminCapId
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* Creates a `withdrawFromRegistry` transaction
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```ts
|
|
153
|
-
* tx.add(client.paymentKit.call.withdrawFromRegistry({coinType, registryName, adminCapId}));
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
this.withdrawFromRegistry = ({
|
|
157
|
-
coinType,
|
|
158
|
-
registryName,
|
|
159
|
-
registryId,
|
|
160
|
-
adminCapId
|
|
161
|
-
}) => {
|
|
162
|
-
const registryIdToUse = registryId ?? (0, import_utils.getRegistryIdFromName)(registryName, __privateGet(this, _packageConfig).namespaceId);
|
|
163
|
-
return (0, import_payment_kit.withdrawFromRegistry)({
|
|
164
|
-
arguments: {
|
|
165
|
-
registry: registryIdToUse,
|
|
166
|
-
cap: adminCapId
|
|
167
|
-
},
|
|
168
|
-
typeArguments: [coinType]
|
|
169
|
-
});
|
|
170
|
-
};
|
|
171
|
-
/**
|
|
172
|
-
* Creates a `deletePaymentRecord` transaction
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```ts
|
|
176
|
-
* tx.add(client.paymentKit.call.deletePaymentRecord({coinType, nonce, amount, receiver, registryName}));
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
179
|
-
this.deletePaymentRecord = ({
|
|
180
|
-
coinType,
|
|
181
|
-
nonce,
|
|
182
|
-
amount,
|
|
183
|
-
receiver,
|
|
184
|
-
registryName,
|
|
185
|
-
registryId
|
|
186
|
-
}) => {
|
|
187
|
-
const registryIdToUse = registryId ?? (0, import_utils.getRegistryIdFromName)(registryName, __privateGet(this, _packageConfig).namespaceId);
|
|
188
|
-
return (0, import_payment_kit.deletePaymentRecord)({
|
|
189
|
-
arguments: {
|
|
190
|
-
registry: registryIdToUse,
|
|
191
|
-
paymentKey: (0, import_payment_kit.createPaymentKey)({
|
|
192
|
-
arguments: {
|
|
193
|
-
nonce,
|
|
194
|
-
paymentAmount: amount,
|
|
195
|
-
receiver
|
|
196
|
-
},
|
|
197
|
-
typeArguments: [coinType]
|
|
198
|
-
})
|
|
199
|
-
},
|
|
200
|
-
typeArguments: [coinType]
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
__privateSet(this, _packageConfig, options.packageConfig);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
_packageConfig = new WeakMap();
|
|
207
|
-
//# sourceMappingURL=calls.js.map
|
package/dist/cjs/calls.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/calls.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport type {\n\tCreateRegistryOptions,\n\tDeletePaymentRecordOptions,\n\tPaymentKitPackageConfig,\n\tProcessEphemeralPaymentOptions,\n\tProcessRegistryPaymentOptions,\n\tSetEpochExpirationDurationOptions,\n\tSetRegistryManagedFundsOptions,\n\tWithdrawFromRegistryOptions,\n} from './types.js';\nimport {\n\tcreatePaymentKey,\n\tcreateRegistry,\n\tdeletePaymentRecord,\n\tprocessEphemeralPayment,\n\tprocessRegistryPayment,\n\tsetConfigEpochExpirationDuration,\n\tsetConfigRegistryManagedFunds,\n\twithdrawFromRegistry,\n} from './contracts/payment_kit/payment_kit.js';\nimport { getRegistryIdFromName } from './utils.js';\n\nexport interface PaymentKitCallOptions {\n\tpackageConfig: PaymentKitPackageConfig;\n}\n\nexport class PaymentKitCalls {\n\t#packageConfig: PaymentKitPackageConfig;\n\n\tconstructor(options: PaymentKitCallOptions) {\n\t\tthis.#packageConfig = options.packageConfig;\n\t}\n\n\t/**\n\t * Creates a `processRegistryPayment` transaction\n\t *\n\t * @example\n\t * ```ts\n\t * tx.add(lient.paymentKit.call.processRegistryPayment({ nonce, coinType, sender, amount, receiver, registryName }));\n\t * ```\n\t */\n\tprocessRegistryPayment = (options: ProcessRegistryPaymentOptions) => {\n\t\tconst { nonce, coinType, amount, receiver, sourceCoin, registryName, registryId } = options;\n\t\tconst registryIdToUse =\n\t\t\tregistryId ?? getRegistryIdFromName(registryName, this.#packageConfig.namespaceId);\n\n\t\treturn processRegistryPayment({\n\t\t\targuments: {\n\t\t\t\tregistry: registryIdToUse,\n\t\t\t\tnonce,\n\t\t\t\tpaymentAmount: amount,\n\t\t\t\tcoin:\n\t\t\t\t\tsourceCoin ??\n\t\t\t\t\tcoinWithBalance({\n\t\t\t\t\t\ttype: coinType,\n\t\t\t\t\t\tbalance: amount,\n\t\t\t\t\t}),\n\t\t\t\treceiver,\n\t\t\t},\n\t\t\ttypeArguments: [coinType],\n\t\t});\n\t};\n\n\t/**\n\t * Creates a `processRegistryPayment` transaction\n\t *\n\t * @example\n\t * ```ts\n\t * tx.add(client.paymentKit.call.processEphemeralPayment({ nonce, coinType, sender, amount, receiver }));\n\t * ```\n\t */\n\tprocessEphemeralPayment = (options: ProcessEphemeralPaymentOptions) => {\n\t\tconst { nonce, coinType, amount, receiver, sourceCoin } = options;\n\n\t\treturn processEphemeralPayment({\n\t\t\targuments: {\n\t\t\t\tnonce: nonce,\n\t\t\t\tpaymentAmount: amount,\n\t\t\t\tcoin:\n\t\t\t\t\tsourceCoin ??\n\t\t\t\t\tcoinWithBalance({\n\t\t\t\t\t\ttype: coinType,\n\t\t\t\t\t\tbalance: amount,\n\t\t\t\t\t}),\n\t\t\t\treceiver,\n\t\t\t},\n\t\t\ttypeArguments: [coinType],\n\t\t});\n\t};\n\n\t/**\n\t * Creates a `createRegistry` transaction\n\t *\n\t * @example\n\t * ```ts\n\t * tx.add(client.paymentKit.call.createRegistry(registryName));\n\t * ```\n\t */\n\tcreateRegistry = ({ registryName }: CreateRegistryOptions) => {\n\t\treturn createRegistry({\n\t\t\targuments: {\n\t\t\t\tnamespace: this.#packageConfig.namespaceId,\n\t\t\t\tname: registryName,\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a `setConfigEpochExpirationDuration` transaction\n\t *\n\t * @example\n\t * ```ts\n\t * tx.add(client.paymentKit.call.setConfigEpochExpirationDuration({registryName, epochExpirationDuration, adminCapId}));\n\t * ```\n\t */\n\tsetConfigEpochExpirationDuration = ({\n\t\tregistryName,\n\t\tregistryId,\n\t\tepochExpirationDuration,\n\t\tadminCapId,\n\t}: SetEpochExpirationDurationOptions) => {\n\t\tconst registryIdToUse =\n\t\t\tregistryId ?? getRegistryIdFromName(registryName, this.#packageConfig.namespaceId);\n\n\t\treturn setConfigEpochExpirationDuration({\n\t\t\targuments: {\n\t\t\t\tregistry: registryIdToUse,\n\t\t\t\tepochExpirationDuration,\n\t\t\t\tcap: adminCapId,\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a `setConfigRegistryManagedFunds` transaction\n\t *\n\t * @example\n\t * ```ts\n\t * tx.add(client.paymentKit.call.setConfigRegistryManagedFunds({registryName, registryManagedFunds, adminCapId}));\n\t * ```\n\t */\n\tsetConfigRegistryManagedFunds = ({\n\t\tregistryName,\n\t\tregistryId,\n\t\tregistryManagedFunds,\n\t\tadminCapId,\n\t}: SetRegistryManagedFundsOptions) => {\n\t\tconst registryIdToUse =\n\t\t\tregistryId ?? getRegistryIdFromName(registryName, this.#packageConfig.namespaceId);\n\n\t\treturn setConfigRegistryManagedFunds({\n\t\t\targuments: {\n\t\t\t\tregistry: registryIdToUse,\n\t\t\t\tregistryManagedFunds,\n\t\t\t\tcap: adminCapId,\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a `withdrawFromRegistry` transaction\n\t *\n\t * @example\n\t * ```ts\n\t * tx.add(client.paymentKit.call.withdrawFromRegistry({coinType, registryName, adminCapId}));\n\t * ```\n\t */\n\twithdrawFromRegistry = ({\n\t\tcoinType,\n\t\tregistryName,\n\t\tregistryId,\n\t\tadminCapId,\n\t}: WithdrawFromRegistryOptions) => {\n\t\tconst registryIdToUse =\n\t\t\tregistryId ?? getRegistryIdFromName(registryName, this.#packageConfig.namespaceId);\n\n\t\treturn withdrawFromRegistry({\n\t\t\targuments: {\n\t\t\t\tregistry: registryIdToUse,\n\t\t\t\tcap: adminCapId,\n\t\t\t},\n\t\t\ttypeArguments: [coinType],\n\t\t});\n\t};\n\n\t/**\n\t * Creates a `deletePaymentRecord` transaction\n\t *\n\t * @example\n\t * ```ts\n\t * tx.add(client.paymentKit.call.deletePaymentRecord({coinType, nonce, amount, receiver, registryName}));\n\t * ```\n\t */\n\tdeletePaymentRecord = ({\n\t\tcoinType,\n\t\tnonce,\n\t\tamount,\n\t\treceiver,\n\t\tregistryName,\n\t\tregistryId,\n\t}: DeletePaymentRecordOptions) => {\n\t\tconst registryIdToUse =\n\t\t\tregistryId ?? getRegistryIdFromName(registryName, this.#packageConfig.namespaceId);\n\n\t\treturn deletePaymentRecord({\n\t\t\targuments: {\n\t\t\t\tregistry: registryIdToUse,\n\t\t\t\tpaymentKey: createPaymentKey({\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tnonce,\n\t\t\t\t\t\tpaymentAmount: amount,\n\t\t\t\t\t\treceiver,\n\t\t\t\t\t},\n\t\t\t\t\ttypeArguments: [coinType],\n\t\t\t\t}),\n\t\t\t},\n\t\t\ttypeArguments: [coinType],\n\t\t});\n\t};\n}\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/cjs/client.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { PaymentKitClientOptions, GetPaymentRecordOptions, GetPaymentRecordResponse } from './types.js';
|
|
2
|
-
import type { ClientWithCoreApi } from '@mysten/sui/experimental';
|
|
3
|
-
import { PaymentKitTransactions } from './transactions.js';
|
|
4
|
-
import { PaymentKitCalls } from './calls.js';
|
|
5
|
-
export declare function paymentKit<const Name = 'paymentKit'>({ name }?: {
|
|
6
|
-
name?: Name | undefined;
|
|
7
|
-
}): {
|
|
8
|
-
name: Name;
|
|
9
|
-
register: (client: ClientWithCoreApi) => PaymentKitClient;
|
|
10
|
-
};
|
|
11
|
-
export declare class PaymentKitClient {
|
|
12
|
-
#private;
|
|
13
|
-
calls: PaymentKitCalls;
|
|
14
|
-
tx: PaymentKitTransactions;
|
|
15
|
-
constructor(options: PaymentKitClientOptions);
|
|
16
|
-
/**
|
|
17
|
-
* Query for a payment record in a registry.
|
|
18
|
-
* Returns the payment record data if it exists, null otherwise.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* const paymentRecord = await client.getPaymentRecord({ registry, nonce, amount, receiver, coinType });
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
getPaymentRecord(options: GetPaymentRecordOptions): Promise<GetPaymentRecordResponse | null>;
|
|
26
|
-
/**
|
|
27
|
-
* Get the registry object id from a registry name.
|
|
28
|
-
* Returns the derived registry id.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* const registryId = await client.getRegistryIdFromName("my-registry");
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
getRegistryIdFromName(registryName: string): string;
|
|
36
|
-
}
|