@shelby-protocol/sdk 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.d.ts +19 -10
- package/dist/browser/index.mjs +4200 -146
- 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 +155 -83
- package/dist/core/clients/ShelbyBlobClient.mjs +1286 -17
- package/dist/core/clients/ShelbyClient.d.ts +39 -6
- package/dist/core/clients/ShelbyClient.mjs +3233 -23
- package/dist/core/clients/ShelbyClientConfig.d.ts +9 -1
- package/dist/core/clients/ShelbyClientConfig.mjs +0 -1
- package/dist/core/clients/ShelbyMetadataClient.d.ts +20 -6
- package/dist/core/clients/ShelbyMetadataClient.mjs +388 -6
- package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +7 -7
- package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +894 -13
- package/dist/core/clients/ShelbyPlacementGroupClient.mjs +310 -8
- package/dist/core/clients/ShelbyRPCClient.d.ts +117 -25
- package/dist/core/clients/ShelbyRPCClient.mjs +1245 -12
- package/dist/core/clients/index.d.ts +4 -2
- package/dist/core/clients/index.mjs +3802 -39
- package/dist/core/clients/utils.mjs +65 -6
- package/dist/core/commitments.d.ts +12 -1
- package/dist/core/commitments.mjs +277 -11
- package/dist/core/constants.d.ts +3 -3
- package/dist/core/constants.mjs +39 -16
- package/dist/core/erasure/clay-codes.mjs +129 -4
- package/dist/core/erasure/constants.d.ts +16 -1
- package/dist/core/erasure/constants.mjs +48 -11
- package/dist/core/erasure/default.mjs +191 -9
- package/dist/core/erasure/index.d.ts +1 -1
- package/dist/core/erasure/index.mjs +281 -24
- package/dist/core/erasure/reed-solomon.mjs +68 -4
- package/dist/core/erasure/utils.mjs +0 -2
- package/dist/core/errors.d.ts +20 -1
- package/dist/core/errors.mjs +58 -8
- package/dist/core/index.d.ts +9 -9
- package/dist/core/index.mjs +4194 -146
- package/dist/core/layout.mjs +37 -5
- package/dist/core/networks.mjs +10 -5
- package/dist/core/operations/generated/sdk.d.ts +807 -42
- package/dist/core/operations/generated/sdk.mjs +267 -18
- package/dist/core/operations/index.d.ts +1 -1
- package/dist/core/operations/index.mjs +368 -24
- package/dist/core/promises.mjs +4 -4
- package/dist/core/rpc-responses.d.ts +1 -57
- package/dist/core/rpc-responses.mjs +14 -15
- package/dist/core/shelby-explorer.mjs +31 -6
- package/dist/core/sp/chunk_proof.d.ts +23 -0
- package/dist/core/sp/chunk_proof.mjs +113 -0
- package/dist/core/sp/index.d.ts +3 -0
- package/dist/core/sp/index.mjs +402 -0
- package/dist/core/sp/sp_write_client.d.ts +53 -0
- package/dist/core/sp/sp_write_client.mjs +302 -0
- package/dist/core/strings.mjs +0 -2
- package/dist/core/types/blobs.d.ts +24 -5
- package/dist/core/types/blobs.mjs +24 -1
- package/dist/core/types/index.d.ts +2 -2
- package/dist/core/types/index.mjs +275 -10
- 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.d.ts +32 -6
- package/dist/core/types/storage_providers.mjs +22 -1
- package/dist/core/utils.mjs +94 -8
- package/dist/gen/rpc_server_pb.d.ts +295 -0
- package/dist/gen/rpc_server_pb.mjs +28 -0
- package/dist/node/clients/ShelbyNodeClient.d.ts +2 -0
- package/dist/node/clients/ShelbyNodeClient.mjs +3237 -24
- package/dist/node/clients/index.d.ts +2 -0
- package/dist/node/clients/index.mjs +3236 -26
- package/dist/node/index.d.ts +9 -9
- package/dist/node/index.mjs +4217 -153
- package/dist/node/parallel/commitment_worker.d.ts +9 -0
- package/dist/node/parallel/commitment_worker.mjs +85 -0
- package/dist/node/parallel/commitment_worker_pool.d.ts +35 -0
- package/dist/node/parallel/commitment_worker_pool.mjs +339 -0
- package/dist/node/parallel/coverage_flush.d.ts +16 -0
- package/dist/node/parallel/coverage_flush.mjs +43 -0
- package/dist/node/parallel/default_commitment_worker_pool.d.ts +24 -0
- package/dist/node/parallel/default_commitment_worker_pool.mjs +355 -0
- package/dist/node/parallel/index.d.ts +12 -0
- package/dist/node/parallel/index.mjs +631 -0
- package/dist/node/parallel/parallel_commitments.d.ts +32 -0
- package/dist/node/parallel/parallel_commitments.mjs +614 -0
- package/dist/node/parallel/worker_pool.d.ts +74 -0
- package/dist/node/parallel/worker_pool.mjs +301 -0
- package/dist/node/testUtil.mjs +8 -4
- package/package.json +16 -5
- 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
|
@@ -137,27 +137,27 @@ interface ChannelInfo {
|
|
|
137
137
|
/**
|
|
138
138
|
* The balance of the channel.
|
|
139
139
|
*/
|
|
140
|
-
balance:
|
|
140
|
+
balance: bigint;
|
|
141
141
|
/**
|
|
142
142
|
* The creation timestamp of the channel.
|
|
143
143
|
*/
|
|
144
|
-
creationMicros:
|
|
144
|
+
creationMicros: bigint;
|
|
145
145
|
/**
|
|
146
146
|
* The current expiration timestamp of the channel.
|
|
147
147
|
*/
|
|
148
|
-
expirationMicros:
|
|
148
|
+
expirationMicros: bigint;
|
|
149
149
|
/**
|
|
150
150
|
* The sequence number for the next allowed withdrawal.
|
|
151
151
|
*/
|
|
152
|
-
nextWithdrawnSequenceNumber:
|
|
152
|
+
nextWithdrawnSequenceNumber: bigint;
|
|
153
153
|
/**
|
|
154
154
|
* The channel's payment id.
|
|
155
155
|
*/
|
|
156
|
-
paymentChannelId:
|
|
156
|
+
paymentChannelId: bigint;
|
|
157
157
|
/**
|
|
158
158
|
* The amount already withdrawn by the receiver.
|
|
159
159
|
*/
|
|
160
|
-
receiverWithdrawnAmount:
|
|
160
|
+
receiverWithdrawnAmount: bigint;
|
|
161
161
|
/**
|
|
162
162
|
* The Ed25519 public key used to verify withdrawal signatures.
|
|
163
163
|
*/
|
|
@@ -1,9 +1,234 @@
|
|
|
1
|
+
// src/core/types/payments.ts
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
AccountAddress,
|
|
4
|
+
Deserializer,
|
|
5
|
+
Hex,
|
|
6
|
+
Serializer
|
|
7
|
+
} from "@aptos-labs/ts-sdk";
|
|
8
|
+
|
|
9
|
+
// src/core/constants.ts
|
|
10
|
+
import { Network } from "@aptos-labs/ts-sdk";
|
|
11
|
+
var NetworkToShelbyRPCBaseUrl = {
|
|
12
|
+
[Network.SHELBYNET]: "https://shelby.shelbynet.shelby.xyz/shelby",
|
|
13
|
+
[Network.NETNA]: void 0,
|
|
14
|
+
[Network.DEVNET]: void 0,
|
|
15
|
+
[Network.TESTNET]: "https://api.testnet.shelby.xyz/shelby",
|
|
16
|
+
[Network.MAINNET]: void 0,
|
|
17
|
+
[Network.LOCAL]: "http://localhost:9090",
|
|
18
|
+
[Network.CUSTOM]: void 0
|
|
19
|
+
};
|
|
20
|
+
var NetworkToShelbyBlobIndexerBaseUrl = {
|
|
21
|
+
[Network.SHELBYNET]: "https://api.shelbynet.aptoslabs.com/nocode/v1/public/alias/shelby/shelbynet/v1/graphql",
|
|
22
|
+
[Network.NETNA]: void 0,
|
|
23
|
+
[Network.DEVNET]: void 0,
|
|
24
|
+
[Network.TESTNET]: "https://api.testnet.aptoslabs.com/nocode/v1/public/alias/shelby/testnet/v1/graphql",
|
|
25
|
+
[Network.MAINNET]: void 0,
|
|
26
|
+
[Network.LOCAL]: "http://localhost:8091/v1/graphql",
|
|
27
|
+
[Network.CUSTOM]: void 0
|
|
28
|
+
};
|
|
29
|
+
var NetworkToGasStationBaseUrl = {
|
|
30
|
+
[Network.SHELBYNET]: "https://api.shelbynet.shelby.xyz/gs/v1",
|
|
31
|
+
[Network.NETNA]: void 0,
|
|
32
|
+
[Network.DEVNET]: void 0,
|
|
33
|
+
[Network.TESTNET]: "https://api.testnet.shelby.xyz/gs/v1",
|
|
34
|
+
[Network.MAINNET]: void 0,
|
|
35
|
+
[Network.LOCAL]: void 0,
|
|
36
|
+
[Network.CUSTOM]: void 0
|
|
37
|
+
};
|
|
38
|
+
var MICROPAYMENTS_DEPLOYER = "0x1ae7275148bf6ef742b658fd9cbcc2e094201606f4a7bc707bab0201da8043ee";
|
|
39
|
+
|
|
40
|
+
// src/core/types/payments.ts
|
|
41
|
+
var MICROPAYMENTS_MODULE_NAME = "micropayments";
|
|
42
|
+
var WITHDRAW_APPROVAL_STRUCT_NAME = "WithdrawApproval";
|
|
43
|
+
function serializeTypeInfo(serializer, moduleAddress, moduleName, structName) {
|
|
44
|
+
moduleAddress.serialize(serializer);
|
|
45
|
+
const moduleNameBytes = new TextEncoder().encode(moduleName);
|
|
46
|
+
serializer.serializeBytes(moduleNameBytes);
|
|
47
|
+
const structNameBytes = new TextEncoder().encode(structName);
|
|
48
|
+
serializer.serializeBytes(structNameBytes);
|
|
49
|
+
}
|
|
50
|
+
var StaleChannelStateError = class _StaleChannelStateError extends Error {
|
|
51
|
+
/**
|
|
52
|
+
* The last valid micropayment stored by the server.
|
|
53
|
+
* Clients can use this to reset their local channel state.
|
|
54
|
+
*/
|
|
55
|
+
storedMicropayment;
|
|
56
|
+
constructor(storedMicropayment, message) {
|
|
57
|
+
super(
|
|
58
|
+
message ?? "Client has stale channel state. Use the returned micropayment to reset local state."
|
|
59
|
+
);
|
|
60
|
+
this.name = "StaleChannelStateError";
|
|
61
|
+
this.storedMicropayment = storedMicropayment;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns the stored micropayment as a base64-encoded string.
|
|
65
|
+
*/
|
|
66
|
+
toBase64() {
|
|
67
|
+
const bytes = this.storedMicropayment.bcsToBytes();
|
|
68
|
+
const binaryString = Array.from(
|
|
69
|
+
bytes,
|
|
70
|
+
(byte) => String.fromCharCode(byte)
|
|
71
|
+
).join("");
|
|
72
|
+
return btoa(binaryString);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a StaleChannelStateError from a base64-encoded micropayment string.
|
|
76
|
+
*/
|
|
77
|
+
static fromBase64(base64, message) {
|
|
78
|
+
const binaryString = atob(base64);
|
|
79
|
+
const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
|
|
80
|
+
const micropayment = SenderBuiltMicropayment.deserialize(bytes);
|
|
81
|
+
return new _StaleChannelStateError(micropayment, message);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var SenderBuiltMicropayment = class _SenderBuiltMicropayment {
|
|
85
|
+
/**
|
|
86
|
+
* The sender's address (owner of the payment channel).
|
|
87
|
+
*/
|
|
88
|
+
sender;
|
|
89
|
+
/**
|
|
90
|
+
* The receiver's address (beneficiary of the withdrawal).
|
|
91
|
+
*/
|
|
92
|
+
receiver;
|
|
93
|
+
/**
|
|
94
|
+
* The unique ID of the payment channel.
|
|
95
|
+
*/
|
|
96
|
+
paymentChannelId;
|
|
97
|
+
/**
|
|
98
|
+
* The cumulative amount the receiver is authorized to withdraw.
|
|
99
|
+
*/
|
|
100
|
+
amount;
|
|
101
|
+
/**
|
|
102
|
+
* The fungible asset metadata address.
|
|
103
|
+
*/
|
|
104
|
+
fungibleAssetAddress;
|
|
105
|
+
/**
|
|
106
|
+
* Monotonically increasing sequence number for replay protection.
|
|
107
|
+
*/
|
|
108
|
+
sequenceNumber;
|
|
109
|
+
/**
|
|
110
|
+
* The sender's Ed25519 public key (32 bytes).
|
|
111
|
+
* Used by the receiver to verify the signature before submitting.
|
|
112
|
+
*/
|
|
113
|
+
publicKey;
|
|
114
|
+
/**
|
|
115
|
+
* The Ed25519 signature of the SignedMessage<WithdrawApproval> struct.
|
|
116
|
+
* The SignedMessage includes TypeInfo for domain separation.
|
|
117
|
+
*/
|
|
118
|
+
signature;
|
|
119
|
+
/**
|
|
120
|
+
* The deployer address of the micropayments module.
|
|
121
|
+
* This is needed to reconstruct the TypeInfo for signature verification.
|
|
122
|
+
*/
|
|
123
|
+
deployer;
|
|
124
|
+
constructor(sender, receiver, paymentChannelId, amount, fungibleAssetAddress, sequenceNumber, publicKey, signature, deployer) {
|
|
125
|
+
this.sender = sender;
|
|
126
|
+
this.receiver = receiver;
|
|
127
|
+
this.paymentChannelId = paymentChannelId;
|
|
128
|
+
this.amount = amount;
|
|
129
|
+
this.fungibleAssetAddress = fungibleAssetAddress;
|
|
130
|
+
this.sequenceNumber = sequenceNumber;
|
|
131
|
+
this.publicKey = publicKey;
|
|
132
|
+
this.signature = signature;
|
|
133
|
+
this.deployer = deployer ?? AccountAddress.fromString(MICROPAYMENTS_DEPLOYER);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Creates the BCS-serialized message that was signed.
|
|
137
|
+
* This is a SignedMessage<WithdrawApproval> which includes:
|
|
138
|
+
* 1. TypeInfo (module_address, module_name, struct_name)
|
|
139
|
+
* 2. WithdrawApproval struct fields
|
|
140
|
+
*
|
|
141
|
+
* This format is used with signature_verify_strict_t for domain separation.
|
|
142
|
+
*/
|
|
143
|
+
getSignedMessage() {
|
|
144
|
+
return _SenderBuiltMicropayment.buildSignedMessage({
|
|
145
|
+
deployer: this.deployer,
|
|
146
|
+
sender: this.sender,
|
|
147
|
+
receiver: this.receiver,
|
|
148
|
+
fungibleAssetAddress: this.fungibleAssetAddress,
|
|
149
|
+
amount: this.amount,
|
|
150
|
+
paymentChannelId: this.paymentChannelId,
|
|
151
|
+
sequenceNumber: this.sequenceNumber
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Static helper to build the SignedMessage<WithdrawApproval> bytes from raw parameters.
|
|
156
|
+
* This can be used to create the message for signing without constructing the full object.
|
|
157
|
+
*
|
|
158
|
+
* @param params - The withdrawal approval parameters.
|
|
159
|
+
* @returns The BCS-serialized SignedMessage<WithdrawApproval> bytes.
|
|
160
|
+
*/
|
|
161
|
+
static buildSignedMessage(params) {
|
|
162
|
+
const serializer = new Serializer();
|
|
163
|
+
serializeTypeInfo(
|
|
164
|
+
serializer,
|
|
165
|
+
params.deployer,
|
|
166
|
+
MICROPAYMENTS_MODULE_NAME,
|
|
167
|
+
WITHDRAW_APPROVAL_STRUCT_NAME
|
|
168
|
+
);
|
|
169
|
+
params.sender.serialize(serializer);
|
|
170
|
+
params.receiver.serialize(serializer);
|
|
171
|
+
params.fungibleAssetAddress.serialize(serializer);
|
|
172
|
+
serializer.serializeU64(params.amount);
|
|
173
|
+
serializer.serializeU64(params.paymentChannelId);
|
|
174
|
+
serializer.serializeU64(params.sequenceNumber);
|
|
175
|
+
return serializer.toUint8Array();
|
|
176
|
+
}
|
|
177
|
+
serialize(serializer) {
|
|
178
|
+
this.sender.serialize(serializer);
|
|
179
|
+
this.receiver.serialize(serializer);
|
|
180
|
+
this.fungibleAssetAddress.serialize(serializer);
|
|
181
|
+
serializer.serializeU64(this.amount);
|
|
182
|
+
serializer.serializeU64(this.paymentChannelId);
|
|
183
|
+
serializer.serializeU64(this.sequenceNumber);
|
|
184
|
+
serializer.serializeBytes(this.publicKey);
|
|
185
|
+
serializer.serializeBytes(this.signature);
|
|
186
|
+
this.deployer.serialize(serializer);
|
|
187
|
+
}
|
|
188
|
+
bcsToBytes() {
|
|
189
|
+
const serializer = new Serializer();
|
|
190
|
+
this.serialize(serializer);
|
|
191
|
+
return serializer.toUint8Array();
|
|
192
|
+
}
|
|
193
|
+
bcsToHex() {
|
|
194
|
+
return Hex.fromHexInput(this.bcsToBytes());
|
|
195
|
+
}
|
|
196
|
+
toStringWithoutPrefix() {
|
|
197
|
+
return this.bcsToHex().toStringWithoutPrefix();
|
|
198
|
+
}
|
|
199
|
+
toString() {
|
|
200
|
+
return this.bcsToHex().toString();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Deserializes a SenderBuiltMicropayment from BCS bytes.
|
|
204
|
+
* @param bytes - The bytes to deserialize from (Uint8Array or hex string).
|
|
205
|
+
* @returns A new SenderBuiltMicropayment instance.
|
|
206
|
+
*/
|
|
207
|
+
static deserialize(bytes) {
|
|
208
|
+
const bytesArray = typeof bytes === "string" ? Hex.fromHexInput(bytes).toUint8Array() : bytes;
|
|
209
|
+
const deserializer = new Deserializer(bytesArray);
|
|
210
|
+
const sender = AccountAddress.deserialize(deserializer);
|
|
211
|
+
const receiver = AccountAddress.deserialize(deserializer);
|
|
212
|
+
const fungibleAssetAddress = AccountAddress.deserialize(deserializer);
|
|
213
|
+
const amount = deserializer.deserializeU64();
|
|
214
|
+
const paymentChannelId = deserializer.deserializeU64();
|
|
215
|
+
const sequenceNumber = deserializer.deserializeU64();
|
|
216
|
+
const publicKey = deserializer.deserializeBytes();
|
|
217
|
+
const signature = deserializer.deserializeBytes();
|
|
218
|
+
const deployer = AccountAddress.deserialize(deserializer);
|
|
219
|
+
return new _SenderBuiltMicropayment(
|
|
220
|
+
sender,
|
|
221
|
+
receiver,
|
|
222
|
+
paymentChannelId,
|
|
223
|
+
amount,
|
|
224
|
+
fungibleAssetAddress,
|
|
225
|
+
sequenceNumber,
|
|
226
|
+
publicKey,
|
|
227
|
+
signature,
|
|
228
|
+
deployer
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
7
232
|
export {
|
|
8
233
|
SenderBuiltMicropayment,
|
|
9
234
|
StaleChannelStateError
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "../../chunk-AD2G3QYD.mjs";
|
|
@@ -1,23 +1,49 @@
|
|
|
1
1
|
import { AccountAddress } from '@aptos-labs/ts-sdk';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Variant names of `ActiveProviderCondition`. Single source of truth — the
|
|
5
|
+
* type below is derived from this tuple so adding a variant means editing
|
|
6
|
+
* one array.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors the on-chain `ActiveProviderCondition` enum in
|
|
9
|
+
* `move/shelby_contract/sources/storage_provider_registry.move`. Keep in sync
|
|
10
|
+
* with the Move enum — the metadata-client parser fails closed (throws) on
|
|
11
|
+
* unknown variants so the mismatch surfaces immediately.
|
|
12
|
+
*/
|
|
13
|
+
declare const ACTIVE_PROVIDER_CONDITIONS: readonly ["Normal", "Faulty", "Leaving", "Evicted", "PendingLeaving"];
|
|
14
|
+
/**
|
|
15
|
+
* Condition of an active storage provider.
|
|
16
|
+
*/
|
|
17
|
+
type ActiveProviderCondition = (typeof ACTIVE_PROVIDER_CONDITIONS)[number];
|
|
18
|
+
/**
|
|
19
|
+
* Type guard for `ActiveProviderCondition` — used by the metadata-client
|
|
20
|
+
* parser to reject unknown wire-format variants.
|
|
21
|
+
*/
|
|
22
|
+
declare function isActiveProviderCondition(value: unknown): value is ActiveProviderCondition;
|
|
23
|
+
/**
|
|
24
|
+
* Returns whether a condition is task-eligible. Mirrors Move's
|
|
25
|
+
* `is_active_for_tasks` in `storage_provider_registry.move` — adding a new
|
|
26
|
+
* task-eligible condition on-chain means updating the set above.
|
|
27
|
+
*/
|
|
28
|
+
declare function isActiveForTasks(condition: ActiveProviderCondition): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* State details for active storage providers.
|
|
5
31
|
*/
|
|
6
32
|
interface ActiveStateDetails {
|
|
7
33
|
variant: "Active";
|
|
34
|
+
/** FixedPoint64 serializes as string. */
|
|
8
35
|
quota: string;
|
|
9
36
|
stakeAtStartOfStakingEpoch: string;
|
|
10
|
-
|
|
11
|
-
leaving: boolean;
|
|
37
|
+
condition: ActiveProviderCondition;
|
|
12
38
|
}
|
|
13
39
|
/**
|
|
14
|
-
* State details for waitlisted storage providers
|
|
40
|
+
* State details for waitlisted storage providers.
|
|
15
41
|
*/
|
|
16
42
|
interface WaitlistedStateDetails {
|
|
17
43
|
variant: "Waitlisted";
|
|
18
44
|
}
|
|
19
45
|
/**
|
|
20
|
-
* State details for frozen storage providers
|
|
46
|
+
* State details for frozen storage providers.
|
|
21
47
|
*/
|
|
22
48
|
interface FrozenStateDetails {
|
|
23
49
|
variant: "Frozen";
|
|
@@ -58,4 +84,4 @@ interface StorageProviderInfo {
|
|
|
58
84
|
state: StorageProviderStateDetails;
|
|
59
85
|
}
|
|
60
86
|
|
|
61
|
-
export type
|
|
87
|
+
export { type ActiveProviderCondition, type ActiveStateDetails, type FrozenStateDetails, type StorageProviderInfo, type StorageProviderStateDetails, type WaitlistedStateDetails, isActiveForTasks, isActiveProviderCondition };
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
// src/core/types/storage_providers.ts
|
|
2
|
+
var ACTIVE_PROVIDER_CONDITIONS = [
|
|
3
|
+
"Normal",
|
|
4
|
+
"Faulty",
|
|
5
|
+
"Leaving",
|
|
6
|
+
"Evicted",
|
|
7
|
+
"PendingLeaving"
|
|
8
|
+
];
|
|
9
|
+
function isActiveProviderCondition(value) {
|
|
10
|
+
return typeof value === "string" && ACTIVE_PROVIDER_CONDITIONS.includes(value);
|
|
11
|
+
}
|
|
12
|
+
var TASK_ELIGIBLE_CONDITIONS = /* @__PURE__ */ new Set([
|
|
13
|
+
"Normal",
|
|
14
|
+
"PendingLeaving"
|
|
15
|
+
]);
|
|
16
|
+
function isActiveForTasks(condition) {
|
|
17
|
+
return TASK_ELIGIBLE_CONDITIONS.has(condition);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
isActiveForTasks,
|
|
21
|
+
isActiveProviderCondition
|
|
22
|
+
};
|
package/dist/core/utils.mjs
CHANGED
|
@@ -1,12 +1,98 @@
|
|
|
1
|
+
// src/core/utils.ts
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
AccountAddress,
|
|
4
|
+
Hex
|
|
5
|
+
} from "@aptos-labs/ts-sdk";
|
|
6
|
+
async function* readInChunks(input, chunkSize) {
|
|
7
|
+
let idx = 0;
|
|
8
|
+
if (isReadableStream(input)) {
|
|
9
|
+
const reader = input.getReader();
|
|
10
|
+
let buffer = new Uint8Array(chunkSize);
|
|
11
|
+
let bufferWriteOffset = 0;
|
|
12
|
+
try {
|
|
13
|
+
while (true) {
|
|
14
|
+
const { value, done } = await reader.read();
|
|
15
|
+
if (done) break;
|
|
16
|
+
if (value === void 0) continue;
|
|
17
|
+
let srcOffset = 0;
|
|
18
|
+
while (srcOffset < value.length) {
|
|
19
|
+
const remainingCapacity = chunkSize - bufferWriteOffset;
|
|
20
|
+
const bytesToCopy = Math.min(
|
|
21
|
+
remainingCapacity,
|
|
22
|
+
value.length - srcOffset
|
|
23
|
+
);
|
|
24
|
+
buffer.set(
|
|
25
|
+
value.subarray(srcOffset, srcOffset + bytesToCopy),
|
|
26
|
+
bufferWriteOffset
|
|
27
|
+
);
|
|
28
|
+
bufferWriteOffset += bytesToCopy;
|
|
29
|
+
srcOffset += bytesToCopy;
|
|
30
|
+
if (bufferWriteOffset >= chunkSize) {
|
|
31
|
+
yield [idx++, buffer];
|
|
32
|
+
buffer = new Uint8Array(chunkSize);
|
|
33
|
+
bufferWriteOffset = 0;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} finally {
|
|
38
|
+
reader.releaseLock();
|
|
39
|
+
}
|
|
40
|
+
if (bufferWriteOffset > 0) {
|
|
41
|
+
yield [idx++, buffer.subarray(0, bufferWriteOffset)];
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const view = toUint8Array(input);
|
|
46
|
+
for (let offset = 0; offset < view.byteLength; offset += chunkSize) {
|
|
47
|
+
yield [
|
|
48
|
+
idx++,
|
|
49
|
+
view.subarray(offset, Math.min(offset + chunkSize, view.byteLength))
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function zeroPadBytes(buffer, desiredLength) {
|
|
54
|
+
if (buffer.byteLength === desiredLength) {
|
|
55
|
+
return buffer;
|
|
56
|
+
}
|
|
57
|
+
if (buffer.byteLength > desiredLength) {
|
|
58
|
+
return buffer.subarray(0, desiredLength);
|
|
59
|
+
}
|
|
60
|
+
const paddedBuffer = new Uint8Array(desiredLength);
|
|
61
|
+
paddedBuffer.set(buffer);
|
|
62
|
+
return paddedBuffer;
|
|
63
|
+
}
|
|
64
|
+
async function concatHashes(parts) {
|
|
65
|
+
const chunks = parts.map((part) => Hex.fromHexInput(part).toUint8Array());
|
|
66
|
+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);
|
|
67
|
+
const combined = new Uint8Array(totalLength);
|
|
68
|
+
let offset = 0;
|
|
69
|
+
for (const chunk of chunks) {
|
|
70
|
+
combined.set(chunk, offset);
|
|
71
|
+
offset += chunk.byteLength;
|
|
72
|
+
}
|
|
73
|
+
return Hex.fromHexInput(
|
|
74
|
+
new Uint8Array(await crypto.subtle.digest("SHA-256", combined))
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function isReadableStream(value) {
|
|
78
|
+
return typeof value === "object" && value !== null && "getReader" in value && typeof value.getReader === "function";
|
|
79
|
+
}
|
|
80
|
+
function toUint8Array(view) {
|
|
81
|
+
return view instanceof Uint8Array ? view : new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
82
|
+
}
|
|
83
|
+
function buildRequestUrl(path, baseUrl) {
|
|
84
|
+
const baseHasSlash = baseUrl.endsWith("/");
|
|
85
|
+
const safeBase = baseHasSlash ? baseUrl : `${baseUrl}/`;
|
|
86
|
+
const safePath = path.replace(/^\/+/, "");
|
|
87
|
+
return new URL(safePath, safeBase);
|
|
88
|
+
}
|
|
89
|
+
function getBlobNameSuffix(blobName) {
|
|
90
|
+
const parts = blobName.split("/");
|
|
91
|
+
return parts.slice(1).join("/") || "";
|
|
92
|
+
}
|
|
93
|
+
function normalizeAddress(address) {
|
|
94
|
+
return AccountAddress.from(address, { maxMissingChars: 63 });
|
|
95
|
+
}
|
|
10
96
|
export {
|
|
11
97
|
buildRequestUrl,
|
|
12
98
|
concatHashes,
|