@shelby-protocol/sdk 0.2.4 → 0.3.1
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/dist/browser/index.d.ts +13 -4
- package/dist/browser/index.mjs +3719 -140
- package/dist/{clay-codes-DHP-bYcP.d.ts → clay-codes-DdXABBDx.d.ts} +0 -7
- package/dist/core/aptos-explorer.mjs +46 -5
- package/dist/core/blobs.d.ts +1 -1
- package/dist/core/blobs.mjs +12 -4
- package/dist/core/chunk.mjs +58 -9
- package/dist/core/clients/ShelbyBlobClient.d.ts +9 -44
- package/dist/core/clients/ShelbyBlobClient.mjs +1084 -17
- package/dist/core/clients/ShelbyClient.d.ts +12 -2
- package/dist/core/clients/ShelbyClient.mjs +2915 -23
- package/dist/core/clients/ShelbyClientConfig.d.ts +8 -0
- package/dist/core/clients/ShelbyClientConfig.mjs +0 -1
- package/dist/core/clients/ShelbyMetadataClient.d.ts +0 -18
- package/dist/core/clients/ShelbyMetadataClient.mjs +306 -6
- package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +7 -49
- package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +839 -13
- package/dist/core/clients/ShelbyPlacementGroupClient.mjs +307 -8
- package/dist/core/clients/ShelbyRPCClient.d.ts +107 -4
- package/dist/core/clients/ShelbyRPCClient.mjs +1261 -12
- package/dist/core/clients/index.d.ts +3 -2
- package/dist/core/clients/index.mjs +3421 -40
- package/dist/core/clients/utils.mjs +65 -6
- package/dist/core/commitments.d.ts +3 -12
- package/dist/core/commitments.mjs +270 -11
- package/dist/core/constants.d.ts +4 -4
- package/dist/core/constants.mjs +39 -16
- package/dist/core/erasure/clay-codes.d.ts +1 -1
- package/dist/core/erasure/clay-codes.mjs +129 -4
- package/dist/core/erasure/constants.mjs +33 -10
- package/dist/core/erasure/default.d.ts +1 -1
- package/dist/core/erasure/default.mjs +191 -9
- package/dist/core/erasure/index.d.ts +1 -1
- package/dist/core/erasure/index.mjs +266 -23
- package/dist/core/erasure/provider.d.ts +1 -1
- package/dist/core/erasure/reed-solomon.d.ts +1 -1
- package/dist/core/erasure/reed-solomon.mjs +68 -4
- package/dist/core/erasure/utils.d.ts +1 -1
- package/dist/core/erasure/utils.mjs +0 -2
- package/dist/core/errors.mjs +29 -8
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.mjs +3713 -140
- package/dist/core/layout.d.ts +1 -1
- package/dist/core/layout.mjs +37 -5
- package/dist/core/networks.mjs +10 -5
- package/dist/core/operations/generated/sdk.d.ts +9 -0
- package/dist/core/operations/generated/sdk.mjs +183 -18
- package/dist/core/operations/index.mjs +284 -24
- package/dist/core/promises.mjs +4 -4
- package/dist/core/rpc-responses.d.ts +38 -1
- package/dist/core/rpc-responses.mjs +31 -8
- package/dist/core/shelby-explorer.mjs +31 -6
- package/dist/core/strings.mjs +0 -2
- package/dist/core/types/blobs.d.ts +1 -1
- package/dist/core/types/blobs.mjs +0 -1
- package/dist/core/types/index.d.ts +1 -1
- package/dist/core/types/index.mjs +230 -9
- package/dist/core/types/payments.d.ts +6 -6
- package/dist/core/types/payments.mjs +230 -5
- package/dist/core/types/placement_groups.mjs +0 -1
- package/dist/core/types/storage_providers.mjs +0 -1
- package/dist/core/utils.mjs +94 -8
- package/dist/node/clients/ShelbyNodeClient.d.ts +2 -1
- package/dist/node/clients/ShelbyNodeClient.mjs +2919 -24
- package/dist/node/clients/index.d.ts +2 -1
- package/dist/node/clients/index.mjs +2920 -26
- package/dist/node/index.d.ts +4 -4
- package/dist/node/index.mjs +3736 -147
- package/dist/node/parallel/commitment_worker.d.ts +9 -0
- package/dist/node/parallel/commitment_worker.mjs +298 -0
- package/dist/node/parallel/commitment_worker_pool.d.ts +35 -0
- package/dist/node/parallel/commitment_worker_pool.mjs +286 -0
- package/dist/node/parallel/default_commitment_worker_pool.d.ts +24 -0
- package/dist/node/parallel/default_commitment_worker_pool.mjs +302 -0
- package/dist/node/parallel/index.d.ts +11 -0
- package/dist/node/parallel/index.mjs +563 -0
- package/dist/node/parallel/parallel_commitments.d.ts +32 -0
- package/dist/node/parallel/parallel_commitments.mjs +561 -0
- package/dist/node/parallel/worker_pool.d.ts +74 -0
- package/dist/node/parallel/worker_pool.mjs +248 -0
- package/dist/node/testUtil.mjs +8 -4
- package/package.json +9 -6
- package/dist/chunk-3NRBHSMQ.mjs +0 -12
- package/dist/chunk-3PCG7PNP.mjs +0 -375
- package/dist/chunk-7OV5ZYW6.mjs +0 -55
- package/dist/chunk-7P6ASYW6.mjs +0 -9
- package/dist/chunk-A4IG6GSE.mjs +0 -21
- package/dist/chunk-AD2G3QYD.mjs +0 -0
- package/dist/chunk-AEDVYYGD.mjs +0 -11
- package/dist/chunk-AUQDI5BS.mjs +0 -43
- package/dist/chunk-BDSW5PHM.mjs +0 -37
- package/dist/chunk-BKL7NCUB.mjs +0 -412
- package/dist/chunk-BUWAD67L.mjs +0 -505
- package/dist/chunk-BXEVML7N.mjs +0 -169
- package/dist/chunk-C6RQ3AEU.mjs +0 -51
- package/dist/chunk-CQ6QPIZK.mjs +0 -37
- package/dist/chunk-D6GQHO6G.mjs +0 -15
- package/dist/chunk-EM67QTMR.mjs +0 -0
- package/dist/chunk-I6NG5GNL.mjs +0 -8
- package/dist/chunk-IE6LYVIA.mjs +0 -26
- package/dist/chunk-IKRWBDG5.mjs +0 -42
- package/dist/chunk-JTXYKO3U.mjs +0 -38
- package/dist/chunk-KYQRWJ3U.mjs +0 -49
- package/dist/chunk-MB7C7VQF.mjs +0 -0
- package/dist/chunk-MQUVYMNQ.mjs +0 -0
- package/dist/chunk-NHWWORCH.mjs +0 -72
- package/dist/chunk-NI6XBZLI.mjs +0 -83
- package/dist/chunk-OGKZ575S.mjs +0 -136
- package/dist/chunk-QQ57OGQ2.mjs +0 -0
- package/dist/chunk-SSE4MFNN.mjs +0 -278
- package/dist/chunk-TET3DJEO.mjs +0 -199
- package/dist/chunk-TVLV7C74.mjs +0 -207
- package/dist/chunk-UEZNZBJO.mjs +0 -104
- package/dist/chunk-WJTVYLKW.mjs +0 -782
- package/dist/chunk-WTICJPDB.mjs +0 -0
- package/dist/chunk-XNEIWM4O.mjs +0 -0
- package/dist/chunk-XRLHLAOW.mjs +0 -51
- package/dist/chunk-Z4FZ7W6L.mjs +0 -39
- package/dist/chunk-Z7RFCADT.mjs +0 -0
- package/dist/chunk-ZHXCVRZX.mjs +0 -0
- package/dist/core/operations/generated/types.d.ts +0 -908
- package/dist/core/operations/generated/types.mjs +0 -63
- package/dist/core/types/encodings.d.ts +0 -11
- package/dist/core/types/encodings.mjs +0 -0
package/dist/chunk-BUWAD67L.mjs
DELETED
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SenderBuiltMicropayment
|
|
3
|
-
} from "./chunk-TVLV7C74.mjs";
|
|
4
|
-
import {
|
|
5
|
-
getShelbyIndexerClient
|
|
6
|
-
} from "./chunk-KYQRWJ3U.mjs";
|
|
7
|
-
import {
|
|
8
|
-
getAptosConfig
|
|
9
|
-
} from "./chunk-IKRWBDG5.mjs";
|
|
10
|
-
import {
|
|
11
|
-
normalizeAddress
|
|
12
|
-
} from "./chunk-UEZNZBJO.mjs";
|
|
13
|
-
import {
|
|
14
|
-
MICROPAYMENTS_DEPLOYER
|
|
15
|
-
} from "./chunk-7OV5ZYW6.mjs";
|
|
16
|
-
|
|
17
|
-
// src/core/clients/ShelbyMicropaymentChannelClient.ts
|
|
18
|
-
import {
|
|
19
|
-
AccountAddress,
|
|
20
|
-
Aptos,
|
|
21
|
-
MoveVector
|
|
22
|
-
} from "@aptos-labs/ts-sdk";
|
|
23
|
-
var ShelbyMicropaymentChannelClient = class _ShelbyMicropaymentChannelClient {
|
|
24
|
-
aptos;
|
|
25
|
-
deployer;
|
|
26
|
-
indexer;
|
|
27
|
-
/**
|
|
28
|
-
* The ShelbyMicropaymentChannelClient is used to interact with the Micropayment contract on the Aptos blockchain. This
|
|
29
|
-
* includes functions for the full lifecycle of micropayment channels: creation, withdrawals, expiration extensions, etc.
|
|
30
|
-
*
|
|
31
|
-
* @param config - The client configuration object.
|
|
32
|
-
* @param config.network - The Shelby network to use.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* const client = new ShelbyMicropaymentChannelClient({
|
|
37
|
-
* aptos: {
|
|
38
|
-
* network: Network.SHELBYNET,
|
|
39
|
-
* clientConfig: {
|
|
40
|
-
* API_KEY: "AG-***",
|
|
41
|
-
* },
|
|
42
|
-
* },
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
constructor(config) {
|
|
47
|
-
this.aptos = new Aptos(getAptosConfig(config));
|
|
48
|
-
this.deployer = config.deployer ?? AccountAddress.fromString(MICROPAYMENTS_DEPLOYER);
|
|
49
|
-
this.indexer = getShelbyIndexerClient(config);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Calls initialize function so caller can thereafter create micropayment channels.
|
|
53
|
-
*
|
|
54
|
-
* @param params.sender - The account that will be sending funds to various receivers in micropayment channels.
|
|
55
|
-
* @param params.options - Optional transaction building options.
|
|
56
|
-
*
|
|
57
|
-
* @returns An object containing the pending transaction.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
*
|
|
62
|
-
* const { transaction } = await client.initializePaymentChannels({
|
|
63
|
-
* sender: sender,
|
|
64
|
-
* });
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
async initializePaymentChannels(params) {
|
|
68
|
-
const transaction = await this.aptos.transaction.build.simple({
|
|
69
|
-
options: params.options,
|
|
70
|
-
data: {
|
|
71
|
-
function: `${(this.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::initialize_payment_channels`,
|
|
72
|
-
functionArguments: []
|
|
73
|
-
},
|
|
74
|
-
sender: params.sender.accountAddress
|
|
75
|
-
});
|
|
76
|
-
return {
|
|
77
|
-
transaction: await this.aptos.signAndSubmitTransaction({
|
|
78
|
-
signer: params.sender,
|
|
79
|
-
transaction
|
|
80
|
-
})
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Creates a micropayment channel to start a channel bweteen a sender and a receiver for a specific asset.
|
|
85
|
-
*
|
|
86
|
-
* @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
|
|
87
|
-
* @param params.sender - The account that will be sending funds.
|
|
88
|
-
* @param params.receiver - The account that will be receiving funds.
|
|
89
|
-
* @param params.expirationMicros - The expiration of the micropayment channel.
|
|
90
|
-
* @param params.depositAmount - The amount of the asset locked to the channel.
|
|
91
|
-
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
92
|
-
* @param params.options - Optional transaction building options.
|
|
93
|
-
*
|
|
94
|
-
* @returns An object containing the pending transaction.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```typescript
|
|
98
|
-
*
|
|
99
|
-
* const { transaction } = await client.createChannel({
|
|
100
|
-
* sender: sender,
|
|
101
|
-
* receiver: receiver,
|
|
102
|
-
* expirationMicros: Date.now() * 1000 + 86400_000_000, // 1 day from now in microseconds
|
|
103
|
-
* depositAmount: 0.001,
|
|
104
|
-
* fungibleAssetAddress: fungibleAssetAddress,
|
|
105
|
-
* });
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
async createChannel(params) {
|
|
109
|
-
const transaction = await this.aptos.transaction.build.simple({
|
|
110
|
-
options: params.options,
|
|
111
|
-
data: _ShelbyMicropaymentChannelClient.makeCreateMicropaymentChannelPayload(
|
|
112
|
-
{
|
|
113
|
-
deployer: this.deployer,
|
|
114
|
-
receiver: params.receiver,
|
|
115
|
-
expirationMicros: params.expirationMicros,
|
|
116
|
-
depositAmount: params.depositAmount,
|
|
117
|
-
fungibleAssetAddress: params.fungibleAssetAddress,
|
|
118
|
-
publicKey: params.publicKey ?? params.sender.publicKey.toUint8Array()
|
|
119
|
-
}
|
|
120
|
-
),
|
|
121
|
-
sender: params.sender.accountAddress
|
|
122
|
-
});
|
|
123
|
-
return {
|
|
124
|
-
transaction: await this.aptos.signAndSubmitTransaction({
|
|
125
|
-
signer: params.sender,
|
|
126
|
-
transaction
|
|
127
|
-
})
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Creates a micropayment channel creation payload to start a channel between a sender and a receiver for a specific asset.
|
|
132
|
-
* This is a static helper method for constructing the Move function call payload.
|
|
133
|
-
*
|
|
134
|
-
* @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
|
|
135
|
-
* @param params.sender - The account that will be sending funds.
|
|
136
|
-
* @param params.receiver - The account that will be receiving funds.
|
|
137
|
-
* @param params.expirationMicros - The expiration of the micropayment channel.
|
|
138
|
-
* @param params.depositAmount - The amount of the asset locked to the channel.
|
|
139
|
-
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
140
|
-
* @param params.publicKey - The Ed25519 public key bytes for the channel.
|
|
141
|
-
*
|
|
142
|
-
* @returns An Aptos transaction payload data object for the create_channel Move function.
|
|
143
|
-
*/
|
|
144
|
-
static makeCreateMicropaymentChannelPayload(params) {
|
|
145
|
-
return {
|
|
146
|
-
function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::create_channel`,
|
|
147
|
-
functionArguments: [
|
|
148
|
-
params.receiver,
|
|
149
|
-
params.expirationMicros,
|
|
150
|
-
params.depositAmount,
|
|
151
|
-
params.fungibleAssetAddress,
|
|
152
|
-
MoveVector.U8(params.publicKey)
|
|
153
|
-
]
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Withdraws funds from a micropayment channel as the sender.
|
|
158
|
-
*
|
|
159
|
-
* @param params.sender - The account that is withdrawing funds.
|
|
160
|
-
* @param params.receiver - The account the channel is configured to send funds to.
|
|
161
|
-
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
162
|
-
* @param params.options - Optional transaction generation options.
|
|
163
|
-
*
|
|
164
|
-
* @returns An object containing the pending transaction.
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```typescript
|
|
168
|
-
* const { transaction } = await client.senderWithdraw({
|
|
169
|
-
* sender: sender,
|
|
170
|
-
* receiver: receiver,
|
|
171
|
-
* fungibleAssetAddress: fungibleAssetAddress,
|
|
172
|
-
* });
|
|
173
|
-
* ```
|
|
174
|
-
*/
|
|
175
|
-
async senderWithdraw(params) {
|
|
176
|
-
const transaction = await this.aptos.transaction.build.simple({
|
|
177
|
-
options: params.options,
|
|
178
|
-
data: _ShelbyMicropaymentChannelClient.createSenderWithdrawPayload({
|
|
179
|
-
deployer: this.deployer,
|
|
180
|
-
receiver: params.receiver,
|
|
181
|
-
fungibleAssetAddress: params.fungibleAssetAddress
|
|
182
|
-
}),
|
|
183
|
-
sender: params.sender.accountAddress
|
|
184
|
-
});
|
|
185
|
-
return {
|
|
186
|
-
transaction: await this.aptos.signAndSubmitTransaction({
|
|
187
|
-
signer: params.sender,
|
|
188
|
-
transaction
|
|
189
|
-
})
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Creates a static payload for the sender_withdraw Move function.
|
|
194
|
-
* This is a helper method for constructing the transaction payload without signing.
|
|
195
|
-
*
|
|
196
|
-
* @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
|
|
197
|
-
* @param params.receiver - The account address of the receiver.
|
|
198
|
-
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
199
|
-
*
|
|
200
|
-
* @returns An Aptos transaction payload data object for the sender_withdraw Move function.
|
|
201
|
-
*/
|
|
202
|
-
static createSenderWithdrawPayload(params) {
|
|
203
|
-
return {
|
|
204
|
-
function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::sender_withdraw`,
|
|
205
|
-
functionArguments: [params.receiver, params.fungibleAssetAddress]
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
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.
|
|
212
|
-
*
|
|
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.
|
|
215
|
-
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
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.
|
|
219
|
-
*
|
|
220
|
-
* @returns A SenderBuiltMicropayment containing the signed approval.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```typescript
|
|
224
|
-
* const senderBuiltMicropayment = client.createMicropayment({
|
|
225
|
-
* sender: senderAccount,
|
|
226
|
-
* receiver: receiverAddress,
|
|
227
|
-
* fungibleAssetAddress: fungibleAssetAddress,
|
|
228
|
-
* amount: 100,
|
|
229
|
-
* paymentChannelId: channelId,
|
|
230
|
-
* sequenceNumber: 1,
|
|
231
|
-
* });
|
|
232
|
-
* ```
|
|
233
|
-
*/
|
|
234
|
-
createMicropayment(params) {
|
|
235
|
-
const message = SenderBuiltMicropayment.buildSignedMessage({
|
|
236
|
-
deployer: this.deployer,
|
|
237
|
-
sender: params.sender.accountAddress,
|
|
238
|
-
receiver: params.receiver,
|
|
239
|
-
fungibleAssetAddress: params.fungibleAssetAddress,
|
|
240
|
-
amount: params.amount,
|
|
241
|
-
paymentChannelId: params.paymentChannelId,
|
|
242
|
-
sequenceNumber: params.sequenceNumber
|
|
243
|
-
});
|
|
244
|
-
const signature = params.sender.sign(message);
|
|
245
|
-
return new SenderBuiltMicropayment(
|
|
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
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Creates a static payload for the receiver_withdraw Move function.
|
|
259
|
-
* This is a helper method for constructing the transaction payload.
|
|
260
|
-
*
|
|
261
|
-
* @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
|
|
262
|
-
* @param params.sender - The sender's account address.
|
|
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.
|
|
268
|
-
*
|
|
269
|
-
* @returns An Aptos transaction payload data object for the receiver_withdraw Move function.
|
|
270
|
-
*/
|
|
271
|
-
static createMicropaymentTransactionPayload(params) {
|
|
272
|
-
return {
|
|
273
|
-
function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::receiver_withdraw`,
|
|
274
|
-
functionArguments: [
|
|
275
|
-
params.sender,
|
|
276
|
-
params.fungibleAssetAddress,
|
|
277
|
-
params.amount,
|
|
278
|
-
params.paymentChannelId,
|
|
279
|
-
params.sequenceNumber,
|
|
280
|
-
MoveVector.U8(params.signature)
|
|
281
|
-
]
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Withdraws funds from a micropayment channel as the receiver.
|
|
286
|
-
* The receiver submits the sender's signed approval to claim funds.
|
|
287
|
-
*
|
|
288
|
-
* @param params.receiver - The receiver account that will sign and submit the transaction.
|
|
289
|
-
* @param params.micropayment - The sender's signed micropayment approval.
|
|
290
|
-
* @param params.options - Optional transaction generation options.
|
|
291
|
-
*
|
|
292
|
-
* @returns An object containing the pending transaction.
|
|
293
|
-
*
|
|
294
|
-
* @example
|
|
295
|
-
* ```typescript
|
|
296
|
-
* const { transaction } = await client.receiverWithdraw({
|
|
297
|
-
* receiver: receiverAccount,
|
|
298
|
-
* micropayment: senderBuiltMicropayment,
|
|
299
|
-
* });
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
async receiverWithdraw(params) {
|
|
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
|
|
317
|
-
});
|
|
318
|
-
return {
|
|
319
|
-
transaction: await this.aptos.signAndSubmitTransaction({
|
|
320
|
-
signer: params.receiver,
|
|
321
|
-
transaction
|
|
322
|
-
})
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Extends the expiration time of a micropayment channel.
|
|
327
|
-
*
|
|
328
|
-
* @param params.sender - The owner of the account.
|
|
329
|
-
* @param params.receiver - The account address of the receiver.
|
|
330
|
-
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
331
|
-
* @param params.newExpirationMicros - The new expiration time in microseconds.
|
|
332
|
-
* @param params.options - Optional transaction generation options.
|
|
333
|
-
*
|
|
334
|
-
* @returns An object containing the pending transaction.
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* ```typescript
|
|
338
|
-
* const { transaction } = await client.extendExpirationTime({
|
|
339
|
-
* sender: sender,
|
|
340
|
-
* receiver: receiverAddress,
|
|
341
|
-
* fungibleAssetAddress: fungibleAssetAddress,
|
|
342
|
-
* newExpirationMicros: Date.now() * 1000 + 172800_000_000, // 2 days from now
|
|
343
|
-
* });
|
|
344
|
-
* ```
|
|
345
|
-
*/
|
|
346
|
-
async extendExpirationTime(params) {
|
|
347
|
-
const transaction = await this.aptos.transaction.build.simple({
|
|
348
|
-
options: params.options,
|
|
349
|
-
data: _ShelbyMicropaymentChannelClient.makeExtendExpirationTimePayload({
|
|
350
|
-
deployer: this.deployer,
|
|
351
|
-
receiver: params.receiver,
|
|
352
|
-
fungibleAssetAddress: params.fungibleAssetAddress,
|
|
353
|
-
newExpirationMicros: params.newExpirationMicros
|
|
354
|
-
}),
|
|
355
|
-
sender: params.sender.accountAddress
|
|
356
|
-
});
|
|
357
|
-
return {
|
|
358
|
-
transaction: await this.aptos.signAndSubmitTransaction({
|
|
359
|
-
signer: params.sender,
|
|
360
|
-
transaction
|
|
361
|
-
})
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Creates a payload to extend the expiration time on a micropayment channel.
|
|
366
|
-
* This is a static helper method for constructing the Move function call payload.
|
|
367
|
-
*
|
|
368
|
-
* @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
|
|
369
|
-
* @param params.receiver - The account that will be receiving funds.
|
|
370
|
-
* @param params.expirationMicros - The new expiration of the micropayment channel.
|
|
371
|
-
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
372
|
-
*
|
|
373
|
-
* @returns An Aptos transaction payload data object for the extend_expiration_time Move function.
|
|
374
|
-
*/
|
|
375
|
-
static makeExtendExpirationTimePayload(params) {
|
|
376
|
-
return {
|
|
377
|
-
function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::extend_expiration_time`,
|
|
378
|
-
functionArguments: [
|
|
379
|
-
params.receiver,
|
|
380
|
-
params.fungibleAssetAddress,
|
|
381
|
-
params.newExpirationMicros
|
|
382
|
-
]
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Increases the deposit amount locked in a micropayment channel.
|
|
387
|
-
*
|
|
388
|
-
* @param params.sender - The account that is increasing the deposit.
|
|
389
|
-
* @param params.receiver - The account address of the receiver.
|
|
390
|
-
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
391
|
-
* @param params.additionalAmount - The additional amount to deposit.
|
|
392
|
-
* @param params.options - Optional transaction generation options.
|
|
393
|
-
*
|
|
394
|
-
* @returns An object containing the pending transaction.
|
|
395
|
-
*
|
|
396
|
-
* @example
|
|
397
|
-
* ```typescript
|
|
398
|
-
* const { transaction } = await client.increaseDepositAmount({
|
|
399
|
-
* sender: sender,
|
|
400
|
-
* receiver: receiverAddress,
|
|
401
|
-
* fungibleAssetAddress: fungibleAssetAddress,
|
|
402
|
-
* additionalAmount: 500,
|
|
403
|
-
* });
|
|
404
|
-
* ```
|
|
405
|
-
*/
|
|
406
|
-
async increaseDepositAmount(params) {
|
|
407
|
-
const transaction = await this.aptos.transaction.build.simple({
|
|
408
|
-
options: params.options,
|
|
409
|
-
data: _ShelbyMicropaymentChannelClient.makeIncreaseDepositAmountPayload({
|
|
410
|
-
deployer: this.deployer,
|
|
411
|
-
receiver: params.receiver,
|
|
412
|
-
fungibleAssetAddress: params.fungibleAssetAddress,
|
|
413
|
-
additionalAmount: params.additionalAmount
|
|
414
|
-
}),
|
|
415
|
-
sender: params.sender.accountAddress
|
|
416
|
-
});
|
|
417
|
-
return {
|
|
418
|
-
transaction: await this.aptos.signAndSubmitTransaction({
|
|
419
|
-
signer: params.sender,
|
|
420
|
-
transaction
|
|
421
|
-
})
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Creates a payload to increase the deposit amount on a micropayment channel.
|
|
426
|
-
* This is a static helper method for constructing the Move function call payload.
|
|
427
|
-
*
|
|
428
|
-
* @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER.
|
|
429
|
-
* @param params.receiver - The account that will be receiving funds.
|
|
430
|
-
* @param params.fungibleAssetAddress - The account address of the fungible asset.
|
|
431
|
-
* @param params.additionalAmount - The amount of the fungible asset to add to the channel's balance.
|
|
432
|
-
*
|
|
433
|
-
* @returns An Aptos transaction payload data object for the extend_expiration_time Move function.
|
|
434
|
-
*/
|
|
435
|
-
static makeIncreaseDepositAmountPayload(params) {
|
|
436
|
-
return {
|
|
437
|
-
function: `${(params.deployer ?? MICROPAYMENTS_DEPLOYER).toString()}::micropayments::increase_deposit_amount`,
|
|
438
|
-
functionArguments: [
|
|
439
|
-
params.receiver,
|
|
440
|
-
params.fungibleAssetAddress,
|
|
441
|
-
params.additionalAmount
|
|
442
|
-
]
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Retrieves the vector of channels owned by the sender, optionally
|
|
447
|
-
* filtered by the receiver.
|
|
448
|
-
*
|
|
449
|
-
* @param params.sender - The account namespace owning the micropayment channels.
|
|
450
|
-
* @param params.receiver? - An optional receiver account address.
|
|
451
|
-
* @returns A vector of ChannelInfo objects.
|
|
452
|
-
*
|
|
453
|
-
* @example
|
|
454
|
-
* ```typescript
|
|
455
|
-
* const channelInfoVec = await client.getChannelInfo({
|
|
456
|
-
* sender: AccountAddress.fromString("0x1"),
|
|
457
|
-
* receiver: AccountAddress.fromString("0x2"),
|
|
458
|
-
* });
|
|
459
|
-
* ```
|
|
460
|
-
*/
|
|
461
|
-
async getChannelInfo(params) {
|
|
462
|
-
const functionName = params.receiver ? "get_all_channels_from_sender_to_receiver" : "get_all_channels_from_sender";
|
|
463
|
-
const functionArguments = [params.sender];
|
|
464
|
-
if (params.receiver) {
|
|
465
|
-
functionArguments.push(params.receiver);
|
|
466
|
-
}
|
|
467
|
-
const rawArray = await this.aptos.view({
|
|
468
|
-
payload: {
|
|
469
|
-
function: `${this.deployer.toString()}::micropayments::${functionName}`,
|
|
470
|
-
functionArguments
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
const channelInfoArray = rawArray[0];
|
|
474
|
-
return channelInfoArray.map(
|
|
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
|
-
);
|
|
480
|
-
return {
|
|
481
|
-
sender: params.sender,
|
|
482
|
-
receiver: params.receiver,
|
|
483
|
-
fungibleAssetAddress: normalizeAddress(
|
|
484
|
-
channelInfo.asset_metadata.inner
|
|
485
|
-
),
|
|
486
|
-
balance: Number(channelInfo.balance),
|
|
487
|
-
creationMicros: Number(channelInfo.creation_micros),
|
|
488
|
-
expirationMicros: Number(channelInfo.expiration_micros),
|
|
489
|
-
nextWithdrawnSequenceNumber: Number(
|
|
490
|
-
channelInfo.next_withdrawn_sequence_number
|
|
491
|
-
),
|
|
492
|
-
paymentChannelId: Number(channelInfo.payment_channel_id),
|
|
493
|
-
receiverWithdrawnAmount: Number(
|
|
494
|
-
channelInfo.receiver_withdrawn_amount
|
|
495
|
-
),
|
|
496
|
-
publicKey
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
);
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
export {
|
|
504
|
-
ShelbyMicropaymentChannelClient
|
|
505
|
-
};
|
package/dist/chunk-BXEVML7N.mjs
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
concatHashes,
|
|
3
|
-
readInChunks,
|
|
4
|
-
zeroPadBytes
|
|
5
|
-
} from "./chunk-UEZNZBJO.mjs";
|
|
6
|
-
import {
|
|
7
|
-
DEFAULT_CHUNKSET_SIZE_BYTES
|
|
8
|
-
} from "./chunk-JTXYKO3U.mjs";
|
|
9
|
-
import {
|
|
10
|
-
DEFAULT_ERASURE_K,
|
|
11
|
-
DEFAULT_ERASURE_M
|
|
12
|
-
} from "./chunk-AUQDI5BS.mjs";
|
|
13
|
-
|
|
14
|
-
// src/core/commitments.ts
|
|
15
|
-
import { Hex } from "@aptos-labs/ts-sdk";
|
|
16
|
-
import { z } from "zod";
|
|
17
|
-
var COMMITMENT_SCHEMA_VERSION = "1.3";
|
|
18
|
-
var ChunksetCommitmentSchema = z.object({
|
|
19
|
-
// Chunkset root (vector commitment of child chunks)
|
|
20
|
-
chunkset_root: z.string(),
|
|
21
|
-
// the size is known statically from the current configuration
|
|
22
|
-
chunk_commitments: z.array(z.string())
|
|
23
|
-
}).refine(
|
|
24
|
-
(data) => {
|
|
25
|
-
return data.chunk_commitments.length === DEFAULT_ERASURE_K + DEFAULT_ERASURE_M;
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
message: `Chunkset must have exactly ${DEFAULT_ERASURE_K + DEFAULT_ERASURE_M} chunks (ERASURE_K + ERASURE_M = ${DEFAULT_ERASURE_K} + ${DEFAULT_ERASURE_M})`,
|
|
29
|
-
path: ["chunk_commitments"]
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
function expectedTotalChunksets(rawSize, chunksetSize = DEFAULT_CHUNKSET_SIZE_BYTES) {
|
|
33
|
-
if (chunksetSize <= 0) {
|
|
34
|
-
throw new Error("chunksetSize must be positive");
|
|
35
|
-
}
|
|
36
|
-
if (rawSize === 0) return 1;
|
|
37
|
-
return Math.ceil(rawSize / chunksetSize);
|
|
38
|
-
}
|
|
39
|
-
var BlobCommitmentsSchema = z.object({
|
|
40
|
-
schema_version: z.string(),
|
|
41
|
-
raw_data_size: z.number(),
|
|
42
|
-
// FIXME I am not sure about this being here, or if it should be somewhere else
|
|
43
|
-
blob_merkle_root: z.string(),
|
|
44
|
-
chunkset_commitments: z.array(ChunksetCommitmentSchema)
|
|
45
|
-
}).refine(
|
|
46
|
-
(data) => {
|
|
47
|
-
return expectedTotalChunksets(data.raw_data_size) === data.chunkset_commitments.length;
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
message: "Total chunkset count mismatches with raw data size",
|
|
51
|
-
// FIXME put more details in here
|
|
52
|
-
path: ["chunkset_commitments"]
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
async function generateMerkleRoot(leafHashes) {
|
|
56
|
-
if (!leafHashes.length) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
"An empty array cannot be used to construct a Merkle tree."
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
const zeroArray = new Uint8Array(leafHashes[0].toUint8Array().length);
|
|
62
|
-
const zeroBytes = Hex.fromHexInput(zeroArray);
|
|
63
|
-
let currentLeaves = leafHashes;
|
|
64
|
-
while (currentLeaves.length > 1) {
|
|
65
|
-
if (currentLeaves.length % 2 !== 0) {
|
|
66
|
-
currentLeaves.push(zeroBytes);
|
|
67
|
-
}
|
|
68
|
-
const nextLeaves = [];
|
|
69
|
-
for (let i = 0; i < currentLeaves.length; i += 2) {
|
|
70
|
-
nextLeaves.push(
|
|
71
|
-
await concatHashes([
|
|
72
|
-
currentLeaves[i].toUint8Array(),
|
|
73
|
-
currentLeaves[i + 1].toUint8Array()
|
|
74
|
-
])
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
currentLeaves = nextLeaves;
|
|
78
|
-
}
|
|
79
|
-
return currentLeaves[0];
|
|
80
|
-
}
|
|
81
|
-
async function generateChunksetCommitments(shouldPad, chunksetIdx, chunksetData, expectedChunksetSize, provider, onChunk) {
|
|
82
|
-
const { erasure_n } = provider.config;
|
|
83
|
-
const chunksetPayload = shouldPad ? zeroPadBytes(chunksetData, expectedChunksetSize) : validatePrePaddedChunkset(
|
|
84
|
-
chunksetData,
|
|
85
|
-
expectedChunksetSize,
|
|
86
|
-
chunksetIdx
|
|
87
|
-
);
|
|
88
|
-
const { chunks } = provider.encode(chunksetPayload);
|
|
89
|
-
if (chunks.length !== erasure_n) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
`Erasure provider produced ${chunks.length} chunks, expected ${erasure_n}.`
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
const chunkRoots = provider.getChunkMerkleRoots();
|
|
95
|
-
let chunkIdx = 0;
|
|
96
|
-
for (const chunkData of chunks) {
|
|
97
|
-
if (onChunk !== void 0) {
|
|
98
|
-
await onChunk(chunksetIdx, chunkIdx, chunkData);
|
|
99
|
-
}
|
|
100
|
-
chunkIdx += 1;
|
|
101
|
-
}
|
|
102
|
-
const a = await generateMerkleRoot(
|
|
103
|
-
chunkRoots.map((a2) => Hex.fromHexInput(a2))
|
|
104
|
-
);
|
|
105
|
-
const entry = {
|
|
106
|
-
chunkset_root: a.toString(),
|
|
107
|
-
chunk_commitments: chunkRoots.map(
|
|
108
|
-
(chunk) => Hex.fromHexInput(chunk).toString()
|
|
109
|
-
)
|
|
110
|
-
};
|
|
111
|
-
return { h: a, entry };
|
|
112
|
-
}
|
|
113
|
-
async function generateCommitments(provider, fullData, onChunk, options) {
|
|
114
|
-
const expectedChunksetSize = provider.config.chunkSizeBytes * provider.config.erasure_k;
|
|
115
|
-
const shouldPad = options?.pad ?? true;
|
|
116
|
-
const chunksetCommitments = [];
|
|
117
|
-
const chunksetCommitmentHashes = [];
|
|
118
|
-
let rawDataSize = 0;
|
|
119
|
-
const chunksetGen = readInChunks(fullData, expectedChunksetSize);
|
|
120
|
-
for await (const [chunksetIdx, chunksetData] of chunksetGen) {
|
|
121
|
-
rawDataSize += chunksetData.length;
|
|
122
|
-
const { h, entry } = await generateChunksetCommitments(
|
|
123
|
-
shouldPad,
|
|
124
|
-
chunksetIdx,
|
|
125
|
-
chunksetData,
|
|
126
|
-
expectedChunksetSize,
|
|
127
|
-
provider,
|
|
128
|
-
onChunk
|
|
129
|
-
);
|
|
130
|
-
chunksetCommitments.push(entry);
|
|
131
|
-
chunksetCommitmentHashes.push(h);
|
|
132
|
-
}
|
|
133
|
-
if (rawDataSize === 0) {
|
|
134
|
-
const zeroChunkset = new Uint8Array(expectedChunksetSize);
|
|
135
|
-
const { h, entry } = await generateChunksetCommitments(
|
|
136
|
-
shouldPad,
|
|
137
|
-
0,
|
|
138
|
-
zeroChunkset,
|
|
139
|
-
expectedChunksetSize,
|
|
140
|
-
provider,
|
|
141
|
-
onChunk
|
|
142
|
-
);
|
|
143
|
-
chunksetCommitments.push(entry);
|
|
144
|
-
chunksetCommitmentHashes.push(h);
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
schema_version: COMMITMENT_SCHEMA_VERSION,
|
|
148
|
-
raw_data_size: rawDataSize,
|
|
149
|
-
blob_merkle_root: (await generateMerkleRoot(chunksetCommitmentHashes)).toString(),
|
|
150
|
-
chunkset_commitments: chunksetCommitments
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function validatePrePaddedChunkset(chunkset, expectedSize, chunksetIdx) {
|
|
154
|
-
if (chunkset.byteLength !== expectedSize) {
|
|
155
|
-
throw new Error(
|
|
156
|
-
`Chunkset ${chunksetIdx} has size ${chunkset.byteLength} bytes but expected ${expectedSize} bytes. Enable padding or supply pre-padded data before calling generateCommitments.`
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
return chunkset;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export {
|
|
163
|
-
COMMITMENT_SCHEMA_VERSION,
|
|
164
|
-
ChunksetCommitmentSchema,
|
|
165
|
-
expectedTotalChunksets,
|
|
166
|
-
BlobCommitmentsSchema,
|
|
167
|
-
generateMerkleRoot,
|
|
168
|
-
generateCommitments
|
|
169
|
-
};
|