@shelby-protocol/sdk 0.0.9 → 0.2.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.
Files changed (99) hide show
  1. package/dist/browser/index.d.ts +17 -10
  2. package/dist/browser/index.mjs +89 -28
  3. package/dist/{chunk-XWAPNLU6.mjs → chunk-2WEX3K7C.mjs} +6 -4
  4. package/dist/chunk-4MG4XGY4.mjs +91 -0
  5. package/dist/{chunk-SEXQTDX6.mjs → chunk-4ZOFT75Q.mjs} +16 -2
  6. package/dist/{chunk-BTHSKDJR.mjs → chunk-7PN65RDX.mjs} +44 -10
  7. package/dist/chunk-AABBONAF.mjs +34 -0
  8. package/dist/{chunk-ZPW742E7.mjs → chunk-AUQDI5BS.mjs} +17 -2
  9. package/dist/{chunk-HFGEQP5N.mjs → chunk-CGYJLKBU.mjs} +4 -4
  10. package/dist/chunk-CQ6QPIZK.mjs +37 -0
  11. package/dist/{chunk-VRLIOKWG.mjs → chunk-D6GQHO6G.mjs} +5 -1
  12. package/dist/chunk-E5QCRTBU.mjs +493 -0
  13. package/dist/chunk-HPPMI7DC.mjs +56 -0
  14. package/dist/chunk-IE6LYVIA.mjs +26 -0
  15. package/dist/{chunk-67F5YZ25.mjs → chunk-JTXYKO3U.mjs} +10 -0
  16. package/dist/{chunk-WJKSPJSS.mjs → chunk-KJ24NKPH.mjs} +46 -0
  17. package/dist/{chunk-WBFEX7OM.mjs → chunk-MV6FNYAU.mjs} +31 -7
  18. package/dist/{chunk-PZF2VTGP.mjs → chunk-NHWWORCH.mjs} +3 -1
  19. package/dist/{chunk-NLPIHQ7K.mjs → chunk-OGKZ575S.mjs} +6 -19
  20. package/dist/{chunk-5I3MBJGN.mjs → chunk-PJVWGMVI.mjs} +164 -35
  21. package/dist/{chunk-7UVMDCCR.mjs → chunk-SRV4YWFH.mjs} +232 -47
  22. package/dist/chunk-W37FZSMA.mjs +83 -0
  23. package/dist/chunk-WTICJPDB.mjs +0 -0
  24. package/dist/chunk-Z4FZ7W6L.mjs +39 -0
  25. package/dist/{chunk-QFWQ7FIC.mjs → chunk-ZEDD2MPU.mjs} +1 -1
  26. package/dist/{clay-codes-pdZFxI_B.d.ts → clay-codes-DHP-bYcP.d.ts} +6 -2
  27. package/dist/core/blobs.d.ts +2 -0
  28. package/dist/core/chunk.d.ts +10 -1
  29. package/dist/core/chunk.mjs +2 -2
  30. package/dist/core/clients/ShelbyBlobClient.d.ts +165 -12
  31. package/dist/core/clients/ShelbyBlobClient.mjs +13 -11
  32. package/dist/core/clients/ShelbyClient.d.ts +21 -4
  33. package/dist/core/clients/ShelbyClient.mjs +17 -14
  34. package/dist/core/clients/ShelbyClientConfig.d.ts +7 -2
  35. package/dist/{node → core}/clients/ShelbyMetadataClient.d.ts +3 -3
  36. package/dist/core/clients/ShelbyMetadataClient.mjs +9 -0
  37. package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +349 -0
  38. package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +16 -0
  39. package/dist/core/clients/ShelbyPlacementGroupClient.d.ts +73 -0
  40. package/dist/core/clients/ShelbyPlacementGroupClient.mjs +11 -0
  41. package/dist/core/clients/ShelbyRPCClient.d.ts +30 -4
  42. package/dist/core/clients/ShelbyRPCClient.mjs +8 -8
  43. package/dist/core/clients/index.d.ts +11 -5
  44. package/dist/core/clients/index.mjs +35 -15
  45. package/dist/core/clients/utils.d.ts +54 -0
  46. package/dist/core/clients/utils.mjs +1 -1
  47. package/dist/core/commitments.d.ts +6 -2
  48. package/dist/core/commitments.mjs +5 -3
  49. package/dist/core/constants.d.ts +18 -3
  50. package/dist/core/constants.mjs +5 -1
  51. package/dist/core/erasure/clay-codes.d.ts +1 -1
  52. package/dist/core/erasure/clay-codes.mjs +5 -5
  53. package/dist/core/erasure/constants.d.ts +15 -3
  54. package/dist/core/erasure/constants.mjs +3 -1
  55. package/dist/core/erasure/default.d.ts +5 -2
  56. package/dist/core/erasure/default.mjs +12 -6
  57. package/dist/core/erasure/index.d.ts +3 -3
  58. package/dist/core/erasure/index.mjs +15 -7
  59. package/dist/core/erasure/provider.d.ts +1 -1
  60. package/dist/core/erasure/reed-solomon.d.ts +1 -1
  61. package/dist/core/erasure/reed-solomon.mjs +1 -1
  62. package/dist/core/erasure/utils.d.ts +1 -1
  63. package/dist/core/errors.d.ts +58 -0
  64. package/dist/core/errors.mjs +15 -0
  65. package/dist/core/index.d.ts +17 -10
  66. package/dist/core/index.mjs +89 -28
  67. package/dist/core/layout.d.ts +5 -16
  68. package/dist/core/layout.mjs +3 -9
  69. package/dist/core/networks.d.ts +1 -1
  70. package/dist/core/networks.mjs +1 -1
  71. package/dist/core/operations/generated/sdk.d.ts +207 -17
  72. package/dist/core/operations/generated/sdk.mjs +7 -1
  73. package/dist/core/operations/index.d.ts +9 -3
  74. package/dist/core/operations/index.mjs +10 -4
  75. package/dist/core/rpc-responses.d.ts +69 -0
  76. package/dist/core/rpc-responses.mjs +15 -0
  77. package/dist/core/types/blobs.d.ts +8 -4
  78. package/dist/core/types/encodings.d.ts +1 -1
  79. package/dist/core/types/index.d.ts +4 -2
  80. package/dist/core/types/index.mjs +12 -2
  81. package/dist/core/types/payments.d.ts +94 -0
  82. package/dist/core/types/payments.mjs +9 -0
  83. package/dist/core/types/placement_groups.d.ts +30 -1
  84. package/dist/core/types/placement_groups.mjs +1 -0
  85. package/dist/core/types/storage_providers.d.ts +32 -2
  86. package/dist/node/clients/ShelbyNodeClient.d.ts +9 -6
  87. package/dist/node/clients/ShelbyNodeClient.mjs +18 -15
  88. package/dist/node/clients/index.d.ts +7 -6
  89. package/dist/node/clients/index.mjs +19 -17
  90. package/dist/node/index.d.ts +17 -11
  91. package/dist/node/index.mjs +91 -34
  92. package/package.json +3 -2
  93. package/dist/chunk-CPNZAQVY.mjs +0 -29
  94. package/dist/chunk-GY5DCVVL.mjs +0 -86
  95. package/dist/chunk-RBFWGDMY.mjs +0 -30
  96. package/dist/node/clients/ShelbyMetadataClient.mjs +0 -9
  97. /package/dist/{chunk-DJJD2AXO.mjs → chunk-AD2G3QYD.mjs} +0 -0
  98. /package/dist/{chunk-MWDW4ROU.mjs → chunk-EM67QTMR.mjs} +0 -0
  99. /package/dist/{chunk-RNXGC54D.mjs → chunk-QQ57OGQ2.mjs} +0 -0
@@ -1,6 +1,7 @@
1
1
  // src/core/erasure/constants.ts
2
2
  var ErasureCodingScheme = /* @__PURE__ */ ((ErasureCodingScheme2) => {
3
3
  ErasureCodingScheme2["ClayCode_16Total_10Data_13Helper"] = "ClayCode_16Total_10Data_13Helper";
4
+ ErasureCodingScheme2["ClayCode_4Total_2Data_3Helper"] = "ClayCode_4Total_2Data_3Helper";
4
5
  return ErasureCodingScheme2;
5
6
  })(ErasureCodingScheme || {});
6
7
  var ERASURE_CODE_PARAMS = {
@@ -10,13 +11,26 @@ var ERASURE_CODE_PARAMS = {
10
11
  // data chunks
11
12
  erasure_k: 10,
12
13
  // helper nodes
13
- erasure_d: 13
14
+ erasure_d: 13,
15
+ // enum index
16
+ enumIndex: 0
17
+ },
18
+ ["ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */]: {
19
+ // total chunks (data + parity)
20
+ erasure_n: 4,
21
+ // data chunks
22
+ erasure_k: 2,
23
+ // helper nodes
24
+ erasure_d: 3,
25
+ // enum index
26
+ enumIndex: 1
14
27
  }
15
28
  };
16
29
  var DEFAULT_ERASURE_N = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_n;
17
30
  var DEFAULT_ERASURE_K = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_k;
18
31
  var DEFAULT_ERASURE_D = ERASURE_CODE_PARAMS["ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */].erasure_d;
19
32
  var DEFAULT_ERASURE_M = DEFAULT_ERASURE_N - DEFAULT_ERASURE_K;
33
+ var DEFAULT_SAMPLE_SIZE = 1024;
20
34
 
21
35
  export {
22
36
  ErasureCodingScheme,
@@ -24,5 +38,6 @@ export {
24
38
  DEFAULT_ERASURE_N,
25
39
  DEFAULT_ERASURE_K,
26
40
  DEFAULT_ERASURE_D,
27
- DEFAULT_ERASURE_M
41
+ DEFAULT_ERASURE_M,
42
+ DEFAULT_SAMPLE_SIZE
28
43
  };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  getSdk
3
- } from "./chunk-WJKSPJSS.mjs";
3
+ } from "./chunk-KJ24NKPH.mjs";
4
4
  import {
5
5
  getAptosConfig
6
- } from "./chunk-RBFWGDMY.mjs";
6
+ } from "./chunk-AABBONAF.mjs";
7
7
  import {
8
8
  NetworkToShelbyBlobIndexerBaseUrl
9
- } from "./chunk-SEXQTDX6.mjs";
9
+ } from "./chunk-4ZOFT75Q.mjs";
10
10
 
11
11
  // src/core/operations/index.ts
12
12
  import { Network } from "@aptos-labs/ts-sdk";
@@ -16,7 +16,7 @@ function createShelbyIndexerClient(baseUrl, options) {
16
16
  return getSdk(graphqlClient);
17
17
  }
18
18
  function getShelbyIndexerClient(config) {
19
- const aptosConfig = config.aptos ?? getAptosConfig(config);
19
+ const aptosConfig = getAptosConfig(config);
20
20
  let { apiKey: indexerApiKey, baseUrl } = config.indexer ?? {};
21
21
  if (!baseUrl) {
22
22
  switch (aptosConfig?.network) {
@@ -0,0 +1,37 @@
1
+ // src/core/errors.ts
2
+ var ShelbyErrorCodes = {
3
+ // blob_metadata.move errors
4
+ E_BLOB_NOT_FOUND: "E_BLOB_NOT_FOUND",
5
+ E_INVALID_EXPIRATION_TIME: "E_INVALID_EXPIRATION_TIME",
6
+ E_TEST_ENCODING_NOT_ALLOWED: "E_TEST_ENCODING_NOT_ALLOWED",
7
+ E_BLOB_NOT_EXPIRED: "E_BLOB_NOT_EXPIRED",
8
+ E_INVALID_CHUNKSET_COUNT: "E_INVALID_CHUNKSET_COUNT",
9
+ E_NOT_BLOB_OWNER: "E_NOT_BLOB_OWNER",
10
+ E_NOT_ADMIN: "E_NOT_ADMIN",
11
+ E_BLOB_EXPIRED: "E_BLOB_EXPIRED",
12
+ E_BLOB_NAME_TOO_LONG: "E_BLOB_NAME_TOO_LONG",
13
+ E_INVALID_PAYMENT_EPOCHS: "E_INVALID_PAYMENT_EPOCHS",
14
+ E_NO_SLICES_AVAILABLE: "E_NO_SLICES_AVAILABLE",
15
+ // Common Aptos/Move errors
16
+ EALREADY_EXISTS: "EALREADY_EXISTS"
17
+ };
18
+ function isBlobAlreadyExistsError(errorMessage) {
19
+ return errorMessage.includes(ShelbyErrorCodes.EALREADY_EXISTS) || errorMessage.includes("already exists");
20
+ }
21
+ function isAccessDeniedError(errorMessage) {
22
+ return errorMessage.includes(ShelbyErrorCodes.E_NOT_BLOB_OWNER) || errorMessage.includes(ShelbyErrorCodes.E_NOT_ADMIN) || errorMessage.includes("ENOT_AUTHORIZED") || errorMessage.includes("not authorized") || errorMessage.includes("permission denied");
23
+ }
24
+ function isBlobNotFoundError(errorMessage) {
25
+ return errorMessage.includes(ShelbyErrorCodes.E_BLOB_NOT_FOUND);
26
+ }
27
+ function isBlobExpiredError(errorMessage) {
28
+ return errorMessage.includes(ShelbyErrorCodes.E_BLOB_EXPIRED);
29
+ }
30
+
31
+ export {
32
+ ShelbyErrorCodes,
33
+ isBlobAlreadyExistsError,
34
+ isAccessDeniedError,
35
+ isBlobNotFoundError,
36
+ isBlobExpiredError
37
+ };
@@ -1,6 +1,10 @@
1
1
  // src/core/networks.ts
2
2
  import { Network } from "@aptos-labs/ts-sdk";
3
- var shelbyNetworks = [Network.LOCAL, Network.SHELBYNET];
3
+ var shelbyNetworks = [
4
+ Network.LOCAL,
5
+ Network.TESTNET,
6
+ Network.SHELBYNET
7
+ ];
4
8
  var isShelbyNetwork = (network) => {
5
9
  return shelbyNetworks.includes(network.toLowerCase());
6
10
  };
@@ -0,0 +1,493 @@
1
+ import {
2
+ SenderBuiltMicropayment
3
+ } from "./chunk-4MG4XGY4.mjs";
4
+ import {
5
+ getShelbyIndexerClient
6
+ } from "./chunk-CGYJLKBU.mjs";
7
+ import {
8
+ getAptosConfig
9
+ } from "./chunk-AABBONAF.mjs";
10
+ import {
11
+ MICROPAYMENTS_DEPLOYER
12
+ } from "./chunk-4ZOFT75Q.mjs";
13
+
14
+ // src/core/clients/ShelbyMicropaymentChannelClient.ts
15
+ import {
16
+ AccountAddress,
17
+ Aptos
18
+ } from "@aptos-labs/ts-sdk";
19
+ var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
20
+ aptos;
21
+ deployer;
22
+ indexer;
23
+ /**
24
+ * The ShelbyMicropaymentChannelClient is used to interact with the Micropayment contract on the Aptos blockchain. This
25
+ * includes functions for the full lifecycle of micropayment channels: creation, withdrawals, expiration extensions, etc.
26
+ *
27
+ * @param config - The client configuration object.
28
+ * @param config.network - The Shelby network to use.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const client = new ShelbyMicropaymentChannelClient({
33
+ * aptos: {
34
+ * network: Network.SHELBYNET,
35
+ * clientConfig: {
36
+ * API_KEY: "AG-***",
37
+ * },
38
+ * },
39
+ * });
40
+ * ```
41
+ */
42
+ constructor(config) {
43
+ this.aptos = new Aptos(getAptosConfig(config));
44
+ this.deployer = config.deployer ?? AccountAddress.fromString(MICROPAYMENTS_DEPLOYER);
45
+ this.indexer = getShelbyIndexerClient(config);
46
+ }
47
+ /**
48
+ * Calls initialize function so caller can thereafter create micropayment channels.
49
+ *
50
+ * @param params.sender - The account that will be sending funds to various receivers in micropayment channels.
51
+ * @param params.options - Optional transaction building options.
52
+ *
53
+ * @returns An object containing the pending transaction.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ *
58
+ * const { transaction } = await client.initializePaymentChannels({
59
+ * sender: sender,
60
+ * });
61
+ * ```
62
+ */
63
+ async initializePaymentChannels(params) {
64
+ const transaction = await this.aptos.transaction.build.simple({
65
+ options: params.options,
66
+ data: {
67
+ function: `${(this.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::initialize_payment_channels`,
68
+ functionArguments: []
69
+ },
70
+ sender: params.sender.accountAddress
71
+ });
72
+ return {
73
+ transaction: await this.aptos.signAndSubmitTransaction({
74
+ signer: params.sender,
75
+ transaction
76
+ })
77
+ };
78
+ }
79
+ /**
80
+ * Creates a micropayment channel to start a channel bweteen a sender and a receiver for a specific asset.
81
+ *
82
+ * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
83
+ * @param params.sender - The account that will be sending funds.
84
+ * @param params.receiver - The account that will be receiving funds.
85
+ * @param params.expirationMicros - The expiration of the micropayment channel.
86
+ * @param params.depositAmount - The amount of the asset locked to the channel.
87
+ * @param params.fungibleAssetAddress - The account address of the fungible asset.
88
+ * @param params.options - Optional transaction building options.
89
+ *
90
+ * @returns An object containing the pending transaction.
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ *
95
+ * const { transaction } = await client.createChannel({
96
+ * sender: sender,
97
+ * receiver: receiver,
98
+ * expirationMicros: Date.now() * 1000 + 86400_000_000, // 1 day from now in microseconds
99
+ * depositAmount: 0.001,
100
+ * fungibleAssetAddress: fungibleAssetAddress,
101
+ * });
102
+ * ```
103
+ */
104
+ async createChannel(params) {
105
+ const transaction = await this.aptos.transaction.build.simple({
106
+ options: params.options,
107
+ data: _ShelbyMicropaymentChannelClient.makeCreateMicropaymentChannelPayload(
108
+ {
109
+ deployer: this.deployer,
110
+ receiver: params.receiver,
111
+ expirationMicros: params.expirationMicros,
112
+ depositAmount: params.depositAmount,
113
+ fungibleAssetAddress: params.fungibleAssetAddress
114
+ }
115
+ ),
116
+ sender: params.sender.accountAddress
117
+ });
118
+ return {
119
+ transaction: await this.aptos.signAndSubmitTransaction({
120
+ signer: params.sender,
121
+ transaction
122
+ })
123
+ };
124
+ }
125
+ /**
126
+ * Creates a micropayment channel creation payload to start a channel between a sender and a receiver for a specific asset.
127
+ * This is a static helper method for constructing the Move function call payload.
128
+ *
129
+ * @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
130
+ * @param params.sender - The account that will be sending funds.
131
+ * @param params.receiver - The account that will be receiving funds.
132
+ * @param params.expirationMicros - The expiration of the micropayment channel.
133
+ * @param params.depositAmount - The amount of the asset locked to the channel.
134
+ * @param params.fungibleAssetAddress - The account address of the fungible asset.
135
+ *
136
+ * @returns An Aptos transaction payload data object for the create_channel Move function.
137
+ */
138
+ static makeCreateMicropaymentChannelPayload(params) {
139
+ return {
140
+ function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::create_channel`,
141
+ functionArguments: [
142
+ params.receiver,
143
+ params.expirationMicros,
144
+ params.depositAmount,
145
+ params.fungibleAssetAddress
146
+ ]
147
+ };
148
+ }
149
+ /**
150
+ * Withdraws funds from a micropayment channel as the sender.
151
+ *
152
+ * @param params.sender - The account that is withdrawing funds.
153
+ * @param params.receiver - The account the channel is configured to send funds to.
154
+ * @param params.fungibleAssetAddress - The account address of the fungible asset.
155
+ * @param params.options - Optional transaction generation options.
156
+ *
157
+ * @returns An object containing the pending transaction.
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const { transaction } = await client.senderWithdraw({
162
+ * sender: sender,
163
+ * receiver: receiver,
164
+ * fungibleAssetAddress: fungibleAssetAddress,
165
+ * });
166
+ * ```
167
+ */
168
+ async senderWithdraw(params) {
169
+ const transaction = await this.aptos.transaction.build.simple({
170
+ options: params.options,
171
+ data: _ShelbyMicropaymentChannelClient.createSenderWithdrawPayload({
172
+ deployer: this.deployer,
173
+ receiver: params.receiver,
174
+ fungibleAssetAddress: params.fungibleAssetAddress
175
+ }),
176
+ sender: params.sender.accountAddress
177
+ });
178
+ return {
179
+ transaction: await this.aptos.signAndSubmitTransaction({
180
+ signer: params.sender,
181
+ transaction
182
+ })
183
+ };
184
+ }
185
+ /**
186
+ * Creates a static payload for the sender_withdraw Move function.
187
+ * This is a helper method for constructing the transaction payload without signing.
188
+ *
189
+ * @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
190
+ * @param params.receiver - The account address of the receiver.
191
+ * @param params.fungibleAssetAddress - The account address of the fungible asset.
192
+ *
193
+ * @returns An Aptos transaction payload data object for the sender_withdraw Move function.
194
+ */
195
+ static createSenderWithdrawPayload(params) {
196
+ return {
197
+ function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::sender_withdraw`,
198
+ functionArguments: [params.receiver, params.fungibleAssetAddress]
199
+ };
200
+ }
201
+ /**
202
+ * Creates a micropayment that can be sent to a receiver.
203
+ *
204
+ * @param params.sender - The account address of the sender.
205
+ * @param params.receiver - The account that is withdrawing funds.
206
+ * @param params.amount - The amount to withdraw into the receiver's account.
207
+ * @param params.paymentChannelId - The id of the payment channel.
208
+ * @param params.sequenceNumber - The sequence number of the micropayment. These must be increasing to be able to store on chain.
209
+ * @param params.fungibleAssetAddress - The account address of the fungible asset.
210
+ * @param params.options - Optional transaction generation options.
211
+ *
212
+ * @returns An object containing the pending transaction and signature.
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * const senderBuiltMicropayment = await client.createMicropayment({
217
+ * sender: senderAddress,
218
+ * receiver: receiver,
219
+ * amount: 1,
220
+ * paymentChannelId: channelIdFromLookup,
221
+ * sequenceNumber: localSequenceNumber,
222
+ * fungibleAssetAddress: fungibleAssetAddress,
223
+ * });
224
+ * ```
225
+ */
226
+ async createMicropayment(params) {
227
+ const replayProtectionNonce = params.options?.replayProtectionNonce ?? Math.floor(Math.random() * 2 ** 24);
228
+ const {
229
+ accountSequenceNumber: _unusedSequenceNumber,
230
+ expireTimestamp: _unusedTimestamp,
231
+ ...restOptions
232
+ } = params.options ?? {};
233
+ const micropayment = await this.aptos.transaction.build.multiAgent({
234
+ options: {
235
+ ...restOptions,
236
+ replayProtectionNonce,
237
+ expireTimestamp: Math.floor(Date.now() / 1e3 + 60)
238
+ // 60 seconds from now
239
+ },
240
+ withFeePayer: true,
241
+ data: _ShelbyMicropaymentChannelClient.createMicropaymentTransactionPayload(
242
+ {
243
+ deployer: this.deployer,
244
+ amount: params.amount,
245
+ paymentChannelId: params.paymentChannelId,
246
+ sequenceNumber: params.sequenceNumber,
247
+ fungibleAssetAddress: params.fungibleAssetAddress
248
+ }
249
+ ),
250
+ sender: params.sender.accountAddress,
251
+ secondarySignerAddresses: [params.receiver]
252
+ });
253
+ return new SenderBuiltMicropayment(
254
+ micropayment,
255
+ this.aptos.sign({
256
+ signer: params.sender,
257
+ transaction: micropayment
258
+ })
259
+ );
260
+ }
261
+ /**
262
+ * Creates a static payload for the receiver_withdraw Move function. This is what
263
+ * constitutes a miropaymet.
264
+ * This is a helper method for constructing the transaction payload without signing.
265
+ *
266
+ * @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
267
+ * @param params.amount - The amount of the fungible asset's smallest increment to send.
268
+ * @param params.paymentChannelId - The payment channel id.
269
+ * @param params.fungibleAssetAddress - The account address of the fungible asset.
270
+ *
271
+ * @returns An Aptos transaction payload data object for the sender_withdraw Move function.
272
+ */
273
+ static createMicropaymentTransactionPayload(params) {
274
+ return {
275
+ function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::receiver_withdraw`,
276
+ functionArguments: [
277
+ params.amount,
278
+ params.paymentChannelId,
279
+ params.sequenceNumber,
280
+ params.fungibleAssetAddress
281
+ ]
282
+ };
283
+ }
284
+ /**
285
+ * Withdraws funds from a micropayment channel as the receiver. The receiver
286
+ * does this by signing and submitting a signed transaction the sender sent it.
287
+ *
288
+ * @param params.receiver - The receiver withdrawing funds.
289
+ * @param params.receiverSignature - The fee-paying transaction signature.
290
+ * @param params.micropayment - The fee-paying transaction signature.
291
+ * @param params.options - Optional transaction generation options.
292
+ *
293
+ * @returns An object containing the pending transaction.
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * const { transaction } = await client.receiverWithdraw({
298
+ * receiver: receiver,
299
+ * micropayment,
300
+ * senderSignature,
301
+ * });
302
+ * ```
303
+ */
304
+ async receiverWithdraw(params) {
305
+ const mySignature = this.aptos.signAsFeePayer({
306
+ signer: params.receiver,
307
+ transaction: params.micropayment.micropayment
308
+ });
309
+ return {
310
+ transaction: await this.aptos.transaction.submit.multiAgent({
311
+ transaction: params.micropayment.micropayment,
312
+ senderAuthenticator: params.micropayment.senderSignature,
313
+ additionalSignersAuthenticators: [mySignature],
314
+ feePayerAuthenticator: mySignature
315
+ })
316
+ };
317
+ }
318
+ /**
319
+ * Extends the expiration time of a micropayment channel.
320
+ *
321
+ * @param params.sender - The owner of the account.
322
+ * @param params.receiver - The account address of the receiver.
323
+ * @param params.fungibleAssetAddress - The account address of the fungible asset.
324
+ * @param params.newExpirationMicros - The new expiration time in microseconds.
325
+ * @param params.options - Optional transaction generation options.
326
+ *
327
+ * @returns An object containing the pending transaction.
328
+ *
329
+ * @example
330
+ * ```typescript
331
+ * const { transaction } = await client.extendExpirationTime({
332
+ * sender: sender,
333
+ * receiver: receiverAddress,
334
+ * fungibleAssetAddress: fungibleAssetAddress,
335
+ * newExpirationMicros: Date.now() * 1000 + 172800_000_000, // 2 days from now
336
+ * });
337
+ * ```
338
+ */
339
+ async extendExpirationTime(params) {
340
+ const transaction = await this.aptos.transaction.build.simple({
341
+ options: params.options,
342
+ data: _ShelbyMicropaymentChannelClient.makeExtendExpirationTimePayload({
343
+ deployer: this.deployer,
344
+ receiver: params.receiver,
345
+ fungibleAssetAddress: params.fungibleAssetAddress,
346
+ newExpirationMicros: params.newExpirationMicros
347
+ }),
348
+ sender: params.sender.accountAddress
349
+ });
350
+ return {
351
+ transaction: await this.aptos.signAndSubmitTransaction({
352
+ signer: params.sender,
353
+ transaction
354
+ })
355
+ };
356
+ }
357
+ /**
358
+ * Creates a payload to extend the expiration time on a micropayment channel.
359
+ * This is a static helper method for constructing the Move function call payload.
360
+ *
361
+ * @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
362
+ * @param params.receiver - The account that will be receiving funds.
363
+ * @param params.expirationMicros - The new expiration of the micropayment channel.
364
+ * @param params.fungibleAssetAddress - The account address of the fungible asset.
365
+ *
366
+ * @returns An Aptos transaction payload data object for the extend_expiration_time Move function.
367
+ */
368
+ static makeExtendExpirationTimePayload(params) {
369
+ return {
370
+ function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::extend_expiration_time`,
371
+ functionArguments: [
372
+ params.receiver,
373
+ params.fungibleAssetAddress,
374
+ params.newExpirationMicros
375
+ ]
376
+ };
377
+ }
378
+ /**
379
+ * Increases the deposit amount locked in a micropayment channel.
380
+ *
381
+ * @param params.sender - The account that is increasing the deposit.
382
+ * @param params.receiver - The account address of the receiver.
383
+ * @param params.fungibleAssetAddress - The account address of the fungible asset.
384
+ * @param params.additionalAmount - The additional amount to deposit.
385
+ * @param params.options - Optional transaction generation options.
386
+ *
387
+ * @returns An object containing the pending transaction.
388
+ *
389
+ * @example
390
+ * ```typescript
391
+ * const { transaction } = await client.increaseDepositAmount({
392
+ * sender: sender,
393
+ * receiver: receiverAddress,
394
+ * fungibleAssetAddress: fungibleAssetAddress,
395
+ * additionalAmount: 500,
396
+ * });
397
+ * ```
398
+ */
399
+ async increaseDepositAmount(params) {
400
+ const transaction = await this.aptos.transaction.build.simple({
401
+ options: params.options,
402
+ data: _ShelbyMicropaymentChannelClient.makeIncreaseDepositAmountPayload({
403
+ deployer: this.deployer,
404
+ receiver: params.receiver,
405
+ fungibleAssetAddress: params.fungibleAssetAddress,
406
+ additionalAmount: params.additionalAmount
407
+ }),
408
+ sender: params.sender.accountAddress
409
+ });
410
+ return {
411
+ transaction: await this.aptos.signAndSubmitTransaction({
412
+ signer: params.sender,
413
+ transaction
414
+ })
415
+ };
416
+ }
417
+ /**
418
+ * Creates a payload to increase the deposit amount on a micropayment channel.
419
+ * This is a static helper method for constructing the Move function call payload.
420
+ *
421
+ * @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
422
+ * @param params.receiver - The account that will be receiving funds.
423
+ * @param params.fungibleAssetAddress - The account address of the fungible asset.
424
+ * @param params.additionalAmount - The amount of the fungible asset to add to the channel's balance.
425
+ *
426
+ * @returns An Aptos transaction payload data object for the extend_expiration_time Move function.
427
+ */
428
+ static makeIncreaseDepositAmountPayload(params) {
429
+ return {
430
+ function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::increase_deposit_amount`,
431
+ functionArguments: [
432
+ params.receiver,
433
+ params.fungibleAssetAddress,
434
+ params.additionalAmount
435
+ ]
436
+ };
437
+ }
438
+ /**
439
+ * Retrieves the vector of channels owned by the sender, optionally
440
+ * filtered by the receiver.
441
+ *
442
+ * @param params.sender - The account namespace owning the micropayment channels.
443
+ * @param params.receiver? - An optional receiver account address.
444
+ * @returns A vector of ChannelInfo objects.
445
+ *
446
+ * @example
447
+ * ```typescript
448
+ * const channelInfoVec = await client.getChannelInfo({
449
+ * sender: AccountAddress.fromString("0x1"),
450
+ * receiver: AccountAddress.fromSTring("0x2"),
451
+ * });
452
+ * ```
453
+ */
454
+ async getChannelInfo(params) {
455
+ const functionName = params.receiver ? "get_all_channels_from_sender_to_receiver" : "get_all_channels_from_sender";
456
+ const functionArguments = [params.sender];
457
+ if (params.receiver) {
458
+ functionArguments.push(params.receiver);
459
+ }
460
+ const rawArray = await this.aptos.view({
461
+ payload: {
462
+ function: `${this.deployer.toString()}::micropayments::${functionName}`,
463
+ functionArguments
464
+ }
465
+ });
466
+ const channelInfoArray = rawArray[0];
467
+ return channelInfoArray.map(
468
+ (channelInfo) => {
469
+ return {
470
+ sender: params.sender,
471
+ receiver: params.receiver,
472
+ fungibleAssetAddress: AccountAddress.fromString(
473
+ channelInfo.asset_metadata.inner
474
+ ),
475
+ balance: Number(channelInfo.balance),
476
+ creationMicros: Number(channelInfo.creation_micros),
477
+ expirationMicros: Number(channelInfo.expiration_micros),
478
+ nextWithdrawnSequenceNumber: Number(
479
+ channelInfo.next_withdrawn_sequence_number
480
+ ),
481
+ paymentChannelId: Number(channelInfo.payment_channel_id),
482
+ receiverWithdrawnAmount: Number(
483
+ channelInfo.receiver_withdrawn_amount
484
+ )
485
+ };
486
+ }
487
+ );
488
+ }
489
+ };
490
+
491
+ export {
492
+ ShelbyMicropaymentChannelClient
493
+ };
@@ -0,0 +1,56 @@
1
+ import {
2
+ ClayErasureCodingProvider
3
+ } from "./chunk-OGKZ575S.mjs";
4
+ import {
5
+ DEFAULT_CHUNK_SIZE_BYTES
6
+ } from "./chunk-JTXYKO3U.mjs";
7
+ import {
8
+ ERASURE_CODE_PARAMS
9
+ } from "./chunk-AUQDI5BS.mjs";
10
+
11
+ // src/core/erasure/default.ts
12
+ var defaultProviderPromise;
13
+ function createDefaultErasureCodingProvider() {
14
+ if (!defaultProviderPromise) {
15
+ defaultProviderPromise = ClayErasureCodingProvider.create(
16
+ defaultErasureCodingConfig()
17
+ );
18
+ }
19
+ return defaultProviderPromise;
20
+ }
21
+ function defaultErasureCodingConfig() {
22
+ console.log(
23
+ `default erasure coding, with env: ${process.env.SHELBY_ENCODING}`
24
+ );
25
+ const encoding = Number(process.env.SHELBY_ENCODING) || 0;
26
+ if (encoding === 0) {
27
+ console.log("getting default erasure coding (16,10,13)");
28
+ return erasureCodingConfig16Total10Data13Helper();
29
+ }
30
+ console.log("getting default erasure coding (4,2,3)");
31
+ return erasureCodingConfig4Total2Data3Helper();
32
+ }
33
+ function erasureCodingConfig16Total10Data13Helper() {
34
+ return erasureCodingConfig(
35
+ "ClayCode_16Total_10Data_13Helper" /* ClayCode_16Total_10Data_13Helper */
36
+ );
37
+ }
38
+ function erasureCodingConfig4Total2Data3Helper() {
39
+ return erasureCodingConfig("ClayCode_4Total_2Data_3Helper" /* ClayCode_4Total_2Data_3Helper */);
40
+ }
41
+ function erasureCodingConfig(encodingScheme) {
42
+ return {
43
+ erasure_n: ERASURE_CODE_PARAMS[encodingScheme].erasure_n,
44
+ erasure_k: ERASURE_CODE_PARAMS[encodingScheme].erasure_k,
45
+ erasure_d: ERASURE_CODE_PARAMS[encodingScheme].erasure_d,
46
+ chunkSizeBytes: DEFAULT_CHUNK_SIZE_BYTES,
47
+ enumIndex: ERASURE_CODE_PARAMS[encodingScheme].enumIndex
48
+ };
49
+ }
50
+
51
+ export {
52
+ createDefaultErasureCodingProvider,
53
+ defaultErasureCodingConfig,
54
+ erasureCodingConfig16Total10Data13Helper,
55
+ erasureCodingConfig4Total2Data3Helper
56
+ };
@@ -0,0 +1,26 @@
1
+ // src/core/rpc-responses.ts
2
+ import { z } from "zod";
3
+ var StartMultipartUploadResponseSchema = z.object({
4
+ uploadId: z.string()
5
+ });
6
+ var UploadPartResponseSchema = z.object({
7
+ success: z.literal(true)
8
+ });
9
+ var CompleteMultipartUploadResponseSchema = z.object({
10
+ success: z.literal(true)
11
+ });
12
+ var RPCErrorResponseSchema = z.object({
13
+ error: z.string()
14
+ });
15
+ var StaleMicropaymentErrorResponseSchema = z.object({
16
+ error: z.string().optional(),
17
+ storedMicropayment: z.string().optional()
18
+ });
19
+
20
+ export {
21
+ StartMultipartUploadResponseSchema,
22
+ UploadPartResponseSchema,
23
+ CompleteMultipartUploadResponseSchema,
24
+ RPCErrorResponseSchema,
25
+ StaleMicropaymentErrorResponseSchema
26
+ };