@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
|
@@ -7,6 +7,43 @@ import { z } from 'zod';
|
|
|
7
7
|
* Both the server (apps/server) and SDK client (ShelbyRPCClient) should use
|
|
8
8
|
* these schemas to ensure type safety and runtime validation.
|
|
9
9
|
*/
|
|
10
|
+
/**
|
|
11
|
+
* Response from POST /v1/auth/challenge
|
|
12
|
+
*/
|
|
13
|
+
declare const ChallengeResponseSchema: z.ZodObject<{
|
|
14
|
+
challenge: z.ZodString;
|
|
15
|
+
expiresAt: z.ZodNumber;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
challenge: string;
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
}, {
|
|
20
|
+
challenge: string;
|
|
21
|
+
expiresAt: number;
|
|
22
|
+
}>;
|
|
23
|
+
type ChallengeResponse = z.infer<typeof ChallengeResponseSchema>;
|
|
24
|
+
/**
|
|
25
|
+
* Response from GET /v1/multipart-uploads?account=X&blobName=Y
|
|
26
|
+
*/
|
|
27
|
+
declare const MultipartUploadStatusResponseSchema: z.ZodObject<{
|
|
28
|
+
uploadId: z.ZodString;
|
|
29
|
+
completedParts: z.ZodArray<z.ZodNumber, "many">;
|
|
30
|
+
partSize: z.ZodNumber;
|
|
31
|
+
nParts: z.ZodNumber;
|
|
32
|
+
uploadedBytes: z.ZodNumber;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
uploadId: string;
|
|
35
|
+
completedParts: number[];
|
|
36
|
+
partSize: number;
|
|
37
|
+
nParts: number;
|
|
38
|
+
uploadedBytes: number;
|
|
39
|
+
}, {
|
|
40
|
+
uploadId: string;
|
|
41
|
+
completedParts: number[];
|
|
42
|
+
partSize: number;
|
|
43
|
+
nParts: number;
|
|
44
|
+
uploadedBytes: number;
|
|
45
|
+
}>;
|
|
46
|
+
type MultipartUploadStatusResponse = z.infer<typeof MultipartUploadStatusResponseSchema>;
|
|
10
47
|
/**
|
|
11
48
|
* Response from POST /v1/multipart-uploads
|
|
12
49
|
*/
|
|
@@ -66,4 +103,4 @@ declare const StaleMicropaymentErrorResponseSchema: z.ZodObject<{
|
|
|
66
103
|
}>;
|
|
67
104
|
type StaleMicropaymentErrorResponse = z.infer<typeof StaleMicropaymentErrorResponseSchema>;
|
|
68
105
|
|
|
69
|
-
export { type CompleteMultipartUploadResponse, CompleteMultipartUploadResponseSchema, type RPCErrorResponse, RPCErrorResponseSchema, type StaleMicropaymentErrorResponse, StaleMicropaymentErrorResponseSchema, type StartMultipartUploadResponse, StartMultipartUploadResponseSchema, type UploadPartResponse, UploadPartResponseSchema };
|
|
106
|
+
export { type ChallengeResponse, ChallengeResponseSchema, type CompleteMultipartUploadResponse, CompleteMultipartUploadResponseSchema, type MultipartUploadStatusResponse, MultipartUploadStatusResponseSchema, type RPCErrorResponse, RPCErrorResponseSchema, type StaleMicropaymentErrorResponse, StaleMicropaymentErrorResponseSchema, type StartMultipartUploadResponse, StartMultipartUploadResponseSchema, type UploadPartResponse, UploadPartResponseSchema };
|
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// src/core/rpc-responses.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var ChallengeResponseSchema = z.object({
|
|
4
|
+
challenge: z.string(),
|
|
5
|
+
expiresAt: z.number()
|
|
6
|
+
});
|
|
7
|
+
var MultipartUploadStatusResponseSchema = z.object({
|
|
8
|
+
uploadId: z.string(),
|
|
9
|
+
completedParts: z.array(z.number()),
|
|
10
|
+
partSize: z.number(),
|
|
11
|
+
nParts: z.number(),
|
|
12
|
+
uploadedBytes: z.number()
|
|
13
|
+
});
|
|
14
|
+
var StartMultipartUploadResponseSchema = z.object({
|
|
15
|
+
uploadId: z.string()
|
|
16
|
+
});
|
|
17
|
+
var UploadPartResponseSchema = z.object({
|
|
18
|
+
success: z.literal(true)
|
|
19
|
+
});
|
|
20
|
+
var CompleteMultipartUploadResponseSchema = z.object({
|
|
21
|
+
success: z.literal(true)
|
|
22
|
+
});
|
|
23
|
+
var RPCErrorResponseSchema = z.object({
|
|
24
|
+
error: z.string()
|
|
25
|
+
});
|
|
26
|
+
var StaleMicropaymentErrorResponseSchema = z.object({
|
|
27
|
+
error: z.string().optional(),
|
|
28
|
+
storedMicropayment: z.string().optional()
|
|
29
|
+
});
|
|
9
30
|
export {
|
|
31
|
+
ChallengeResponseSchema,
|
|
10
32
|
CompleteMultipartUploadResponseSchema,
|
|
33
|
+
MultipartUploadStatusResponseSchema,
|
|
11
34
|
RPCErrorResponseSchema,
|
|
12
35
|
StaleMicropaymentErrorResponseSchema,
|
|
13
36
|
StartMultipartUploadResponseSchema,
|
|
@@ -1,9 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
// src/core/shelby-explorer.ts
|
|
2
|
+
import { Network } from "@aptos-labs/ts-sdk";
|
|
3
|
+
function getShelbyExplorerBaseUrl(network) {
|
|
4
|
+
const normalizedNetwork = network.toLowerCase();
|
|
5
|
+
switch (normalizedNetwork) {
|
|
6
|
+
case Network.MAINNET.toLowerCase():
|
|
7
|
+
return "https://explorer.shelby.xyz/mainnet";
|
|
8
|
+
case Network.TESTNET.toLowerCase():
|
|
9
|
+
return "https://explorer.shelby.xyz/testnet";
|
|
10
|
+
case Network.DEVNET.toLowerCase():
|
|
11
|
+
return "https://explorer.shelby.xyz/devnet";
|
|
12
|
+
case Network.LOCAL.toLowerCase():
|
|
13
|
+
return "https://explorer.shelby.xyz/local";
|
|
14
|
+
case Network.SHELBYNET.toLowerCase():
|
|
15
|
+
return "https://explorer.shelby.xyz/shelbynet";
|
|
16
|
+
default:
|
|
17
|
+
return `https://explorer.shelby.xyz/${normalizedNetwork}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function getShelbyAccountBlobsExplorerUrl(network, accountAddress) {
|
|
21
|
+
const baseUrl = getShelbyExplorerBaseUrl(network);
|
|
22
|
+
return `${baseUrl}/account/${accountAddress}/blobs`;
|
|
23
|
+
}
|
|
24
|
+
function getShelbyBlobExplorerUrl(network, accountAddress, blobName) {
|
|
25
|
+
const baseUrl = getShelbyExplorerBaseUrl(network);
|
|
26
|
+
return `${baseUrl}/account/${accountAddress}/blob/${encodeURIComponent(blobName)}`;
|
|
27
|
+
}
|
|
28
|
+
function getShelbyAccountExplorerUrl(network, accountAddress) {
|
|
29
|
+
const baseUrl = getShelbyExplorerBaseUrl(network);
|
|
30
|
+
return `${baseUrl}/account/${accountAddress}`;
|
|
31
|
+
}
|
|
7
32
|
export {
|
|
8
33
|
getShelbyAccountBlobsExplorerUrl,
|
|
9
34
|
getShelbyAccountExplorerUrl,
|
package/dist/core/strings.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AccountAddress } from '@aptos-labs/ts-sdk';
|
|
2
|
-
import { c as ClayProviderOptions } from '../../clay-codes-
|
|
2
|
+
import { c as ClayProviderOptions } from '../../clay-codes-DdXABBDx.js';
|
|
3
3
|
import { BlobName } from '../layout.js';
|
|
4
4
|
import '@shelby-protocol/clay-codes';
|
|
5
5
|
import 'zod';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "../../chunk-ZHXCVRZX.mjs";
|
|
@@ -3,7 +3,7 @@ export { ChannelInfo, SenderBuiltMicropayment, StaleChannelStateError } from './
|
|
|
3
3
|
export { PlacementGroupInfo, PlacementGroupSlot, PlacementGroupSlotStatus } from './placement_groups.js';
|
|
4
4
|
export { ActiveStateDetails, FrozenStateDetails, StorageProviderInfo, StorageProviderStateDetails, WaitlistedStateDetails } from './storage_providers.js';
|
|
5
5
|
import '@aptos-labs/ts-sdk';
|
|
6
|
-
import '../../clay-codes-
|
|
6
|
+
import '../../clay-codes-DdXABBDx.js';
|
|
7
7
|
import '@shelby-protocol/clay-codes';
|
|
8
8
|
import '../layout.js';
|
|
9
9
|
import 'zod';
|
|
@@ -1,13 +1,234 @@
|
|
|
1
|
-
|
|
2
|
-
import "../../chunk-ZHXCVRZX.mjs";
|
|
3
|
-
import "../../chunk-AD2G3QYD.mjs";
|
|
4
|
-
import "../../chunk-MQUVYMNQ.mjs";
|
|
1
|
+
// src/core/types/payments.ts
|
|
5
2
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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://api.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
|
+
};
|
|
11
232
|
export {
|
|
12
233
|
SenderBuiltMicropayment,
|
|
13
234
|
StaleChannelStateError
|
|
@@ -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://api.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 +0,0 @@
|
|
|
1
|
-
import "../../chunk-MQUVYMNQ.mjs";
|