@shelby-protocol/sdk 0.3.0 → 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 +12 -3
- package/dist/browser/index.mjs +3717 -142
- package/dist/core/aptos-explorer.mjs +46 -5
- package/dist/core/blobs.mjs +12 -4
- package/dist/core/chunk.mjs +58 -9
- package/dist/core/clients/ShelbyBlobClient.d.ts +0 -43
- 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.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 +106 -3
- package/dist/core/clients/ShelbyRPCClient.mjs +1261 -12
- package/dist/core/clients/index.d.ts +2 -1
- package/dist/core/clients/index.mjs +3420 -39
- package/dist/core/clients/utils.mjs +65 -6
- package/dist/core/commitments.mjs +270 -11
- package/dist/core/constants.d.ts +2 -2
- package/dist/core/constants.mjs +39 -16
- package/dist/core/erasure/clay-codes.mjs +129 -4
- package/dist/core/erasure/constants.mjs +33 -10
- package/dist/core/erasure/default.mjs +191 -9
- package/dist/core/erasure/index.mjs +266 -23
- package/dist/core/erasure/reed-solomon.mjs +68 -4
- package/dist/core/erasure/utils.mjs +0 -2
- package/dist/core/errors.mjs +29 -8
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.mjs +3711 -142
- 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.mjs +29 -10
- package/dist/core/shelby-explorer.mjs +31 -6
- package/dist/core/strings.mjs +0 -2
- package/dist/core/types/blobs.mjs +0 -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 +1 -0
- package/dist/node/clients/ShelbyNodeClient.mjs +2919 -24
- package/dist/node/clients/index.d.ts +1 -0
- package/dist/node/clients/index.mjs +2920 -26
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.mjs +3734 -149
- 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 +6 -2
- package/dist/chunk-3NRBHSMQ.mjs +0 -12
- package/dist/chunk-5BVSWXQJ.mjs +0 -801
- package/dist/chunk-6FJNAUU5.mjs +0 -278
- package/dist/chunk-6XSZRDLJ.mjs +0 -375
- package/dist/chunk-7P6ASYW6.mjs +0 -9
- package/dist/chunk-A4IG6GSE.mjs +0 -21
- package/dist/chunk-AD2G3QYD.mjs +0 -0
- package/dist/chunk-AUQDI5BS.mjs +0 -43
- package/dist/chunk-AY3HBWXA.mjs +0 -51
- package/dist/chunk-BDSW5PHM.mjs +0 -37
- 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-JTXYKO3U.mjs +0 -38
- package/dist/chunk-KG2TMLEV.mjs +0 -207
- package/dist/chunk-M3CP5TFP.mjs +0 -39
- package/dist/chunk-M7W43K2Q.mjs +0 -505
- package/dist/chunk-MB7C7VQF.mjs +0 -0
- package/dist/chunk-MNCQBEMS.mjs +0 -55
- package/dist/chunk-MQUVYMNQ.mjs +0 -0
- package/dist/chunk-NEO7Z3ZQ.mjs +0 -49
- package/dist/chunk-NHWWORCH.mjs +0 -72
- package/dist/chunk-OEK24ON7.mjs +0 -135
- package/dist/chunk-QQ57OGQ2.mjs +0 -0
- package/dist/chunk-RNNJXTX2.mjs +0 -154
- package/dist/chunk-S6Q4OG7H.mjs +0 -83
- package/dist/chunk-TET3DJEO.mjs +0 -199
- package/dist/chunk-UEZNZBJO.mjs +0 -104
- package/dist/chunk-V46D5NBW.mjs +0 -11
- package/dist/chunk-V4B3GAMQ.mjs +0 -42
- package/dist/chunk-WFWRBNTW.mjs +0 -412
- package/dist/chunk-WTICJPDB.mjs +0 -0
- package/dist/chunk-XNEIWM4O.mjs +0 -0
- package/dist/chunk-Z4FZ7W6L.mjs +0 -39
- package/dist/chunk-Z7RFCADT.mjs +0 -0
- package/dist/chunk-ZHXCVRZX.mjs +0 -0
package/dist/chunk-M7W43K2Q.mjs
DELETED
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SenderBuiltMicropayment
|
|
3
|
-
} from "./chunk-KG2TMLEV.mjs";
|
|
4
|
-
import {
|
|
5
|
-
getShelbyIndexerClient
|
|
6
|
-
} from "./chunk-NEO7Z3ZQ.mjs";
|
|
7
|
-
import {
|
|
8
|
-
getAptosConfig
|
|
9
|
-
} from "./chunk-V4B3GAMQ.mjs";
|
|
10
|
-
import {
|
|
11
|
-
normalizeAddress
|
|
12
|
-
} from "./chunk-UEZNZBJO.mjs";
|
|
13
|
-
import {
|
|
14
|
-
MICROPAYMENTS_DEPLOYER
|
|
15
|
-
} from "./chunk-MNCQBEMS.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-MB7C7VQF.mjs
DELETED
|
File without changes
|
package/dist/chunk-MNCQBEMS.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// src/core/constants.ts
|
|
2
|
-
import { Network } from "@aptos-labs/ts-sdk";
|
|
3
|
-
var DEFAULT_PROJECT_NAME = "shelby";
|
|
4
|
-
var DEFAULT_PROJECT_DESCRIPTION = "High performance, decentralized storage";
|
|
5
|
-
var NetworkToShelbyRPCBaseUrl = {
|
|
6
|
-
[Network.SHELBYNET]: "https://api.shelbynet.shelby.xyz/shelby",
|
|
7
|
-
[Network.NETNA]: void 0,
|
|
8
|
-
[Network.DEVNET]: void 0,
|
|
9
|
-
[Network.TESTNET]: "https://api.testnet.shelby.xyz/shelby",
|
|
10
|
-
[Network.MAINNET]: void 0,
|
|
11
|
-
[Network.LOCAL]: void 0,
|
|
12
|
-
[Network.CUSTOM]: void 0
|
|
13
|
-
};
|
|
14
|
-
var NetworkToShelbyBlobIndexerBaseUrl = {
|
|
15
|
-
[Network.SHELBYNET]: "https://api.shelbynet.aptoslabs.com/nocode/v1/public/alias/shelby/shelbynet/v1/graphql",
|
|
16
|
-
[Network.NETNA]: void 0,
|
|
17
|
-
[Network.DEVNET]: void 0,
|
|
18
|
-
[Network.TESTNET]: "https://api.testnet.aptoslabs.com/nocode/v1/public/alias/shelby/testnet/v1/graphql",
|
|
19
|
-
[Network.MAINNET]: void 0,
|
|
20
|
-
[Network.LOCAL]: void 0,
|
|
21
|
-
[Network.CUSTOM]: void 0
|
|
22
|
-
};
|
|
23
|
-
var NetworkToGasStationBaseUrl = {
|
|
24
|
-
[Network.SHELBYNET]: "https://api.shelbynet.shelby.xyz/gs/v1",
|
|
25
|
-
[Network.NETNA]: void 0,
|
|
26
|
-
[Network.DEVNET]: void 0,
|
|
27
|
-
[Network.TESTNET]: "https://api.testnet.shelby.xyz/gs/v1",
|
|
28
|
-
[Network.MAINNET]: void 0,
|
|
29
|
-
[Network.LOCAL]: void 0,
|
|
30
|
-
[Network.CUSTOM]: void 0
|
|
31
|
-
};
|
|
32
|
-
var SHELBY_DEPLOYER = "0x85fdb9a176ab8ef1d9d9c1b60d60b3924f0800ac1de1cc2085fb0b8bb4988e6a";
|
|
33
|
-
var MICROPAYMENTS_DEPLOYER = "0x1ae7275148bf6ef742b658fd9cbcc2e094201606f4a7bc707bab0201da8043ee";
|
|
34
|
-
var TOKEN_DEPLOYER = "0x33009e852be7f93762dd0bf303383c2cb2c5cab7a30d8238ca5f9f177ae75124";
|
|
35
|
-
var TOKEN_OBJECT_ADDRESS = "0x249f5c642a63885ff88a5113b3ba0079840af5a1357706f8c7f3bfc5dd12511f";
|
|
36
|
-
var SHELBYUSD_TOKEN_ADDRESS = TOKEN_OBJECT_ADDRESS;
|
|
37
|
-
var SHELBYUSD_TOKEN_MODULE = "shelby_usd";
|
|
38
|
-
var SHELBYUSD_TOKEN_NAME = "ShelbyUSD";
|
|
39
|
-
var SHELBYUSD_FA_METADATA_ADDRESS = "0x1b18363a9f1fe5e6ebf247daba5cc1c18052bb232efdc4c50f556053922d98e1";
|
|
40
|
-
|
|
41
|
-
export {
|
|
42
|
-
DEFAULT_PROJECT_NAME,
|
|
43
|
-
DEFAULT_PROJECT_DESCRIPTION,
|
|
44
|
-
NetworkToShelbyRPCBaseUrl,
|
|
45
|
-
NetworkToShelbyBlobIndexerBaseUrl,
|
|
46
|
-
NetworkToGasStationBaseUrl,
|
|
47
|
-
SHELBY_DEPLOYER,
|
|
48
|
-
MICROPAYMENTS_DEPLOYER,
|
|
49
|
-
TOKEN_DEPLOYER,
|
|
50
|
-
TOKEN_OBJECT_ADDRESS,
|
|
51
|
-
SHELBYUSD_TOKEN_ADDRESS,
|
|
52
|
-
SHELBYUSD_TOKEN_MODULE,
|
|
53
|
-
SHELBYUSD_TOKEN_NAME,
|
|
54
|
-
SHELBYUSD_FA_METADATA_ADDRESS
|
|
55
|
-
};
|
package/dist/chunk-MQUVYMNQ.mjs
DELETED
|
File without changes
|
package/dist/chunk-NEO7Z3ZQ.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getSdk
|
|
3
|
-
} from "./chunk-TET3DJEO.mjs";
|
|
4
|
-
import {
|
|
5
|
-
getAptosConfig
|
|
6
|
-
} from "./chunk-V4B3GAMQ.mjs";
|
|
7
|
-
import {
|
|
8
|
-
NetworkToShelbyBlobIndexerBaseUrl
|
|
9
|
-
} from "./chunk-MNCQBEMS.mjs";
|
|
10
|
-
|
|
11
|
-
// src/core/operations/index.ts
|
|
12
|
-
import { Network } from "@aptos-labs/ts-sdk";
|
|
13
|
-
import { GraphQLClient } from "graphql-request";
|
|
14
|
-
function createShelbyIndexerClient(baseUrl, options) {
|
|
15
|
-
const graphqlClient = new GraphQLClient(baseUrl, options);
|
|
16
|
-
return getSdk(graphqlClient);
|
|
17
|
-
}
|
|
18
|
-
function getShelbyIndexerClient(config) {
|
|
19
|
-
const aptosConfig = getAptosConfig(config);
|
|
20
|
-
let { apiKey: indexerApiKey, baseUrl } = config.indexer ?? {};
|
|
21
|
-
if (!baseUrl) {
|
|
22
|
-
switch (aptosConfig?.network) {
|
|
23
|
-
// TODO: Add endpoints for core networks
|
|
24
|
-
case Network.MAINNET:
|
|
25
|
-
case Network.TESTNET:
|
|
26
|
-
case Network.DEVNET:
|
|
27
|
-
case Network.SHELBYNET:
|
|
28
|
-
baseUrl = NetworkToShelbyBlobIndexerBaseUrl[aptosConfig.network];
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (baseUrl === void 0) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
"The ShelbyClientConfig does not support the Shelby indexer. Please configure the endpoint in the ShelbyClientConfig.indexer.endpoint or provide a supported Aptos network."
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
const apiKey = indexerApiKey ?? config.apiKey;
|
|
38
|
-
return createShelbyIndexerClient(baseUrl, {
|
|
39
|
-
headers: {
|
|
40
|
-
...apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
|
|
41
|
-
"x-aptos-client": "shelby-ts-sdk"
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export {
|
|
47
|
-
createShelbyIndexerClient,
|
|
48
|
-
getShelbyIndexerClient
|
|
49
|
-
};
|
package/dist/chunk-NHWWORCH.mjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// src/core/erasure/reed-solomon.ts
|
|
2
|
-
import { createWasmReedSolomonBinding } from "@shelby-protocol/reed-solomon";
|
|
3
|
-
var DEFAULT_ERASURE_K = 10;
|
|
4
|
-
var DEFAULT_ERASURE_N = 16;
|
|
5
|
-
var DEFAULT_CHUNK_SIZE_BYTES = 2 * 1024 * 1024;
|
|
6
|
-
var ReedSolomonErasureCodingProvider = class {
|
|
7
|
-
config;
|
|
8
|
-
constructor(options) {
|
|
9
|
-
const erasure_k = options?.erasure_k ?? DEFAULT_ERASURE_K;
|
|
10
|
-
const erasure_n = options?.erasure_n ?? DEFAULT_ERASURE_N;
|
|
11
|
-
const chunkSizeBytes = options?.chunkSizeBytes ?? DEFAULT_CHUNK_SIZE_BYTES;
|
|
12
|
-
const enumIndex = -1;
|
|
13
|
-
if (erasure_k <= 0)
|
|
14
|
-
throw new Error("erasure_k (number of data chunks) must be > 0");
|
|
15
|
-
if (erasure_n <= erasure_k)
|
|
16
|
-
throw new Error(
|
|
17
|
-
`erasure_n (${erasure_n}) must be > erasure_k (${erasure_k})`
|
|
18
|
-
);
|
|
19
|
-
if (chunkSizeBytes <= 0) throw new Error("chunkSizeBytes must be > 0");
|
|
20
|
-
this.config = {
|
|
21
|
-
erasure_n,
|
|
22
|
-
erasure_k,
|
|
23
|
-
chunkSizeBytes,
|
|
24
|
-
enumIndex
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
encode(data) {
|
|
28
|
-
const { erasure_k, erasure_n, chunkSizeBytes } = this.config;
|
|
29
|
-
const erasure_m = erasure_n - erasure_k;
|
|
30
|
-
const systematicCapacity = erasure_k * chunkSizeBytes;
|
|
31
|
-
if (data.byteLength > systematicCapacity) {
|
|
32
|
-
throw new Error(
|
|
33
|
-
`Data size ${data.byteLength} bytes exceeds systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}).`
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
if (data.byteLength !== systematicCapacity) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
`Data size ${data.byteLength} bytes does not match systematic capacity ${systematicCapacity} bytes (erasure_k=${erasure_k} * chunkSizeBytes=${chunkSizeBytes}). Provide pre-padded data before encoding.`
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
const reedSolomon = createWasmReedSolomonBinding();
|
|
42
|
-
const shards = new Uint8Array(
|
|
43
|
-
systematicCapacity + erasure_m * chunkSizeBytes
|
|
44
|
-
);
|
|
45
|
-
shards.set(data, 0);
|
|
46
|
-
reedSolomon.encode(shards, erasure_k, erasure_m);
|
|
47
|
-
const chunks = new Array(erasure_n);
|
|
48
|
-
for (let idx = 0; idx < erasure_n; idx++) {
|
|
49
|
-
const start = idx * chunkSizeBytes;
|
|
50
|
-
chunks[idx] = shards.slice(start, start + chunkSizeBytes);
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
chunks,
|
|
54
|
-
systematic: chunks.slice(0, erasure_k),
|
|
55
|
-
parity: chunks.slice(erasure_k)
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
decode(_available, _config) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
"ReedSolomonErasureCodingProvider does not implement decode"
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
getChunkMerkleRoots() {
|
|
64
|
-
throw new Error(
|
|
65
|
-
"ReedSolomonErasureCodingProvider does not implement getChunkMerkleRoots"
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export {
|
|
71
|
-
ReedSolomonErasureCodingProvider
|
|
72
|
-
};
|