@shelby-protocol/sdk 0.2.0 → 0.2.2

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 (48) hide show
  1. package/dist/browser/index.d.ts +1 -1
  2. package/dist/browser/index.mjs +31 -29
  3. package/dist/chunk-3NRBHSMQ.mjs +12 -0
  4. package/dist/{chunk-W37FZSMA.mjs → chunk-57RQAVKL.mjs} +1 -1
  5. package/dist/{chunk-4ZOFT75Q.mjs → chunk-7OV5ZYW6.mjs} +2 -2
  6. package/dist/{chunk-2WEX3K7C.mjs → chunk-BXEVML7N.mjs} +1 -1
  7. package/dist/{chunk-PJVWGMVI.mjs → chunk-E5PP7BZJ.mjs} +9 -9
  8. package/dist/{chunk-CGYJLKBU.mjs → chunk-EZPZAUIV.mjs} +1 -1
  9. package/dist/{chunk-ZEDD2MPU.mjs → chunk-FMPOGFDW.mjs} +1 -1
  10. package/dist/{chunk-MV6FNYAU.mjs → chunk-H53O23I7.mjs} +99 -20
  11. package/dist/{chunk-E5QCRTBU.mjs → chunk-H5YZHUSJ.mjs} +87 -75
  12. package/dist/{chunk-7PN65RDX.mjs → chunk-ONOOCOQ5.mjs} +16 -14
  13. package/dist/{chunk-SRV4YWFH.mjs → chunk-PESSW3FK.mjs} +52 -17
  14. package/dist/chunk-TVLV7C74.mjs +207 -0
  15. package/dist/{chunk-4JZO2D7T.mjs → chunk-UEZNZBJO.mjs} +9 -2
  16. package/dist/core/blobs.mjs +2 -1
  17. package/dist/core/clients/ShelbyBlobClient.d.ts +16 -0
  18. package/dist/core/clients/ShelbyBlobClient.mjs +8 -8
  19. package/dist/core/clients/ShelbyClient.mjs +13 -13
  20. package/dist/core/clients/ShelbyMetadataClient.d.ts +56 -5
  21. package/dist/core/clients/ShelbyMetadataClient.mjs +3 -2
  22. package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +39 -34
  23. package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +5 -4
  24. package/dist/core/clients/ShelbyPlacementGroupClient.mjs +3 -3
  25. package/dist/core/clients/ShelbyRPCClient.mjs +6 -6
  26. package/dist/core/clients/index.mjs +17 -17
  27. package/dist/core/commitments.mjs +2 -2
  28. package/dist/core/constants.d.ts +2 -2
  29. package/dist/core/constants.mjs +1 -1
  30. package/dist/core/index.d.ts +1 -1
  31. package/dist/core/index.mjs +31 -29
  32. package/dist/core/operations/generated/types.d.ts +908 -0
  33. package/dist/core/operations/generated/types.mjs +63 -0
  34. package/dist/core/operations/index.mjs +2 -2
  35. package/dist/core/types/index.mjs +2 -1
  36. package/dist/core/types/payments.d.ts +82 -9
  37. package/dist/core/types/payments.mjs +2 -1
  38. package/dist/core/types/placement_groups.d.ts +2 -2
  39. package/dist/core/types/storage_providers.d.ts +2 -2
  40. package/dist/core/utils.d.ts +3 -2
  41. package/dist/core/utils.mjs +3 -1
  42. package/dist/node/clients/ShelbyNodeClient.mjs +14 -14
  43. package/dist/node/clients/index.mjs +16 -16
  44. package/dist/node/index.d.ts +1 -1
  45. package/dist/node/index.mjs +32 -30
  46. package/package.json +1 -1
  47. package/dist/chunk-4MG4XGY4.mjs +0 -91
  48. package/dist/chunk-OTBLZL2S.mjs +0 -9
@@ -1,20 +1,24 @@
1
1
  import {
2
2
  SenderBuiltMicropayment
3
- } from "./chunk-4MG4XGY4.mjs";
3
+ } from "./chunk-TVLV7C74.mjs";
4
4
  import {
5
5
  getShelbyIndexerClient
6
- } from "./chunk-CGYJLKBU.mjs";
6
+ } from "./chunk-EZPZAUIV.mjs";
7
7
  import {
8
8
  getAptosConfig
9
9
  } from "./chunk-AABBONAF.mjs";
10
+ import {
11
+ normalizeAddress
12
+ } from "./chunk-UEZNZBJO.mjs";
10
13
  import {
11
14
  MICROPAYMENTS_DEPLOYER
12
- } from "./chunk-4ZOFT75Q.mjs";
15
+ } from "./chunk-7OV5ZYW6.mjs";
13
16
 
14
17
  // src/core/clients/ShelbyMicropaymentChannelClient.ts
15
18
  import {
16
19
  AccountAddress,
17
- Aptos
20
+ Aptos,
21
+ MoveVector
18
22
  } from "@aptos-labs/ts-sdk";
19
23
  var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
20
24
  aptos;
@@ -110,7 +114,8 @@ var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
110
114
  receiver: params.receiver,
111
115
  expirationMicros: params.expirationMicros,
112
116
  depositAmount: params.depositAmount,
113
- fungibleAssetAddress: params.fungibleAssetAddress
117
+ fungibleAssetAddress: params.fungibleAssetAddress,
118
+ publicKey: params.publicKey ?? params.sender.publicKey.toUint8Array()
114
119
  }
115
120
  ),
116
121
  sender: params.sender.accountAddress
@@ -132,6 +137,7 @@ var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
132
137
  * @param params.expirationMicros - The expiration of the micropayment channel.
133
138
  * @param params.depositAmount - The amount of the asset locked to the channel.
134
139
  * @param params.fungibleAssetAddress - The account address of the fungible asset.
140
+ * @param params.publicKey - The Ed25519 public key bytes for the channel.
135
141
  *
136
142
  * @returns An Aptos transaction payload data object for the create_channel Move function.
137
143
  */
@@ -142,7 +148,8 @@ var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
142
148
  params.receiver,
143
149
  params.expirationMicros,
144
150
  params.depositAmount,
145
- params.fungibleAssetAddress
151
+ params.fungibleAssetAddress,
152
+ MoveVector.U8(params.publicKey)
146
153
  ]
147
154
  };
148
155
  }
@@ -200,94 +207,86 @@ var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
200
207
  }
201
208
  /**
202
209
  * Creates a micropayment that can be sent to a receiver.
210
+ * The sender signs a WithdrawApproval message that authorizes the receiver
211
+ * to withdraw funds from the micropayment channel.
203
212
  *
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.
213
+ * @param params.sender - The account that owns the payment channel and signs the approval.
214
+ * @param params.receiver - The account address that will receive funds.
209
215
  * @param params.fungibleAssetAddress - The account address of the fungible asset.
210
- * @param params.options - Optional transaction generation options.
216
+ * @param params.amount - The cumulative amount to authorize (not incremental).
217
+ * @param params.paymentChannelId - The id of the payment channel.
218
+ * @param params.sequenceNumber - The sequence number of the micropayment. Must be >= channel's next_withdrawn_sequence_number.
211
219
  *
212
- * @returns An object containing the pending transaction and signature.
220
+ * @returns A SenderBuiltMicropayment containing the signed approval.
213
221
  *
214
222
  * @example
215
223
  * ```typescript
216
- * const senderBuiltMicropayment = await client.createMicropayment({
217
- * sender: senderAddress,
218
- * receiver: receiver,
219
- * amount: 1,
220
- * paymentChannelId: channelIdFromLookup,
221
- * sequenceNumber: localSequenceNumber,
224
+ * const senderBuiltMicropayment = client.createMicropayment({
225
+ * sender: senderAccount,
226
+ * receiver: receiverAddress,
222
227
  * fungibleAssetAddress: fungibleAssetAddress,
228
+ * amount: 100,
229
+ * paymentChannelId: channelId,
230
+ * sequenceNumber: 1,
223
231
  * });
224
232
  * ```
225
233
  */
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
- ),
234
+ createMicropayment(params) {
235
+ const message = SenderBuiltMicropayment.buildSignedMessage({
236
+ deployer: this.deployer,
250
237
  sender: params.sender.accountAddress,
251
- secondarySignerAddresses: [params.receiver]
238
+ receiver: params.receiver,
239
+ fungibleAssetAddress: params.fungibleAssetAddress,
240
+ amount: params.amount,
241
+ paymentChannelId: params.paymentChannelId,
242
+ sequenceNumber: params.sequenceNumber
252
243
  });
244
+ const signature = params.sender.sign(message);
253
245
  return new SenderBuiltMicropayment(
254
- micropayment,
255
- this.aptos.sign({
256
- signer: params.sender,
257
- transaction: micropayment
258
- })
246
+ params.sender.accountAddress,
247
+ params.receiver,
248
+ BigInt(params.paymentChannelId),
249
+ BigInt(params.amount),
250
+ params.fungibleAssetAddress,
251
+ BigInt(params.sequenceNumber),
252
+ params.sender.publicKey.toUint8Array(),
253
+ signature.toUint8Array(),
254
+ this.deployer
259
255
  );
260
256
  }
261
257
  /**
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.
258
+ * Creates a static payload for the receiver_withdraw Move function.
259
+ * This is a helper method for constructing the transaction payload.
265
260
  *
266
261
  * @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.
262
+ * @param params.sender - The sender's account address.
269
263
  * @param params.fungibleAssetAddress - The account address of the fungible asset.
264
+ * @param params.amount - The cumulative amount authorized to withdraw.
265
+ * @param params.paymentChannelId - The payment channel id.
266
+ * @param params.sequenceNumber - The sequence number for this withdrawal.
267
+ * @param params.signature - The Ed25519 signature bytes.
270
268
  *
271
- * @returns An Aptos transaction payload data object for the sender_withdraw Move function.
269
+ * @returns An Aptos transaction payload data object for the receiver_withdraw Move function.
272
270
  */
273
271
  static createMicropaymentTransactionPayload(params) {
274
272
  return {
275
273
  function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::receiver_withdraw`,
276
274
  functionArguments: [
275
+ params.sender,
276
+ params.fungibleAssetAddress,
277
277
  params.amount,
278
278
  params.paymentChannelId,
279
279
  params.sequenceNumber,
280
- params.fungibleAssetAddress
280
+ MoveVector.U8(params.signature)
281
281
  ]
282
282
  };
283
283
  }
284
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.
285
+ * Withdraws funds from a micropayment channel as the receiver.
286
+ * The receiver submits the sender's signed approval to claim funds.
287
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.
288
+ * @param params.receiver - The receiver account that will sign and submit the transaction.
289
+ * @param params.micropayment - The sender's signed micropayment approval.
291
290
  * @param params.options - Optional transaction generation options.
292
291
  *
293
292
  * @returns An object containing the pending transaction.
@@ -295,23 +294,31 @@ var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
295
294
  * @example
296
295
  * ```typescript
297
296
  * const { transaction } = await client.receiverWithdraw({
298
- * receiver: receiver,
299
- * micropayment,
300
- * senderSignature,
297
+ * receiver: receiverAccount,
298
+ * micropayment: senderBuiltMicropayment,
301
299
  * });
302
300
  * ```
303
301
  */
304
302
  async receiverWithdraw(params) {
305
- const mySignature = this.aptos.signAsFeePayer({
306
- signer: params.receiver,
307
- transaction: params.micropayment.micropayment
303
+ const transaction = await this.aptos.transaction.build.simple({
304
+ options: params.options,
305
+ data: _ShelbyMicropaymentChannelClient.createMicropaymentTransactionPayload(
306
+ {
307
+ deployer: this.deployer,
308
+ sender: params.micropayment.sender,
309
+ fungibleAssetAddress: params.micropayment.fungibleAssetAddress,
310
+ amount: params.micropayment.amount,
311
+ paymentChannelId: params.micropayment.paymentChannelId,
312
+ sequenceNumber: params.micropayment.sequenceNumber,
313
+ signature: params.micropayment.signature
314
+ }
315
+ ),
316
+ sender: params.receiver.accountAddress
308
317
  });
309
318
  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
319
+ transaction: await this.aptos.signAndSubmitTransaction({
320
+ signer: params.receiver,
321
+ transaction
315
322
  })
316
323
  };
317
324
  }
@@ -447,7 +454,7 @@ var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
447
454
  * ```typescript
448
455
  * const channelInfoVec = await client.getChannelInfo({
449
456
  * sender: AccountAddress.fromString("0x1"),
450
- * receiver: AccountAddress.fromSTring("0x2"),
457
+ * receiver: AccountAddress.fromString("0x2"),
451
458
  * });
452
459
  * ```
453
460
  */
@@ -466,10 +473,14 @@ var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
466
473
  const channelInfoArray = rawArray[0];
467
474
  return channelInfoArray.map(
468
475
  (channelInfo) => {
476
+ const publicKeyHex = channelInfo.public_key.startsWith("0x") ? channelInfo.public_key.slice(2) : channelInfo.public_key;
477
+ const publicKey = new Uint8Array(
478
+ publicKeyHex.match(/.{1,2}/g)?.map((byte) => Number.parseInt(byte, 16)) ?? []
479
+ );
469
480
  return {
470
481
  sender: params.sender,
471
482
  receiver: params.receiver,
472
- fungibleAssetAddress: AccountAddress.fromString(
483
+ fungibleAssetAddress: normalizeAddress(
473
484
  channelInfo.asset_metadata.inner
474
485
  ),
475
486
  balance: Number(channelInfo.balance),
@@ -481,7 +492,8 @@ var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
481
492
  paymentChannelId: Number(channelInfo.payment_channel_id),
482
493
  receiverWithdrawnAmount: Number(
483
494
  channelInfo.receiver_withdrawn_amount
484
- )
495
+ ),
496
+ publicKey
485
497
  };
486
498
  }
487
499
  );
@@ -1,34 +1,36 @@
1
1
  import {
2
2
  ShelbyBlobClient
3
- } from "./chunk-SRV4YWFH.mjs";
4
- import {
5
- defaultErasureCodingConfig
6
- } from "./chunk-HPPMI7DC.mjs";
7
- import {
8
- ClayErasureCodingProvider
9
- } from "./chunk-OGKZ575S.mjs";
3
+ } from "./chunk-PESSW3FK.mjs";
10
4
  import {
11
5
  ShelbyMetadataClient
12
- } from "./chunk-MV6FNYAU.mjs";
6
+ } from "./chunk-H53O23I7.mjs";
13
7
  import {
14
8
  ShelbyRPCClient
15
- } from "./chunk-PJVWGMVI.mjs";
9
+ } from "./chunk-E5PP7BZJ.mjs";
16
10
  import {
17
11
  getAptosConfig
18
12
  } from "./chunk-AABBONAF.mjs";
13
+ import {
14
+ defaultErasureCodingConfig
15
+ } from "./chunk-HPPMI7DC.mjs";
16
+ import {
17
+ ClayErasureCodingProvider
18
+ } from "./chunk-OGKZ575S.mjs";
19
19
  import {
20
20
  createBlobKey
21
- } from "./chunk-OTBLZL2S.mjs";
21
+ } from "./chunk-3NRBHSMQ.mjs";
22
22
  import {
23
23
  generateCommitments
24
- } from "./chunk-2WEX3K7C.mjs";
24
+ } from "./chunk-BXEVML7N.mjs";
25
+ import {
26
+ normalizeAddress
27
+ } from "./chunk-UEZNZBJO.mjs";
25
28
  import {
26
29
  NetworkToShelbyRPCBaseUrl
27
- } from "./chunk-4ZOFT75Q.mjs";
30
+ } from "./chunk-7OV5ZYW6.mjs";
28
31
 
29
32
  // src/core/clients/ShelbyClient.ts
30
33
  import {
31
- AccountAddress,
32
34
  Aptos,
33
35
  DEFAULT_TXN_TIMEOUT_SEC,
34
36
  Network,
@@ -316,7 +318,7 @@ var ShelbyClient = class {
316
318
  const response = await fetch(`${faucet}`, {
317
319
  method: "POST",
318
320
  body: JSON.stringify({
319
- address: AccountAddress.from(address).toString(),
321
+ address: normalizeAddress(address).toString(),
320
322
  amount
321
323
  }),
322
324
  headers: {
@@ -1,21 +1,22 @@
1
- import {
2
- defaultErasureCodingConfig
3
- } from "./chunk-HPPMI7DC.mjs";
4
1
  import {
5
2
  getShelbyIndexerClient
6
- } from "./chunk-CGYJLKBU.mjs";
3
+ } from "./chunk-EZPZAUIV.mjs";
7
4
  import {
8
5
  getAptosConfig
9
6
  } from "./chunk-AABBONAF.mjs";
7
+ import {
8
+ defaultErasureCodingConfig
9
+ } from "./chunk-HPPMI7DC.mjs";
10
10
  import {
11
11
  createBlobKey
12
- } from "./chunk-OTBLZL2S.mjs";
12
+ } from "./chunk-3NRBHSMQ.mjs";
13
13
  import {
14
14
  expectedTotalChunksets
15
- } from "./chunk-2WEX3K7C.mjs";
15
+ } from "./chunk-BXEVML7N.mjs";
16
16
  import {
17
- getBlobNameSuffix
18
- } from "./chunk-4JZO2D7T.mjs";
17
+ getBlobNameSuffix,
18
+ normalizeAddress
19
+ } from "./chunk-UEZNZBJO.mjs";
19
20
  import {
20
21
  ERASURE_CODE_AND_CHUNK_MAPPING
21
22
  } from "./chunk-JTXYKO3U.mjs";
@@ -24,7 +25,7 @@ import {
24
25
  } from "./chunk-AUQDI5BS.mjs";
25
26
  import {
26
27
  SHELBY_DEPLOYER
27
- } from "./chunk-4ZOFT75Q.mjs";
28
+ } from "./chunk-7OV5ZYW6.mjs";
28
29
 
29
30
  // src/core/clients/ShelbyBlobClient.ts
30
31
  import {
@@ -174,14 +175,14 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
174
175
  blobMerkleRoot: Hex.fromHexInput(
175
176
  metadata.blob_commitment
176
177
  ).toUint8Array(),
177
- owner: AccountAddress.fromString(metadata.owner),
178
+ owner: normalizeAddress(metadata.owner),
178
179
  name: params.name,
179
180
  blobNameSuffix: getBlobNameSuffix(params.name),
180
181
  size: Number(metadata.blob_size),
181
182
  encoding,
182
183
  expirationMicros: Number(metadata.expiration_micros),
183
184
  creationMicros: Number(metadata.creation_micros),
184
- sliceAddress: AccountAddress.fromString(metadata.slice.inner),
185
+ sliceAddress: normalizeAddress(metadata.slice.inner),
185
186
  isWritten: metadata.is_written
186
187
  };
187
188
  } catch (error) {
@@ -214,7 +215,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
214
215
  return this.getBlobs({
215
216
  where: {
216
217
  ...where,
217
- owner: { _eq: AccountAddress.from(params.account).toString() }
218
+ owner: { _eq: normalizeAddress(params.account).toString() }
218
219
  },
219
220
  pagination: rest.pagination,
220
221
  orderBy: rest.orderBy
@@ -253,7 +254,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
253
254
  });
254
255
  return blobs.map(
255
256
  (blob) => ({
256
- owner: AccountAddress.from(blob.owner),
257
+ owner: normalizeAddress(blob.owner),
257
258
  name: blob.blob_name,
258
259
  blobNameSuffix: getBlobNameSuffix(blob.blob_name),
259
260
  blobMerkleRoot: Hex.fromHexInput(blob.blob_commitment).toUint8Array(),
@@ -266,7 +267,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
266
267
  },
267
268
  expirationMicros: Number(blob.expires_at),
268
269
  creationMicros: Number(blob.created_at),
269
- sliceAddress: AccountAddress.from(blob.slice_address),
270
+ sliceAddress: normalizeAddress(blob.slice_address),
270
271
  isWritten: Boolean(Number(blob.is_written)),
271
272
  isDeleted: Boolean(Number(blob.is_deleted))
272
273
  })
@@ -290,9 +291,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
290
291
  return blob_activities.map(
291
292
  (activity) => ({
292
293
  blobName: activity.blob_name,
293
- accountAddress: AccountAddress.from(
294
- activity.blob_name.substring(1, 65)
295
- ),
294
+ accountAddress: normalizeAddress(activity.blob_name.substring(1, 65)),
296
295
  type: activityTypeMapping[activity.event_type] ?? "unknown",
297
296
  eventType: activity.event_type,
298
297
  eventIndex: Number(activity.event_index),
@@ -725,6 +724,42 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
725
724
  ]
726
725
  };
727
726
  }
727
+ static createBlobAcknowledgementsPayload(params) {
728
+ const ackBitMask = params.storageProviderAcks.reduce(
729
+ (acc, ack) => acc | 1 << ack.slot,
730
+ 0
731
+ );
732
+ return {
733
+ function: `${SHELBY_DEPLOYER}::blob_metadata::add_blob_acknowledgements`,
734
+ functionArguments: [
735
+ createBlobKey({
736
+ account: params.blobOwner,
737
+ blobName: params.blobName
738
+ }),
739
+ params.creationMicros,
740
+ new U32(Number(ackBitMask)),
741
+ params.storageProviderAcks.map((ack) => ack.signature)
742
+ ]
743
+ };
744
+ }
745
+ async addBlobAcknowledgements(params) {
746
+ const transaction = await this.aptos.transaction.build.simple({
747
+ ...params.options?.build,
748
+ data: _ShelbyBlobClient.createBlobAcknowledgementsPayload({
749
+ blobOwner: params.blobOwner,
750
+ blobName: params.blobName,
751
+ creationMicros: params.creationMicros,
752
+ storageProviderAcks: params.storageProviderAcks
753
+ }),
754
+ sender: params.account.accountAddress
755
+ });
756
+ return {
757
+ transaction: await this.aptos.signAndSubmitTransaction({
758
+ signer: params.account,
759
+ transaction
760
+ })
761
+ };
762
+ }
728
763
  };
729
764
 
730
765
  export {
@@ -0,0 +1,207 @@
1
+ import {
2
+ MICROPAYMENTS_DEPLOYER
3
+ } from "./chunk-7OV5ZYW6.mjs";
4
+
5
+ // src/core/types/payments.ts
6
+ import {
7
+ AccountAddress,
8
+ Deserializer,
9
+ Hex,
10
+ Serializer
11
+ } from "@aptos-labs/ts-sdk";
12
+ var MICROPAYMENTS_MODULE_NAME = "micropayments";
13
+ var WITHDRAW_APPROVAL_STRUCT_NAME = "WithdrawApproval";
14
+ function serializeTypeInfo(serializer, moduleAddress, moduleName, structName) {
15
+ moduleAddress.serialize(serializer);
16
+ const moduleNameBytes = new TextEncoder().encode(moduleName);
17
+ serializer.serializeBytes(moduleNameBytes);
18
+ const structNameBytes = new TextEncoder().encode(structName);
19
+ serializer.serializeBytes(structNameBytes);
20
+ }
21
+ var StaleChannelStateError = class _StaleChannelStateError extends Error {
22
+ /**
23
+ * The last valid micropayment stored by the server.
24
+ * Clients can use this to reset their local channel state.
25
+ */
26
+ storedMicropayment;
27
+ constructor(storedMicropayment, message) {
28
+ super(
29
+ message ?? "Client has stale channel state. Use the returned micropayment to reset local state."
30
+ );
31
+ this.name = "StaleChannelStateError";
32
+ this.storedMicropayment = storedMicropayment;
33
+ }
34
+ /**
35
+ * Returns the stored micropayment as a base64-encoded string.
36
+ */
37
+ toBase64() {
38
+ const bytes = this.storedMicropayment.bcsToBytes();
39
+ const binaryString = Array.from(
40
+ bytes,
41
+ (byte) => String.fromCharCode(byte)
42
+ ).join("");
43
+ return btoa(binaryString);
44
+ }
45
+ /**
46
+ * Creates a StaleChannelStateError from a base64-encoded micropayment string.
47
+ */
48
+ static fromBase64(base64, message) {
49
+ const binaryString = atob(base64);
50
+ const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
51
+ const micropayment = SenderBuiltMicropayment.deserialize(bytes);
52
+ return new _StaleChannelStateError(micropayment, message);
53
+ }
54
+ };
55
+ var SenderBuiltMicropayment = class _SenderBuiltMicropayment {
56
+ /**
57
+ * The sender's address (owner of the payment channel).
58
+ */
59
+ sender;
60
+ /**
61
+ * The receiver's address (beneficiary of the withdrawal).
62
+ */
63
+ receiver;
64
+ /**
65
+ * The unique ID of the payment channel.
66
+ */
67
+ paymentChannelId;
68
+ /**
69
+ * The cumulative amount the receiver is authorized to withdraw.
70
+ */
71
+ amount;
72
+ /**
73
+ * The fungible asset metadata address.
74
+ */
75
+ fungibleAssetAddress;
76
+ /**
77
+ * Monotonically increasing sequence number for replay protection.
78
+ */
79
+ sequenceNumber;
80
+ /**
81
+ * The sender's Ed25519 public key (32 bytes).
82
+ * Used by the receiver to verify the signature before submitting.
83
+ */
84
+ publicKey;
85
+ /**
86
+ * The Ed25519 signature of the SignedMessage<WithdrawApproval> struct.
87
+ * The SignedMessage includes TypeInfo for domain separation.
88
+ */
89
+ signature;
90
+ /**
91
+ * The deployer address of the micropayments module.
92
+ * This is needed to reconstruct the TypeInfo for signature verification.
93
+ */
94
+ deployer;
95
+ constructor(sender, receiver, paymentChannelId, amount, fungibleAssetAddress, sequenceNumber, publicKey, signature, deployer) {
96
+ this.sender = sender;
97
+ this.receiver = receiver;
98
+ this.paymentChannelId = paymentChannelId;
99
+ this.amount = amount;
100
+ this.fungibleAssetAddress = fungibleAssetAddress;
101
+ this.sequenceNumber = sequenceNumber;
102
+ this.publicKey = publicKey;
103
+ this.signature = signature;
104
+ this.deployer = deployer ?? AccountAddress.fromString(MICROPAYMENTS_DEPLOYER);
105
+ }
106
+ /**
107
+ * Creates the BCS-serialized message that was signed.
108
+ * This is a SignedMessage<WithdrawApproval> which includes:
109
+ * 1. TypeInfo (module_address, module_name, struct_name)
110
+ * 2. WithdrawApproval struct fields
111
+ *
112
+ * This format is used with signature_verify_strict_t for domain separation.
113
+ */
114
+ getSignedMessage() {
115
+ return _SenderBuiltMicropayment.buildSignedMessage({
116
+ deployer: this.deployer,
117
+ sender: this.sender,
118
+ receiver: this.receiver,
119
+ fungibleAssetAddress: this.fungibleAssetAddress,
120
+ amount: this.amount,
121
+ paymentChannelId: this.paymentChannelId,
122
+ sequenceNumber: this.sequenceNumber
123
+ });
124
+ }
125
+ /**
126
+ * Static helper to build the SignedMessage<WithdrawApproval> bytes from raw parameters.
127
+ * This can be used to create the message for signing without constructing the full object.
128
+ *
129
+ * @param params - The withdrawal approval parameters.
130
+ * @returns The BCS-serialized SignedMessage<WithdrawApproval> bytes.
131
+ */
132
+ static buildSignedMessage(params) {
133
+ const serializer = new Serializer();
134
+ serializeTypeInfo(
135
+ serializer,
136
+ params.deployer,
137
+ MICROPAYMENTS_MODULE_NAME,
138
+ WITHDRAW_APPROVAL_STRUCT_NAME
139
+ );
140
+ params.sender.serialize(serializer);
141
+ params.receiver.serialize(serializer);
142
+ params.fungibleAssetAddress.serialize(serializer);
143
+ serializer.serializeU64(params.amount);
144
+ serializer.serializeU64(params.paymentChannelId);
145
+ serializer.serializeU64(params.sequenceNumber);
146
+ return serializer.toUint8Array();
147
+ }
148
+ serialize(serializer) {
149
+ this.sender.serialize(serializer);
150
+ this.receiver.serialize(serializer);
151
+ this.fungibleAssetAddress.serialize(serializer);
152
+ serializer.serializeU64(this.amount);
153
+ serializer.serializeU64(this.paymentChannelId);
154
+ serializer.serializeU64(this.sequenceNumber);
155
+ serializer.serializeBytes(this.publicKey);
156
+ serializer.serializeBytes(this.signature);
157
+ this.deployer.serialize(serializer);
158
+ }
159
+ bcsToBytes() {
160
+ const serializer = new Serializer();
161
+ this.serialize(serializer);
162
+ return serializer.toUint8Array();
163
+ }
164
+ bcsToHex() {
165
+ return Hex.fromHexInput(this.bcsToBytes());
166
+ }
167
+ toStringWithoutPrefix() {
168
+ return this.bcsToHex().toStringWithoutPrefix();
169
+ }
170
+ toString() {
171
+ return this.bcsToHex().toString();
172
+ }
173
+ /**
174
+ * Deserializes a SenderBuiltMicropayment from BCS bytes.
175
+ * @param bytes - The bytes to deserialize from (Uint8Array or hex string).
176
+ * @returns A new SenderBuiltMicropayment instance.
177
+ */
178
+ static deserialize(bytes) {
179
+ const bytesArray = typeof bytes === "string" ? Hex.fromHexInput(bytes).toUint8Array() : bytes;
180
+ const deserializer = new Deserializer(bytesArray);
181
+ const sender = AccountAddress.deserialize(deserializer);
182
+ const receiver = AccountAddress.deserialize(deserializer);
183
+ const fungibleAssetAddress = AccountAddress.deserialize(deserializer);
184
+ const amount = deserializer.deserializeU64();
185
+ const paymentChannelId = deserializer.deserializeU64();
186
+ const sequenceNumber = deserializer.deserializeU64();
187
+ const publicKey = deserializer.deserializeBytes();
188
+ const signature = deserializer.deserializeBytes();
189
+ const deployer = AccountAddress.deserialize(deserializer);
190
+ return new _SenderBuiltMicropayment(
191
+ sender,
192
+ receiver,
193
+ paymentChannelId,
194
+ amount,
195
+ fungibleAssetAddress,
196
+ sequenceNumber,
197
+ publicKey,
198
+ signature,
199
+ deployer
200
+ );
201
+ }
202
+ };
203
+
204
+ export {
205
+ StaleChannelStateError,
206
+ SenderBuiltMicropayment
207
+ };