@shelby-protocol/sdk 0.2.0 → 0.2.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 +1 -1
- package/dist/browser/index.mjs +31 -29
- package/dist/{chunk-ZEDD2MPU.mjs → chunk-33BZ7KYA.mjs} +1 -1
- package/dist/chunk-3NRBHSMQ.mjs +12 -0
- package/dist/{chunk-7PN65RDX.mjs → chunk-5CES6RPZ.mjs} +11 -9
- package/dist/{chunk-MV6FNYAU.mjs → chunk-7O77OM4T.mjs} +98 -19
- package/dist/{chunk-2WEX3K7C.mjs → chunk-BXEVML7N.mjs} +1 -1
- package/dist/{chunk-PJVWGMVI.mjs → chunk-EFR6H3RT.mjs} +7 -7
- package/dist/{chunk-SRV4YWFH.mjs → chunk-IBAUPQOF.mjs} +11 -12
- package/dist/chunk-KTVNKLBT.mjs +207 -0
- package/dist/{chunk-E5QCRTBU.mjs → chunk-OQNP5QXH.mjs} +85 -73
- package/dist/{chunk-4JZO2D7T.mjs → chunk-UEZNZBJO.mjs} +9 -2
- package/dist/core/blobs.mjs +2 -1
- package/dist/core/clients/ShelbyBlobClient.mjs +5 -5
- package/dist/core/clients/ShelbyClient.d.ts +1 -1
- package/dist/core/clients/ShelbyClient.mjs +10 -10
- package/dist/core/clients/ShelbyMetadataClient.d.ts +56 -5
- package/dist/core/clients/ShelbyMetadataClient.mjs +2 -1
- package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +39 -34
- package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +4 -3
- package/dist/core/clients/ShelbyRPCClient.mjs +4 -4
- package/dist/core/clients/index.mjs +17 -17
- package/dist/core/commitments.mjs +2 -2
- package/dist/core/erasure/index.mjs +3 -3
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.mjs +31 -29
- package/dist/core/types/index.mjs +3 -2
- package/dist/core/types/payments.d.ts +82 -9
- package/dist/core/types/payments.mjs +2 -1
- package/dist/core/types/placement_groups.d.ts +2 -2
- package/dist/core/types/storage_providers.d.ts +2 -2
- package/dist/core/utils.d.ts +3 -2
- package/dist/core/utils.mjs +3 -1
- package/dist/node/clients/ShelbyNodeClient.mjs +11 -11
- package/dist/node/clients/index.mjs +11 -11
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.mjs +35 -33
- package/package.json +1 -1
- package/dist/chunk-4MG4XGY4.mjs +0 -91
- package/dist/chunk-OTBLZL2S.mjs +0 -9
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MICROPAYMENTS_DEPLOYER
|
|
3
|
+
} from "./chunk-4ZOFT75Q.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
|
+
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SenderBuiltMicropayment
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KTVNKLBT.mjs";
|
|
4
4
|
import {
|
|
5
5
|
getShelbyIndexerClient
|
|
6
6
|
} from "./chunk-CGYJLKBU.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
15
|
} from "./chunk-4ZOFT75Q.mjs";
|
|
@@ -14,7 +17,8 @@ import {
|
|
|
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
|
|
205
|
-
* @param params.receiver - The account that
|
|
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.
|
|
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
|
|
220
|
+
* @returns A SenderBuiltMicropayment containing the signed approval.
|
|
213
221
|
*
|
|
214
222
|
* @example
|
|
215
223
|
* ```typescript
|
|
216
|
-
* const senderBuiltMicropayment =
|
|
217
|
-
* sender:
|
|
218
|
-
* 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
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
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
|
-
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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.
|
|
263
|
-
*
|
|
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.
|
|
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
|
|
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.
|
|
280
|
+
MoveVector.U8(params.signature)
|
|
281
281
|
]
|
|
282
282
|
};
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
285
|
-
* Withdraws funds from a micropayment channel as the receiver.
|
|
286
|
-
*
|
|
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
|
|
289
|
-
* @param params.
|
|
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:
|
|
299
|
-
* micropayment,
|
|
300
|
-
* senderSignature,
|
|
297
|
+
* receiver: receiverAccount,
|
|
298
|
+
* micropayment: senderBuiltMicropayment,
|
|
301
299
|
* });
|
|
302
300
|
* ```
|
|
303
301
|
*/
|
|
304
302
|
async receiverWithdraw(params) {
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
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.
|
|
311
|
-
|
|
312
|
-
|
|
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.
|
|
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:
|
|
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,5 +1,8 @@
|
|
|
1
1
|
// src/core/utils.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AccountAddress,
|
|
4
|
+
Hex
|
|
5
|
+
} from "@aptos-labs/ts-sdk";
|
|
3
6
|
async function* readInChunks(input, chunkSize) {
|
|
4
7
|
let idx = 0;
|
|
5
8
|
if (isReadableStream(input)) {
|
|
@@ -87,11 +90,15 @@ function getBlobNameSuffix(blobName) {
|
|
|
87
90
|
const parts = blobName.split("/");
|
|
88
91
|
return parts.slice(1).join("/") || "";
|
|
89
92
|
}
|
|
93
|
+
function normalizeAddress(address) {
|
|
94
|
+
return AccountAddress.from(address, { maxMissingChars: 63 });
|
|
95
|
+
}
|
|
90
96
|
|
|
91
97
|
export {
|
|
92
98
|
readInChunks,
|
|
93
99
|
zeroPadBytes,
|
|
94
100
|
concatHashes,
|
|
95
101
|
buildRequestUrl,
|
|
96
|
-
getBlobNameSuffix
|
|
102
|
+
getBlobNameSuffix,
|
|
103
|
+
normalizeAddress
|
|
97
104
|
};
|
package/dist/core/blobs.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MissingTransactionSubmitterError,
|
|
3
3
|
ShelbyBlobClient
|
|
4
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-IBAUPQOF.mjs";
|
|
5
5
|
import "../../chunk-XNEIWM4O.mjs";
|
|
6
|
+
import "../../chunk-NHWWORCH.mjs";
|
|
6
7
|
import "../../chunk-HPPMI7DC.mjs";
|
|
7
8
|
import "../../chunk-OGKZ575S.mjs";
|
|
8
|
-
import "../../chunk-NHWWORCH.mjs";
|
|
9
9
|
import "../../chunk-CGYJLKBU.mjs";
|
|
10
10
|
import "../../chunk-KJ24NKPH.mjs";
|
|
11
11
|
import "../../chunk-AABBONAF.mjs";
|
|
12
|
-
import "../../chunk-
|
|
13
|
-
import "../../chunk-
|
|
14
|
-
import "../../chunk-
|
|
12
|
+
import "../../chunk-3NRBHSMQ.mjs";
|
|
13
|
+
import "../../chunk-BXEVML7N.mjs";
|
|
14
|
+
import "../../chunk-UEZNZBJO.mjs";
|
|
15
15
|
import "../../chunk-JTXYKO3U.mjs";
|
|
16
16
|
import "../../chunk-AUQDI5BS.mjs";
|
|
17
17
|
import "../../chunk-4ZOFT75Q.mjs";
|
|
@@ -6,8 +6,8 @@ import { WriteBlobCommitmentsOptions, ShelbyBlobClient } from './ShelbyBlobClien
|
|
|
6
6
|
import { ShelbyClientConfig } from './ShelbyClientConfig.js';
|
|
7
7
|
import { ShelbyMetadataClient } from './ShelbyMetadataClient.js';
|
|
8
8
|
import { ShelbyRPCClient } from './ShelbyRPCClient.js';
|
|
9
|
-
import 'zod';
|
|
10
9
|
import '@shelby-protocol/clay-codes';
|
|
10
|
+
import 'zod';
|
|
11
11
|
import '../types/blobs.js';
|
|
12
12
|
import '../operations/index.js';
|
|
13
13
|
import 'graphql-request';
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ShelbyClient
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-5CES6RPZ.mjs";
|
|
4
|
+
import "../../chunk-EFR6H3RT.mjs";
|
|
5
|
+
import "../../chunk-IBAUPQOF.mjs";
|
|
5
6
|
import "../../chunk-XNEIWM4O.mjs";
|
|
7
|
+
import "../../chunk-NHWWORCH.mjs";
|
|
6
8
|
import "../../chunk-HPPMI7DC.mjs";
|
|
7
9
|
import "../../chunk-OGKZ575S.mjs";
|
|
8
|
-
import "../../chunk-
|
|
9
|
-
import "../../chunk-
|
|
10
|
-
import "../../chunk-PJVWGMVI.mjs";
|
|
11
|
-
import "../../chunk-4MG4XGY4.mjs";
|
|
10
|
+
import "../../chunk-7O77OM4T.mjs";
|
|
11
|
+
import "../../chunk-KTVNKLBT.mjs";
|
|
12
12
|
import "../../chunk-CGYJLKBU.mjs";
|
|
13
13
|
import "../../chunk-KJ24NKPH.mjs";
|
|
14
14
|
import "../../chunk-AABBONAF.mjs";
|
|
15
|
+
import "../../chunk-Z4FZ7W6L.mjs";
|
|
15
16
|
import "../../chunk-I6NG5GNL.mjs";
|
|
16
17
|
import "../../chunk-IE6LYVIA.mjs";
|
|
17
|
-
import "../../chunk-
|
|
18
|
-
import "../../chunk-
|
|
19
|
-
import "../../chunk-
|
|
18
|
+
import "../../chunk-3NRBHSMQ.mjs";
|
|
19
|
+
import "../../chunk-BXEVML7N.mjs";
|
|
20
|
+
import "../../chunk-UEZNZBJO.mjs";
|
|
20
21
|
import "../../chunk-JTXYKO3U.mjs";
|
|
21
22
|
import "../../chunk-AUQDI5BS.mjs";
|
|
22
23
|
import "../../chunk-4ZOFT75Q.mjs";
|
|
23
|
-
import "../../chunk-Z4FZ7W6L.mjs";
|
|
24
24
|
import "../../chunk-7P6ASYW6.mjs";
|
|
25
25
|
export {
|
|
26
26
|
ShelbyClient
|
|
@@ -54,19 +54,70 @@ declare class ShelbyMetadataClient {
|
|
|
54
54
|
*/
|
|
55
55
|
getSliceAddresses(): Promise<AccountAddress[]>;
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* Gets the placement group address for a slice.
|
|
58
|
+
*
|
|
59
|
+
* @param sliceAddress - The address of the slice account.
|
|
60
|
+
* @returns The placement group address as a string.
|
|
61
|
+
*/
|
|
62
|
+
private getPlacementGroupAddressForSlice;
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves the designated storage providers for a slice.
|
|
65
|
+
*
|
|
66
|
+
* Designated SPs are those appointed to store data for their slots:
|
|
67
|
+
* - Active: Currently serving data
|
|
68
|
+
* - Receiving: Receiving data during slot transfer
|
|
69
|
+
* - Repairing: Repairing data after crash or failed transfer
|
|
70
|
+
* - Reconstructing: Reconstructing data if the repair fails
|
|
71
|
+
*
|
|
72
|
+
* @param params.account - The address of the slice account.
|
|
73
|
+
* @returns An array where result[i] is the designated SP for slot i, or null if no SP is designated.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const providers = await client.getDesignatedStorageProvidersForSlice({ account: sliceAddress });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
getDesignatedStorageProvidersForSlice(params: {
|
|
81
|
+
account: AccountAddressInput;
|
|
82
|
+
}): Promise<(AccountAddress | null)[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves the active storage providers for a slice.
|
|
85
|
+
*
|
|
86
|
+
* Active SPs have a complete copy of the data for the slot, and are not in any data transfer/repair/reconstruction phase.
|
|
87
|
+
* Active SP can be audited for the data it contains.
|
|
88
|
+
* Each slot has at most one active SP.
|
|
89
|
+
*
|
|
90
|
+
* @param params.account - The address of the slice account.
|
|
91
|
+
* @returns An array where result[i] is the active SP for slot i, or null if no SP is active.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const providers = await client.getActiveStorageProvidersForSlice({ account: sliceAddress });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
getActiveStorageProvidersForSlice(params: {
|
|
99
|
+
account: AccountAddressInput;
|
|
100
|
+
}): Promise<(AccountAddress | null)[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Retrieves the serving storage providers for a slice.
|
|
103
|
+
*
|
|
104
|
+
* Serving SPs are those that can respond to read requests. The serving logic is:
|
|
105
|
+
* - If an Active SP exists for a slot: Only the Active SP is serving
|
|
106
|
+
* - If no Active SP (transition in progress): Both Designated and Vacating SPs serve
|
|
107
|
+
*
|
|
108
|
+
* Each slot may have multiple serving SPs during transitions.
|
|
58
109
|
*
|
|
59
110
|
* @param params.account - The address of the slice account.
|
|
60
|
-
* @returns
|
|
111
|
+
* @returns An array where result[i] contains the serving SPs for slot i.
|
|
61
112
|
*
|
|
62
113
|
* @example
|
|
63
114
|
* ```typescript
|
|
64
|
-
* const
|
|
115
|
+
* const providers = await client.getServingStorageProvidersForSlice({ account: sliceAddress });
|
|
65
116
|
* ```
|
|
66
117
|
*/
|
|
67
|
-
|
|
118
|
+
getServingStorageProvidersForSlice(params: {
|
|
68
119
|
account: AccountAddressInput;
|
|
69
|
-
}): Promise<AccountAddress[]>;
|
|
120
|
+
}): Promise<AccountAddress[][]>;
|
|
70
121
|
}
|
|
71
122
|
|
|
72
123
|
export { ShelbyMetadataClient };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ShelbyMetadataClient
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-7O77OM4T.mjs";
|
|
4
4
|
import "../../chunk-AABBONAF.mjs";
|
|
5
|
+
import "../../chunk-UEZNZBJO.mjs";
|
|
5
6
|
import "../../chunk-4ZOFT75Q.mjs";
|
|
6
7
|
import "../../chunk-7P6ASYW6.mjs";
|
|
7
8
|
export {
|