@mysten/walrus 1.0.4 → 1.1.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/CHANGELOG.md +28 -0
- package/README.md +52 -0
- package/dist/client.d.mts +108 -36
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +177 -345
- package/dist/client.mjs.map +1 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +2 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/contracts/utils/index.d.mts.map +1 -1
- package/dist/contracts/utils/index.mjs.map +1 -1
- package/dist/contracts/walrus/blob.d.mts +12 -12
- package/dist/contracts/walrus/blob.d.mts.map +1 -1
- package/dist/contracts/walrus/storage_node.d.mts +8 -8
- package/dist/contracts/walrus/storage_node.d.mts.map +1 -1
- package/dist/error.d.mts.map +1 -1
- package/dist/files/blob.d.mts.map +1 -1
- package/dist/files/file.d.mts.map +1 -1
- package/dist/files/readers/blob.d.mts.map +1 -1
- package/dist/files/readers/quilt-file.d.mts +0 -1
- package/dist/files/readers/quilt-file.d.mts.map +1 -1
- package/dist/files/readers/quilt.d.mts.map +1 -1
- package/dist/flows/write-blob.mjs +227 -0
- package/dist/flows/write-blob.mjs.map +1 -0
- package/dist/flows/write-files.mjs +112 -0
- package/dist/flows/write-files.mjs.map +1 -0
- package/dist/index.d.mts +3 -2
- package/dist/storage-node/client.d.mts.map +1 -1
- package/dist/storage-node/client.mjs +14 -0
- package/dist/storage-node/client.mjs.map +1 -1
- package/dist/storage-node/error.d.mts.map +1 -1
- package/dist/storage-node/types.d.mts +2 -1
- package/dist/storage-node/types.d.mts.map +1 -1
- package/dist/storage-node/utils.d.mts.map +1 -1
- package/dist/types.d.mts +82 -30
- package/dist/types.d.mts.map +1 -1
- package/dist/upload-relay/client.d.mts.map +1 -1
- package/dist/utils/bcs.d.mts +1 -2
- package/dist/utils/bcs.d.mts.map +1 -1
- package/dist/utils/bcs.mjs +14 -1
- package/dist/utils/bcs.mjs.map +1 -1
- package/dist/utils/quilts.d.mts +0 -1
- package/dist/utils/quilts.d.mts.map +1 -1
- package/docs/index.md +174 -129
- package/package.json +9 -9
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { MoveStruct } from "../utils/index.mjs";
|
|
2
2
|
import { Transaction } from "@mysten/sui/transactions";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _mysten_sui_bcs34 from "@mysten/sui/bcs";
|
|
4
4
|
|
|
5
5
|
//#region src/contracts/walrus/blob.d.ts
|
|
6
6
|
declare const Blob: MoveStruct<{
|
|
7
|
-
id:
|
|
8
|
-
registered_epoch:
|
|
9
|
-
blob_id:
|
|
10
|
-
size:
|
|
11
|
-
encoding_type:
|
|
12
|
-
certified_epoch:
|
|
7
|
+
id: _mysten_sui_bcs34.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
8
|
+
registered_epoch: _mysten_sui_bcs34.BcsType<number, number, "u32">;
|
|
9
|
+
blob_id: _mysten_sui_bcs34.BcsType<string, string | number | bigint, "u256">;
|
|
10
|
+
size: _mysten_sui_bcs34.BcsType<string, string | number | bigint, "u64">;
|
|
11
|
+
encoding_type: _mysten_sui_bcs34.BcsType<number, number, "u8">;
|
|
12
|
+
certified_epoch: _mysten_sui_bcs34.BcsType<number | null, number | null | undefined, "Option<u32>">;
|
|
13
13
|
storage: MoveStruct<{
|
|
14
|
-
id:
|
|
15
|
-
start_epoch:
|
|
16
|
-
end_epoch:
|
|
17
|
-
storage_size:
|
|
14
|
+
id: _mysten_sui_bcs34.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
15
|
+
start_epoch: _mysten_sui_bcs34.BcsType<number, number, "u32">;
|
|
16
|
+
end_epoch: _mysten_sui_bcs34.BcsType<number, number, "u32">;
|
|
17
|
+
storage_size: _mysten_sui_bcs34.BcsType<string, string | number | bigint, "u64">;
|
|
18
18
|
}, "@local-pkg/walrus::storage_resource::Storage">;
|
|
19
|
-
deletable:
|
|
19
|
+
deletable: _mysten_sui_bcs34.BcsType<boolean, boolean, "bool">;
|
|
20
20
|
}, "@local-pkg/walrus::blob::Blob">;
|
|
21
21
|
//#endregion
|
|
22
22
|
export { Blob };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.d.mts","names":[],"sources":["../../../src/contracts/walrus/blob.ts"],"
|
|
1
|
+
{"version":3,"file":"blob.d.mts","names":[],"sources":["../../../src/contracts/walrus/blob.ts"],"mappings":";;;;;cAQa,IAAA,EAAI,UAAA"}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { MoveStruct } from "../utils/index.mjs";
|
|
2
2
|
import { Transaction } from "@mysten/sui/transactions";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _mysten_sui_bcs48 from "@mysten/sui/bcs";
|
|
4
4
|
|
|
5
5
|
//#region src/contracts/walrus/storage_node.d.ts
|
|
6
6
|
declare const StorageNodeInfo: MoveStruct<{
|
|
7
|
-
name:
|
|
8
|
-
node_id:
|
|
9
|
-
network_address:
|
|
7
|
+
name: _mysten_sui_bcs48.BcsType<string, string, "string">;
|
|
8
|
+
node_id: _mysten_sui_bcs48.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
9
|
+
network_address: _mysten_sui_bcs48.BcsType<string, string, "string">;
|
|
10
10
|
public_key: MoveStruct<{
|
|
11
|
-
bytes:
|
|
11
|
+
bytes: _mysten_sui_bcs48.BcsType<number[], Iterable<number> & {
|
|
12
12
|
length: number;
|
|
13
13
|
}, string>;
|
|
14
14
|
}, "0x2::group_ops::Element<phantom T>">;
|
|
15
|
-
next_epoch_public_key:
|
|
15
|
+
next_epoch_public_key: _mysten_sui_bcs48.BcsType<{
|
|
16
16
|
bytes: number[];
|
|
17
17
|
} | null, {
|
|
18
18
|
bytes: Iterable<number> & {
|
|
19
19
|
length: number;
|
|
20
20
|
};
|
|
21
21
|
} | null | undefined, "Option<0x2::group_ops::Element<phantom T>>">;
|
|
22
|
-
network_public_key:
|
|
22
|
+
network_public_key: _mysten_sui_bcs48.BcsType<number[], Iterable<number> & {
|
|
23
23
|
length: number;
|
|
24
24
|
}, string>;
|
|
25
25
|
metadata: MoveStruct<{
|
|
26
|
-
id:
|
|
26
|
+
id: _mysten_sui_bcs48.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
27
27
|
}, "@local-pkg/walrus::extended_field::ExtendedField<phantom T>">;
|
|
28
28
|
}, "@local-pkg/walrus::storage_node::StorageNodeInfo">;
|
|
29
29
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage_node.d.mts","names":[],"sources":["../../../src/contracts/walrus/storage_node.ts"],"
|
|
1
|
+
{"version":3,"file":"storage_node.d.mts","names":[],"sources":["../../../src/contracts/walrus/storage_node.ts"],"mappings":";;;;;cAUa,eAAA,EAAe,UAAA;QAW1B,iBAAA,CAAA,OAAA"}
|
package/dist/error.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.mts","names":[],"sources":["../src/error.ts"],"
|
|
1
|
+
{"version":3,"file":"error.d.mts","names":[],"sources":["../src/error.ts"],"mappings":";cAGa,iBAAA,SAA0B,KAAA;AAAA,cAE1B,0BAAA,SAAmC,iBAAA;;cAGnC,yBAAA,SAAkC,iBAAA;;cAGlC,iCAAA,SAA0C,iBAAA;;cAG1C,2BAAA,SAAoC,0BAAA;;cAGpC,6BAAA,SAAsC,0BAAA;AANnD;AAAA,cASa,+BAAA,SAAwC,0BAAA;;cAGxC,uBAAA,SAAgC,0BAAA;;cAGhC,qBAAA,SAA8B,0BAAA;;cAG9B,qBAAA,SAA8B,iBAAA;;cAG9B,gBAAA,SAAyB,KAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.d.mts","names":[],"sources":["../../src/files/blob.ts"],"
|
|
1
|
+
{"version":3,"file":"blob.d.mts","names":[],"sources":["../../src/files/blob.ts"],"mappings":";;;;;cAQa,UAAA;EAAA;;IAKE,MAAA;IAAQ;EAAA;IAAY,MAAA,EAAQ,UAAA;IAAY,MAAA,EAAQ,YAAA;EAAA;EAM9D,MAAA,CAAA,GAAM,UAAA;EAIA,MAAA,CAAA,GAAU,OAAA;EAKV,KAAA,CACL,OAAA;IACC,GAAA;IACA,IAAA;MAAA,CAAU,OAAA;IAAA;IACV,WAAA;EAAA,IACK,OAAA,CAAA,UAAA;EAqCD,MAAA,CAAA,GAAM,OAAA;EAKN,WAAA,CAAA,GAAW,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.mts","names":[],"sources":["../../src/files/file.ts"],"
|
|
1
|
+
{"version":3,"file":"file.d.mts","names":[],"sources":["../../src/files/file.ts"],"mappings":";UAKiB,UAAA;EAChB,aAAA,IAAiB,OAAA;EACjB,OAAA,IAAW,OAAA,CAAQ,MAAA;EACnB,QAAA,IAAY,OAAA,CAAQ,UAAA;AAAA;AAAA,cAGR,UAAA;EAAA;SAGL,IAAA,CAAK,OAAA;IACX,QAAA,EAAU,UAAA,GAAa,IAAA;IACvB,UAAA;IACA,IAAA,GAAO,MAAA;EAAA,IACP,UAAA;;IAMa;EAAA;IAAY,MAAA,EAAQ,UAAA;EAAA;EAIlC,aAAA,CAAA,GAAa,OAAA;EAGb,OAAA,CAAA,GAAO,OAAA,CAAA,MAAA;EAIP,KAAA,CAAA,GAAK,OAAA,CAAA,UAAA,CAAA,eAAA;EAIC,IAAA,CAAA,GAAI,OAAA;EAMJ,IAAA,CAAA,GAAI,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.d.mts","names":[],"sources":["../../../src/files/readers/blob.ts"],"
|
|
1
|
+
{"version":3,"file":"blob.d.mts","names":[],"sources":["../../../src/files/readers/blob.ts"],"mappings":";;;;;;UASiB,iBAAA;EAChB,MAAA,EAAQ,YAAA;EACR,MAAA;EACA,SAAA;AAAA;AAAA,cAGY,UAAA,YAAsB,UAAA;EAAA;EAClC,MAAA;EAMA,yBAAA;;IAGc,MAAA;IAAQ,MAAA;IAAQ;EAAA,GAAa,iBAAA;EAMrC,aAAA,CAAA,GAAa,OAAA;EAIb,OAAA,CAAA,GAAO,OAAA;EAIb,cAAA,CAAA,GAAc,WAAA;EAIR,QAAA,CAAA,GAAQ,OAAA,CAAA,UAAA,CAAA,eAAA;EAad,WAAA,CAAA;;;;uBAbc,aAAA,CAAA,uBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBR,aAAA,CAAA,GAAa,OAAA;EA4Bb,aAAA,CAAA,GAAa,OAAA;EAWb,UAAA,CAAA,GAAU,OAAA;EAMV,kBAAA,CAAA;IAAqB,WAAA;IAAa;EAAA;IAAY,WAAA;IAAqB,MAAA,GAAS,WAAA;EAAA,IAAa,OAAA,CAAA,UAAA,CAAA,eAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quilt-file.d.mts","names":[],"sources":["../../../src/files/readers/quilt-file.ts"],"
|
|
1
|
+
{"version":3,"file":"quilt-file.d.mts","names":[],"sources":["../../../src/files/readers/quilt-file.ts"],"mappings":";;;;cAca,eAAA,YAA2B,UAAA;EAAA;;IAOtC,KAAA;IACA,WAAA;IACA,UAAA;IACA;EAAA;IAEA,KAAA,EAAO,WAAA;IACP,WAAA;IACA,UAAA;IACA,IAAA,GAAO,MAAA;EAAA;EAQF,QAAA,CAAA,GAAY,OAAA,CAAQ,UAAA;EAOpB,aAAA,CAAA,GAAa,OAAA;EAWb,OAAA,CAAA,GAAO,OAAA,CAAA,MAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quilt.d.mts","names":[],"sources":["../../../src/files/readers/quilt.ts"],"
|
|
1
|
+
{"version":3,"file":"quilt.d.mts","names":[],"sources":["../../../src/files/readers/quilt.ts"],"mappings":";;;;UAiBiB,kBAAA;EAChB,IAAA,EAAM,UAAA;AAAA;AAAA,cAGM,WAAA;EAAA;;IAIE;EAAA,GAAQ,kBAAA;EAkHhB,aAAA,CAAc,WAAA,WAAmB,OAAA;;;;;;EA0CjC,QAAA,CAAS,WAAA,WAAmB,OAAA;;;;;EAYlC,gBAAA,CAAiB,EAAA,WAAU,eAAA;EAYrB,SAAA,CAAA,GAAS,OAAA"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { WalrusClientError } from "../error.mjs";
|
|
2
|
+
import { CertificateBcs, parseCertificateFromBase64 } from "../utils/bcs.mjs";
|
|
3
|
+
import { fromBase64, toBase64 } from "@mysten/bcs";
|
|
4
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
5
|
+
|
|
6
|
+
//#region src/flows/write-blob.ts
|
|
7
|
+
function createWriteBlobFlow(client, ctx, options) {
|
|
8
|
+
const { resume } = options;
|
|
9
|
+
let encodeState;
|
|
10
|
+
let registerState;
|
|
11
|
+
let uploadState;
|
|
12
|
+
let certifyState;
|
|
13
|
+
const resumeBlobObjectId = resume && "blobObjectId" in resume ? resume.blobObjectId : void 0;
|
|
14
|
+
const resumeTxDigest = resume && "txDigest" in resume ? resume.txDigest : void 0;
|
|
15
|
+
const resumeNonce = resume && "nonce" in resume && resume.nonce ? fromBase64(resume.nonce) : void 0;
|
|
16
|
+
const resumeBlobId = resume ? resume.blobId : void 0;
|
|
17
|
+
const encode = async () => {
|
|
18
|
+
if (!encodeState) {
|
|
19
|
+
const { blob } = options;
|
|
20
|
+
const hasUploadRelay = ctx.hasUploadRelay();
|
|
21
|
+
const metadata$1 = hasUploadRelay ? await client.computeBlobMetadata({
|
|
22
|
+
bytes: blob,
|
|
23
|
+
nonce: resumeNonce
|
|
24
|
+
}) : await client.encodeBlob(blob);
|
|
25
|
+
if (resumeBlobId && metadata$1.blobId !== resumeBlobId) throw new WalrusClientError(`Resume blobId mismatch: expected ${resumeBlobId}, got ${metadata$1.blobId}. The blob content may have changed.`);
|
|
26
|
+
encodeState = {
|
|
27
|
+
metadata: metadata$1,
|
|
28
|
+
size: blob.length,
|
|
29
|
+
data: hasUploadRelay ? blob : void 0
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const { metadata, size } = encodeState;
|
|
33
|
+
return {
|
|
34
|
+
step: "encoded",
|
|
35
|
+
blobId: metadata.blobId,
|
|
36
|
+
rootHash: toBase64(metadata.rootHash),
|
|
37
|
+
unencodedSize: size,
|
|
38
|
+
..."nonce" in metadata ? { nonce: toBase64(metadata.nonce) } : {}
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const register = ({ epochs, deletable, owner, attributes }) => {
|
|
42
|
+
if (!encodeState) throw new Error("encode must be executed before calling register");
|
|
43
|
+
const { metadata, size } = encodeState;
|
|
44
|
+
const transaction = new Transaction();
|
|
45
|
+
transaction.setSenderIfNotSet(owner);
|
|
46
|
+
if (ctx.hasUploadRelay()) {
|
|
47
|
+
const meta = metadata;
|
|
48
|
+
transaction.add(client.sendUploadRelayTip({
|
|
49
|
+
size,
|
|
50
|
+
blobDigest: meta.blobDigest,
|
|
51
|
+
nonce: meta.nonce
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
transaction.transferObjects([client.registerBlob({
|
|
55
|
+
size,
|
|
56
|
+
epochs,
|
|
57
|
+
blobId: metadata.blobId,
|
|
58
|
+
rootHash: metadata.rootHash,
|
|
59
|
+
deletable,
|
|
60
|
+
attributes
|
|
61
|
+
})], owner);
|
|
62
|
+
registerState = {
|
|
63
|
+
...encodeState,
|
|
64
|
+
deletable
|
|
65
|
+
};
|
|
66
|
+
return transaction;
|
|
67
|
+
};
|
|
68
|
+
const upload = async (options$1) => {
|
|
69
|
+
if (!encodeState) throw new Error("encode must be executed before calling upload");
|
|
70
|
+
const { metadata, data } = encodeState;
|
|
71
|
+
const deletable = options$1?.deletable ?? registerState?.deletable ?? false;
|
|
72
|
+
let blobObject;
|
|
73
|
+
if (resumeBlobObjectId) blobObject = await client.getBlobObject(resumeBlobObjectId);
|
|
74
|
+
else if (options$1?.digest) blobObject = await ctx.getCreatedBlob(options$1.digest);
|
|
75
|
+
else throw new Error("Either resume.blobObjectId or upload digest must be provided");
|
|
76
|
+
let certificate;
|
|
77
|
+
if (ctx.hasUploadRelay()) {
|
|
78
|
+
const meta = metadata;
|
|
79
|
+
certificate = (await client.writeBlobToUploadRelay({
|
|
80
|
+
blobId: metadata.blobId,
|
|
81
|
+
blob: data,
|
|
82
|
+
nonce: meta.nonce,
|
|
83
|
+
txDigest: options$1?.digest ?? resumeTxDigest,
|
|
84
|
+
blobObjectId: blobObject.id,
|
|
85
|
+
deletable,
|
|
86
|
+
encodingType: meta.metadata.encodingType,
|
|
87
|
+
signal: options$1?.signal
|
|
88
|
+
})).certificate;
|
|
89
|
+
} else {
|
|
90
|
+
const meta = metadata;
|
|
91
|
+
const confirmations = await client.writeEncodedBlobToNodes({
|
|
92
|
+
blobId: metadata.blobId,
|
|
93
|
+
objectId: blobObject.id,
|
|
94
|
+
metadata: meta.metadata,
|
|
95
|
+
sliversByNode: meta.sliversByNode,
|
|
96
|
+
deletable,
|
|
97
|
+
signal: options$1?.signal
|
|
98
|
+
});
|
|
99
|
+
certificate = await client.certificateFromConfirmations({
|
|
100
|
+
confirmations,
|
|
101
|
+
blobId: metadata.blobId,
|
|
102
|
+
blobObjectId: blobObject.id,
|
|
103
|
+
deletable
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
uploadState = {
|
|
107
|
+
blobObject,
|
|
108
|
+
blobId: metadata.blobId,
|
|
109
|
+
deletable,
|
|
110
|
+
certificate
|
|
111
|
+
};
|
|
112
|
+
const txDigest = options$1?.digest ?? resumeTxDigest;
|
|
113
|
+
return {
|
|
114
|
+
step: "uploaded",
|
|
115
|
+
blobId: metadata.blobId,
|
|
116
|
+
blobObjectId: blobObject.id,
|
|
117
|
+
...txDigest ? { txDigest } : {},
|
|
118
|
+
certificate: CertificateBcs.serialize(certificate).toBase64()
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
const certify = () => {
|
|
122
|
+
if (!uploadState) throw new Error("upload must be executed before calling certify");
|
|
123
|
+
const { blobObject, blobId, deletable, certificate } = uploadState;
|
|
124
|
+
const transaction = client.certifyBlobTransaction({
|
|
125
|
+
certificate,
|
|
126
|
+
blobId,
|
|
127
|
+
blobObjectId: blobObject.id,
|
|
128
|
+
deletable
|
|
129
|
+
});
|
|
130
|
+
certifyState = {
|
|
131
|
+
blobObject,
|
|
132
|
+
blobId,
|
|
133
|
+
transaction
|
|
134
|
+
};
|
|
135
|
+
return transaction;
|
|
136
|
+
};
|
|
137
|
+
const executeRegister = async ({ signer, ...options$1 }) => {
|
|
138
|
+
const transaction = register(options$1);
|
|
139
|
+
const { digest } = await ctx.executeTransaction(transaction, signer, "register blob");
|
|
140
|
+
return {
|
|
141
|
+
step: "registered",
|
|
142
|
+
blobId: encodeState.metadata.blobId,
|
|
143
|
+
blobObjectId: (await ctx.getCreatedBlob(digest)).id,
|
|
144
|
+
txDigest: digest,
|
|
145
|
+
..."nonce" in encodeState.metadata ? { nonce: toBase64(encodeState.metadata.nonce) } : {}
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
const executeCertify = async ({ signer }) => {
|
|
149
|
+
const transaction = certify();
|
|
150
|
+
await ctx.executeTransaction(transaction, signer, "certify blob");
|
|
151
|
+
const blobObject = await ctx.loadBlobObject(uploadState.blobObject.id);
|
|
152
|
+
return {
|
|
153
|
+
step: "certified",
|
|
154
|
+
blobId: uploadState.blobId,
|
|
155
|
+
blobObjectId: blobObject.id,
|
|
156
|
+
blobObject
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
const getBlob = async () => {
|
|
160
|
+
if (!certifyState && !uploadState) throw new Error("upload or certify must be executed before calling getBlob");
|
|
161
|
+
const state = certifyState ?? uploadState;
|
|
162
|
+
const blobObject = await ctx.loadBlobObject(state.blobObject.id);
|
|
163
|
+
return {
|
|
164
|
+
step: "certified",
|
|
165
|
+
blobId: state.blobId,
|
|
166
|
+
blobObjectId: blobObject.id,
|
|
167
|
+
blobObject
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
const restoreUploadState = async (resumeData, deletable) => {
|
|
171
|
+
uploadState = {
|
|
172
|
+
blobObject: await client.getBlobObject(resumeData.blobObjectId),
|
|
173
|
+
blobId: resumeData.blobId,
|
|
174
|
+
deletable,
|
|
175
|
+
certificate: parseCertificateFromBase64(resumeData.certificate)
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
/** @yields {WriteBlobStep} */
|
|
179
|
+
async function* run(options$1) {
|
|
180
|
+
const resumeStep = resume?.step;
|
|
181
|
+
const stepOrder = [
|
|
182
|
+
"encoded",
|
|
183
|
+
"registered",
|
|
184
|
+
"uploaded",
|
|
185
|
+
"certified"
|
|
186
|
+
];
|
|
187
|
+
const resumeIndex = resumeStep ? stepOrder.indexOf(resumeStep) : -1;
|
|
188
|
+
if (resumeIndex >= stepOrder.indexOf("certified")) return;
|
|
189
|
+
if (resumeIndex < stepOrder.indexOf("encoded")) yield await encode();
|
|
190
|
+
else if (resumeIndex < stepOrder.indexOf("uploaded")) await encode();
|
|
191
|
+
let registerDigest;
|
|
192
|
+
if (!resumeBlobObjectId) {
|
|
193
|
+
const regResult = await executeRegister({
|
|
194
|
+
signer: options$1.signer,
|
|
195
|
+
epochs: options$1.epochs,
|
|
196
|
+
deletable: options$1.deletable,
|
|
197
|
+
owner: options$1.owner ?? options$1.signer.toSuiAddress(),
|
|
198
|
+
attributes: options$1.attributes
|
|
199
|
+
});
|
|
200
|
+
registerDigest = regResult.txDigest;
|
|
201
|
+
yield regResult;
|
|
202
|
+
} else registerState = {
|
|
203
|
+
...encodeState,
|
|
204
|
+
deletable: options$1.deletable
|
|
205
|
+
};
|
|
206
|
+
if (resumeIndex < stepOrder.indexOf("uploaded")) yield await upload({
|
|
207
|
+
digest: registerDigest ?? resumeTxDigest,
|
|
208
|
+
signal: options$1.signal
|
|
209
|
+
});
|
|
210
|
+
else await restoreUploadState(resume, options$1.deletable);
|
|
211
|
+
yield await executeCertify({ signer: options$1.signer });
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
encode,
|
|
215
|
+
register,
|
|
216
|
+
upload,
|
|
217
|
+
certify,
|
|
218
|
+
getBlob,
|
|
219
|
+
executeRegister,
|
|
220
|
+
executeCertify,
|
|
221
|
+
run
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
//#endregion
|
|
226
|
+
export { createWriteBlobFlow };
|
|
227
|
+
//# sourceMappingURL=write-blob.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-blob.mjs","names":["metadata","options"],"sources":["../../src/flows/write-blob.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64 } from '@mysten/bcs';\nimport type { Signer } from '@mysten/sui/cryptography';\nimport { Transaction } from '@mysten/sui/transactions';\n\nimport type { Blob } from '../contracts/walrus/blob.js';\nimport { WalrusClientError } from '../error.js';\nimport type {\n\tEncodingType,\n\tProtocolMessageCertificate,\n\tSliversForNode,\n\tWriteBlobFlow,\n\tWriteBlobFlowOptions,\n\tWriteBlobFlowRegisterOptions,\n\tWriteBlobFlowRunOptions,\n\tWriteBlobFlowUploadOptions,\n\tWriteBlobStep,\n\tWriteBlobStepCertified,\n\tWriteBlobStepEncoded,\n\tWriteBlobStepRegistered,\n\tWriteBlobStepUploaded,\n} from '../types.js';\nimport { CertificateBcs, parseCertificateFromBase64 } from '../utils/bcs.js';\nimport type { WalrusClient } from '../client.js';\n\nexport interface WriteBlobFlowContext {\n\thasUploadRelay(): boolean;\n\texecuteTransaction(\n\t\ttransaction: Transaction,\n\t\tsigner: Signer,\n\t\taction: string,\n\t): Promise<{ digest: string }>;\n\tgetCreatedBlob(digest: string): Promise<(typeof Blob)['$inferType']>;\n\tloadBlobObject(objectId: string): Promise<(typeof Blob)['$inferType']>;\n}\n\ntype BlobMetadataResult = {\n\tblobId: string;\n\trootHash: Uint8Array;\n\tmetadata: { encodingType: string; unencodedLength: bigint };\n\tnonce: Uint8Array;\n\tblobDigest: () => Promise<Uint8Array>;\n};\n\ntype EncodeBlobResult = {\n\tblobId: string;\n\trootHash: Uint8Array;\n\tmetadata: Awaited<ReturnType<WalrusClient['encodeBlob']>>['metadata'];\n\tsliversByNode: SliversForNode[];\n};\n\ntype EncodeState = {\n\tmetadata: BlobMetadataResult | EncodeBlobResult;\n\tsize: number;\n\tdata?: Uint8Array;\n};\n\ntype RegisterState = EncodeState & { deletable: boolean };\n\ntype UploadState = {\n\tblobObject: (typeof Blob)['$inferType'];\n\tblobId: string;\n\tdeletable: boolean;\n\tcertificate: ProtocolMessageCertificate;\n};\n\ntype CertifyState = {\n\tblobObject: (typeof Blob)['$inferType'];\n\tblobId: string;\n\ttransaction: Transaction;\n};\n\nexport function createWriteBlobFlow(\n\tclient: WalrusClient,\n\tctx: WriteBlobFlowContext,\n\toptions: WriteBlobFlowOptions,\n): WriteBlobFlow {\n\tconst { resume } = options;\n\tlet encodeState: EncodeState | undefined;\n\tlet registerState: RegisterState | undefined;\n\tlet uploadState: UploadState | undefined;\n\tlet certifyState: CertifyState | undefined;\n\n\tconst resumeBlobObjectId = resume && 'blobObjectId' in resume ? resume.blobObjectId : undefined;\n\tconst resumeTxDigest = resume && 'txDigest' in resume ? resume.txDigest : undefined;\n\tconst resumeNonce =\n\t\tresume && 'nonce' in resume && resume.nonce ? fromBase64(resume.nonce) : undefined;\n\tconst resumeBlobId = resume ? resume.blobId : undefined;\n\n\tconst encode = async (): Promise<WriteBlobStepEncoded> => {\n\t\tif (!encodeState) {\n\t\t\tconst { blob } = options;\n\t\t\tconst hasUploadRelay = ctx.hasUploadRelay();\n\t\t\tconst metadata = hasUploadRelay\n\t\t\t\t? await client.computeBlobMetadata({\n\t\t\t\t\t\tbytes: blob,\n\t\t\t\t\t\tnonce: resumeNonce,\n\t\t\t\t\t})\n\t\t\t\t: await client.encodeBlob(blob);\n\n\t\t\tif (resumeBlobId && metadata.blobId !== resumeBlobId) {\n\t\t\t\tthrow new WalrusClientError(\n\t\t\t\t\t`Resume blobId mismatch: expected ${resumeBlobId}, got ${metadata.blobId}. The blob content may have changed.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tencodeState = {\n\t\t\t\tmetadata,\n\t\t\t\tsize: blob.length,\n\t\t\t\tdata: hasUploadRelay ? blob : undefined,\n\t\t\t};\n\t\t}\n\n\t\tconst { metadata, size } = encodeState!;\n\t\treturn {\n\t\t\tstep: 'encoded' as const,\n\t\t\tblobId: metadata.blobId,\n\t\t\trootHash: toBase64(metadata.rootHash),\n\t\t\tunencodedSize: size,\n\t\t\t...('nonce' in metadata ? { nonce: toBase64(metadata.nonce) } : {}),\n\t\t};\n\t};\n\n\tconst register = ({ epochs, deletable, owner, attributes }: WriteBlobFlowRegisterOptions) => {\n\t\tif (!encodeState) {\n\t\t\tthrow new Error('encode must be executed before calling register');\n\t\t}\n\n\t\tconst { metadata, size } = encodeState;\n\t\tconst transaction = new Transaction();\n\t\ttransaction.setSenderIfNotSet(owner);\n\n\t\tif (ctx.hasUploadRelay()) {\n\t\t\tconst meta = metadata as BlobMetadataResult;\n\t\t\ttransaction.add(\n\t\t\t\tclient.sendUploadRelayTip({\n\t\t\t\t\tsize,\n\t\t\t\t\tblobDigest: meta.blobDigest,\n\t\t\t\t\tnonce: meta.nonce,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\ttransaction.transferObjects(\n\t\t\t[\n\t\t\t\tclient.registerBlob({\n\t\t\t\t\tsize,\n\t\t\t\t\tepochs,\n\t\t\t\t\tblobId: metadata.blobId,\n\t\t\t\t\trootHash: metadata.rootHash,\n\t\t\t\t\tdeletable,\n\t\t\t\t\tattributes,\n\t\t\t\t}),\n\t\t\t],\n\t\t\towner,\n\t\t);\n\n\t\tregisterState = { ...encodeState, deletable };\n\n\t\treturn transaction;\n\t};\n\n\tconst upload = async (options?: WriteBlobFlowUploadOptions): Promise<WriteBlobStepUploaded> => {\n\t\tif (!encodeState) {\n\t\t\tthrow new Error('encode must be executed before calling upload');\n\t\t}\n\n\t\tconst { metadata, data } = encodeState;\n\t\tconst deletable = options?.deletable ?? registerState?.deletable ?? false;\n\n\t\tlet blobObject: (typeof Blob)['$inferType'];\n\t\tif (resumeBlobObjectId) {\n\t\t\tblobObject = await client.getBlobObject(resumeBlobObjectId);\n\t\t} else if (options?.digest) {\n\t\t\tblobObject = await ctx.getCreatedBlob(options.digest);\n\t\t} else {\n\t\t\tthrow new Error('Either resume.blobObjectId or upload digest must be provided');\n\t\t}\n\n\t\tlet certificate: ProtocolMessageCertificate;\n\t\tif (ctx.hasUploadRelay()) {\n\t\t\tconst meta = metadata as BlobMetadataResult;\n\t\t\tcertificate = (\n\t\t\t\tawait client.writeBlobToUploadRelay({\n\t\t\t\t\tblobId: metadata.blobId,\n\t\t\t\t\tblob: data!,\n\t\t\t\t\tnonce: meta.nonce,\n\t\t\t\t\ttxDigest: options?.digest ?? resumeTxDigest!,\n\t\t\t\t\tblobObjectId: blobObject.id,\n\t\t\t\t\tdeletable,\n\t\t\t\t\tencodingType: meta.metadata.encodingType as EncodingType,\n\t\t\t\t\tsignal: options?.signal,\n\t\t\t\t})\n\t\t\t).certificate;\n\t\t} else {\n\t\t\tconst meta = metadata as EncodeBlobResult;\n\t\t\tconst confirmations = await client.writeEncodedBlobToNodes({\n\t\t\t\tblobId: metadata.blobId,\n\t\t\t\tobjectId: blobObject.id,\n\t\t\t\tmetadata: meta.metadata,\n\t\t\t\tsliversByNode: meta.sliversByNode,\n\t\t\t\tdeletable,\n\t\t\t\tsignal: options?.signal,\n\t\t\t});\n\n\t\t\tcertificate = await client.certificateFromConfirmations({\n\t\t\t\tconfirmations,\n\t\t\t\tblobId: metadata.blobId,\n\t\t\t\tblobObjectId: blobObject.id,\n\t\t\t\tdeletable,\n\t\t\t});\n\t\t}\n\n\t\tuploadState = { blobObject, blobId: metadata.blobId, deletable, certificate };\n\n\t\tconst txDigest = options?.digest ?? resumeTxDigest;\n\t\treturn {\n\t\t\tstep: 'uploaded' as const,\n\t\t\tblobId: metadata.blobId,\n\t\t\tblobObjectId: blobObject.id,\n\t\t\t...(txDigest ? { txDigest } : {}),\n\t\t\tcertificate: CertificateBcs.serialize(certificate).toBase64(),\n\t\t};\n\t};\n\n\tconst certify = (): Transaction => {\n\t\tif (!uploadState) {\n\t\t\tthrow new Error('upload must be executed before calling certify');\n\t\t}\n\n\t\tconst { blobObject, blobId, deletable, certificate } = uploadState;\n\t\tconst transaction = client.certifyBlobTransaction({\n\t\t\tcertificate,\n\t\t\tblobId,\n\t\t\tblobObjectId: blobObject.id,\n\t\t\tdeletable,\n\t\t});\n\n\t\tcertifyState = { blobObject, blobId, transaction };\n\t\treturn transaction;\n\t};\n\n\tconst executeRegister = async ({\n\t\tsigner,\n\t\t...options\n\t}: WriteBlobFlowRegisterOptions & { signer: Signer }): Promise<WriteBlobStepRegistered> => {\n\t\tconst transaction = register(options);\n\t\tconst { digest } = await ctx.executeTransaction(transaction, signer, 'register blob');\n\n\t\treturn {\n\t\t\tstep: 'registered' as const,\n\t\t\tblobId: encodeState!.metadata.blobId,\n\t\t\tblobObjectId: (await ctx.getCreatedBlob(digest)).id,\n\t\t\ttxDigest: digest,\n\t\t\t...('nonce' in encodeState!.metadata ? { nonce: toBase64(encodeState!.metadata.nonce) } : {}),\n\t\t};\n\t};\n\n\tconst executeCertify = async ({\n\t\tsigner,\n\t}: {\n\t\tsigner: Signer;\n\t}): Promise<WriteBlobStepCertified> => {\n\t\tconst transaction = certify();\n\t\tawait ctx.executeTransaction(transaction, signer, 'certify blob');\n\n\t\tconst blobObject = await ctx.loadBlobObject(uploadState!.blobObject.id);\n\t\treturn {\n\t\t\tstep: 'certified' as const,\n\t\t\tblobId: uploadState!.blobId,\n\t\t\tblobObjectId: blobObject.id,\n\t\t\tblobObject,\n\t\t};\n\t};\n\n\tconst getBlob = async (): Promise<WriteBlobStepCertified> => {\n\t\tif (!certifyState && !uploadState) {\n\t\t\tthrow new Error('upload or certify must be executed before calling getBlob');\n\t\t}\n\n\t\tconst state = certifyState ?? uploadState!;\n\t\tconst blobObject = await ctx.loadBlobObject(state.blobObject.id);\n\t\treturn {\n\t\t\tstep: 'certified' as const,\n\t\t\tblobId: state.blobId,\n\t\t\tblobObjectId: blobObject.id,\n\t\t\tblobObject,\n\t\t};\n\t};\n\n\tconst restoreUploadState = async (resumeData: WriteBlobStepUploaded, deletable: boolean) => {\n\t\tconst blobObject = await client.getBlobObject(resumeData.blobObjectId);\n\t\tuploadState = {\n\t\t\tblobObject,\n\t\t\tblobId: resumeData.blobId,\n\t\t\tdeletable,\n\t\t\tcertificate: parseCertificateFromBase64(resumeData.certificate),\n\t\t};\n\t};\n\n\t/** @yields {WriteBlobStep} */\n\tasync function* run(options: WriteBlobFlowRunOptions): AsyncGenerator<WriteBlobStep> {\n\t\tconst resumeStep = resume?.step;\n\t\tconst stepOrder = ['encoded', 'registered', 'uploaded', 'certified'] as const;\n\t\tconst resumeIndex = resumeStep ? stepOrder.indexOf(resumeStep) : -1;\n\n\t\t// Already certified — nothing to do\n\t\tif (resumeIndex >= stepOrder.indexOf('certified')) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (resumeIndex < stepOrder.indexOf('encoded')) {\n\t\t\tyield await encode();\n\t\t} else if (resumeIndex < stepOrder.indexOf('uploaded')) {\n\t\t\tawait encode(); // Re-encode to populate internal state for upload\n\t\t}\n\n\t\tlet registerDigest: string | undefined;\n\t\tif (!resumeBlobObjectId) {\n\t\t\tconst regResult = await executeRegister({\n\t\t\t\tsigner: options.signer,\n\t\t\t\tepochs: options.epochs,\n\t\t\t\tdeletable: options.deletable,\n\t\t\t\towner: options.owner ?? options.signer.toSuiAddress(),\n\t\t\t\tattributes: options.attributes,\n\t\t\t});\n\t\t\tregisterDigest = regResult.txDigest;\n\t\t\tyield regResult;\n\t\t} else {\n\t\t\tregisterState = {\n\t\t\t\t...encodeState!,\n\t\t\t\tdeletable: options.deletable,\n\t\t\t};\n\t\t}\n\n\t\tif (resumeIndex < stepOrder.indexOf('uploaded')) {\n\t\t\tconst uploadResult = await upload({\n\t\t\t\tdigest: registerDigest ?? resumeTxDigest,\n\t\t\t\tsignal: options.signal,\n\t\t\t});\n\t\t\tyield uploadResult;\n\t\t} else {\n\t\t\tawait restoreUploadState(resume as WriteBlobStepUploaded, options.deletable);\n\t\t}\n\n\t\tconst certResult = await executeCertify({ signer: options.signer });\n\t\tyield certResult;\n\t}\n\n\treturn {\n\t\tencode,\n\t\tregister,\n\t\tupload,\n\t\tcertify,\n\t\tgetBlob,\n\t\texecuteRegister,\n\t\texecuteCertify,\n\t\trun,\n\t};\n}\n"],"mappings":";;;;;;AA0EA,SAAgB,oBACf,QACA,KACA,SACgB;CAChB,MAAM,EAAE,WAAW;CACnB,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CAEJ,MAAM,qBAAqB,UAAU,kBAAkB,SAAS,OAAO,eAAe;CACtF,MAAM,iBAAiB,UAAU,cAAc,SAAS,OAAO,WAAW;CAC1E,MAAM,cACL,UAAU,WAAW,UAAU,OAAO,QAAQ,WAAW,OAAO,MAAM,GAAG;CAC1E,MAAM,eAAe,SAAS,OAAO,SAAS;CAE9C,MAAM,SAAS,YAA2C;AACzD,MAAI,CAAC,aAAa;GACjB,MAAM,EAAE,SAAS;GACjB,MAAM,iBAAiB,IAAI,gBAAgB;GAC3C,MAAMA,aAAW,iBACd,MAAM,OAAO,oBAAoB;IACjC,OAAO;IACP,OAAO;IACP,CAAC,GACD,MAAM,OAAO,WAAW,KAAK;AAEhC,OAAI,gBAAgBA,WAAS,WAAW,aACvC,OAAM,IAAI,kBACT,oCAAoC,aAAa,QAAQA,WAAS,OAAO,sCACzE;AAGF,iBAAc;IACb;IACA,MAAM,KAAK;IACX,MAAM,iBAAiB,OAAO;IAC9B;;EAGF,MAAM,EAAE,UAA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;GAChB,CAAC;MAGF,OAAM,mBAAmB,QAAiCA,UAAQ,UAAU;AAI7E,QADmB,MAAM,eAAe,EAAE,QAAQA,UAAQ,QAAQ,CAAC;;AAIpE,QAAO;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { encodeQuiltPatchId } from "../utils/quilts.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/flows/write-files.ts
|
|
4
|
+
function createWriteFilesFlow(client, { files, resume }) {
|
|
5
|
+
let quiltBytes;
|
|
6
|
+
let quiltIndex;
|
|
7
|
+
const blobFlow = client.writeBlobFlow({
|
|
8
|
+
get blob() {
|
|
9
|
+
if (!quiltBytes) throw new Error("encode must be executed before accessing blob");
|
|
10
|
+
return quiltBytes;
|
|
11
|
+
},
|
|
12
|
+
resume
|
|
13
|
+
});
|
|
14
|
+
const encode = async () => {
|
|
15
|
+
if (!quiltBytes) {
|
|
16
|
+
const { quilt, index } = await client.encodeQuilt({ blobs: await Promise.all(files.map(async (file, i) => ({
|
|
17
|
+
contents: await file.bytes(),
|
|
18
|
+
identifier: await file.getIdentifier() ?? `file-${i}`,
|
|
19
|
+
tags: await file.getTags() ?? {}
|
|
20
|
+
}))) });
|
|
21
|
+
quiltBytes = quilt;
|
|
22
|
+
quiltIndex = index;
|
|
23
|
+
}
|
|
24
|
+
return blobFlow.encode();
|
|
25
|
+
};
|
|
26
|
+
const register = (options) => {
|
|
27
|
+
if (!quiltBytes) throw new Error("encode must be executed before calling register");
|
|
28
|
+
return blobFlow.register({
|
|
29
|
+
...options,
|
|
30
|
+
attributes: {
|
|
31
|
+
_walrusBlobType: "quilt",
|
|
32
|
+
...options.attributes
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const listFiles = async () => {
|
|
37
|
+
if (!quiltIndex) throw new Error("encode must be executed before calling listFiles");
|
|
38
|
+
const certResult = await blobFlow.getBlob();
|
|
39
|
+
return quiltIndex.patches.map((patch) => ({
|
|
40
|
+
id: encodeQuiltPatchId({
|
|
41
|
+
quiltId: certResult.blobId,
|
|
42
|
+
patchId: {
|
|
43
|
+
version: 1,
|
|
44
|
+
startIndex: patch.startIndex,
|
|
45
|
+
endIndex: patch.endIndex
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
blobId: certResult.blobId,
|
|
49
|
+
blobObject: certResult.blobObject
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
/** @yields {WriteBlobStep} */
|
|
53
|
+
async function* run(options) {
|
|
54
|
+
const resumeStep = resume?.step;
|
|
55
|
+
const stepOrder = [
|
|
56
|
+
"encoded",
|
|
57
|
+
"registered",
|
|
58
|
+
"uploaded",
|
|
59
|
+
"certified"
|
|
60
|
+
];
|
|
61
|
+
const resumeIndex = resumeStep ? stepOrder.indexOf(resumeStep) : -1;
|
|
62
|
+
if (resumeIndex >= stepOrder.indexOf("certified")) return;
|
|
63
|
+
if (resumeIndex < stepOrder.indexOf("encoded")) yield await encode();
|
|
64
|
+
else if (resumeIndex < stepOrder.indexOf("uploaded")) await encode();
|
|
65
|
+
const resumeBlobObjectId = resume && "blobObjectId" in resume ? resume.blobObjectId : void 0;
|
|
66
|
+
let registerDigest;
|
|
67
|
+
if (!resumeBlobObjectId) {
|
|
68
|
+
const regResult = await blobFlow.executeRegister({
|
|
69
|
+
signer: options.signer,
|
|
70
|
+
epochs: options.epochs,
|
|
71
|
+
deletable: options.deletable,
|
|
72
|
+
owner: options.owner ?? options.signer.toSuiAddress(),
|
|
73
|
+
attributes: {
|
|
74
|
+
_walrusBlobType: "quilt",
|
|
75
|
+
...options.attributes
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
registerDigest = regResult.txDigest;
|
|
79
|
+
yield regResult;
|
|
80
|
+
}
|
|
81
|
+
if (resumeIndex < stepOrder.indexOf("uploaded")) yield await blobFlow.upload({
|
|
82
|
+
digest: registerDigest,
|
|
83
|
+
deletable: options.deletable,
|
|
84
|
+
signal: options.signal
|
|
85
|
+
});
|
|
86
|
+
if (resumeIndex < stepOrder.indexOf("certified")) yield await blobFlow.executeCertify({ signer: options.signer });
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
encode,
|
|
90
|
+
register,
|
|
91
|
+
upload: blobFlow.upload,
|
|
92
|
+
certify: blobFlow.certify,
|
|
93
|
+
listFiles,
|
|
94
|
+
executeRegister: async (options) => {
|
|
95
|
+
const { signer, ...rest } = options;
|
|
96
|
+
return blobFlow.executeRegister({
|
|
97
|
+
signer,
|
|
98
|
+
...rest,
|
|
99
|
+
attributes: {
|
|
100
|
+
_walrusBlobType: "quilt",
|
|
101
|
+
...rest.attributes
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
executeCertify: blobFlow.executeCertify,
|
|
106
|
+
run
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
export { createWriteFilesFlow };
|
|
112
|
+
//# sourceMappingURL=write-files.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-files.mjs","names":[],"sources":["../../src/flows/write-files.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Signer } from '@mysten/sui/cryptography';\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type {\n\tWriteBlobFlowOptions,\n\tWriteBlobStep,\n\tWriteBlobStepEncoded,\n\tWriteFilesFlow,\n\tWriteFilesFlowOptions,\n\tWriteFilesFlowRegisterOptions,\n\tWriteFilesFlowRunOptions,\n} from '../types.js';\nimport { encodeQuiltPatchId } from '../utils/quilts.js';\nimport type { WalrusClient } from '../client.js';\n\nexport function createWriteFilesFlow(\n\tclient: WalrusClient,\n\t{ files, resume }: WriteFilesFlowOptions,\n): WriteFilesFlow {\n\tlet quiltBytes: Uint8Array | undefined;\n\tlet quiltIndex: Awaited<ReturnType<typeof client.encodeQuilt>>['index'] | undefined;\n\n\tconst blobFlow = client.writeBlobFlow({\n\t\tget blob(): Uint8Array {\n\t\t\tif (!quiltBytes) {\n\t\t\t\tthrow new Error('encode must be executed before accessing blob');\n\t\t\t}\n\t\t\treturn quiltBytes;\n\t\t},\n\t\tresume,\n\t} as WriteBlobFlowOptions); // Cast needed: blob is a lazy getter populated by encode()\n\n\tconst encode = async (): Promise<WriteBlobStepEncoded> => {\n\t\tif (!quiltBytes) {\n\t\t\tconst { quilt, index } = await client.encodeQuilt({\n\t\t\t\tblobs: await Promise.all(\n\t\t\t\t\tfiles.map(async (file, i) => ({\n\t\t\t\t\t\tcontents: await file.bytes(),\n\t\t\t\t\t\tidentifier: (await file.getIdentifier()) ?? `file-${i}`,\n\t\t\t\t\t\ttags: (await file.getTags()) ?? {},\n\t\t\t\t\t})),\n\t\t\t\t),\n\t\t\t});\n\t\t\tquiltBytes = quilt;\n\t\t\tquiltIndex = index;\n\t\t}\n\n\t\treturn blobFlow.encode();\n\t};\n\n\tconst register = (options: WriteFilesFlowRegisterOptions): Transaction => {\n\t\tif (!quiltBytes) {\n\t\t\tthrow new Error('encode must be executed before calling register');\n\t\t}\n\n\t\treturn blobFlow.register({\n\t\t\t...options,\n\t\t\tattributes: {\n\t\t\t\t_walrusBlobType: 'quilt',\n\t\t\t\t...options.attributes,\n\t\t\t},\n\t\t});\n\t};\n\n\tconst listFiles = async () => {\n\t\tif (!quiltIndex) {\n\t\t\tthrow new Error('encode must be executed before calling listFiles');\n\t\t}\n\n\t\tconst certResult = await blobFlow.getBlob();\n\t\treturn quiltIndex.patches.map((patch) => ({\n\t\t\tid: encodeQuiltPatchId({\n\t\t\t\tquiltId: certResult.blobId,\n\t\t\t\tpatchId: {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tstartIndex: patch.startIndex,\n\t\t\t\t\tendIndex: patch.endIndex,\n\t\t\t\t},\n\t\t\t}),\n\t\t\tblobId: certResult.blobId,\n\t\t\tblobObject: certResult.blobObject,\n\t\t}));\n\t};\n\n\t/** @yields {WriteBlobStep} */\n\tasync function* run(options: WriteFilesFlowRunOptions): AsyncGenerator<WriteBlobStep> {\n\t\tconst resumeStep = resume?.step;\n\t\tconst stepOrder = ['encoded', 'registered', 'uploaded', 'certified'] as const;\n\t\tconst resumeIndex = resumeStep ? stepOrder.indexOf(resumeStep) : -1;\n\n\t\tif (resumeIndex >= stepOrder.indexOf('certified')) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (resumeIndex < stepOrder.indexOf('encoded')) {\n\t\t\tyield await encode();\n\t\t} else if (resumeIndex < stepOrder.indexOf('uploaded')) {\n\t\t\tawait encode();\n\t\t}\n\n\t\tconst resumeBlobObjectId = resume && 'blobObjectId' in resume ? resume.blobObjectId : undefined;\n\t\tlet registerDigest: string | undefined;\n\t\tif (!resumeBlobObjectId) {\n\t\t\tconst regResult = await blobFlow.executeRegister({\n\t\t\t\tsigner: options.signer,\n\t\t\t\tepochs: options.epochs,\n\t\t\t\tdeletable: options.deletable,\n\t\t\t\towner: options.owner ?? options.signer.toSuiAddress(),\n\t\t\t\tattributes: {\n\t\t\t\t\t_walrusBlobType: 'quilt',\n\t\t\t\t\t...options.attributes,\n\t\t\t\t},\n\t\t\t});\n\t\t\tregisterDigest = regResult.txDigest;\n\t\t\tyield regResult;\n\t\t}\n\n\t\tif (resumeIndex < stepOrder.indexOf('uploaded')) {\n\t\t\tyield await blobFlow.upload({\n\t\t\t\tdigest: registerDigest,\n\t\t\t\tdeletable: options.deletable,\n\t\t\t\tsignal: options.signal,\n\t\t\t});\n\t\t}\n\n\t\tif (resumeIndex < stepOrder.indexOf('certified')) {\n\t\t\tyield await blobFlow.executeCertify({ signer: options.signer });\n\t\t}\n\t}\n\n\treturn {\n\t\tencode: encode,\n\t\tregister: register,\n\t\tupload: blobFlow.upload,\n\t\tcertify: blobFlow.certify,\n\t\tlistFiles: listFiles,\n\t\texecuteRegister: async (options: WriteFilesFlowRegisterOptions & { signer: Signer }) => {\n\t\t\tconst { signer, ...rest } = options;\n\t\t\treturn blobFlow.executeRegister({\n\t\t\t\tsigner,\n\t\t\t\t...rest,\n\t\t\t\tattributes: {\n\t\t\t\t\t_walrusBlobType: 'quilt',\n\t\t\t\t\t...rest.attributes,\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\texecuteCertify: blobFlow.executeCertify,\n\t\trun,\n\t};\n}\n"],"mappings":";;;AAkBA,SAAgB,qBACf,QACA,EAAE,OAAO,UACQ;CACjB,IAAI;CACJ,IAAI;CAEJ,MAAM,WAAW,OAAO,cAAc;EACrC,IAAI,OAAmB;AACtB,OAAI,CAAC,WACJ,OAAM,IAAI,MAAM,gDAAgD;AAEjE,UAAO;;EAER;EACA,CAAyB;CAE1B,MAAM,SAAS,YAA2C;AACzD,MAAI,CAAC,YAAY;GAChB,MAAM,EAAE,OAAO,UAAU,MAAM,OAAO,YAAY,EACjD,OAAO,MAAM,QAAQ,IACpB,MAAM,IAAI,OAAO,MAAM,OAAO;IAC7B,UAAU,MAAM,KAAK,OAAO;IAC5B,YAAa,MAAM,KAAK,eAAe,IAAK,QAAQ;IACpD,MAAO,MAAM,KAAK,SAAS,IAAK,EAAE;IAClC,EAAE,CACH,EACD,CAAC;AACF,gBAAa;AACb,gBAAa;;AAGd,SAAO,SAAS,QAAQ;;CAGzB,MAAM,YAAY,YAAwD;AACzE,MAAI,CAAC,WACJ,OAAM,IAAI,MAAM,kDAAkD;AAGnE,SAAO,SAAS,SAAS;GACxB,GAAG;GACH,YAAY;IACX,iBAAiB;IACjB,GAAG,QAAQ;IACX;GACD,CAAC;;CAGH,MAAM,YAAY,YAAY;AAC7B,MAAI,CAAC,WACJ,OAAM,IAAI,MAAM,mDAAmD;EAGpE,MAAM,aAAa,MAAM,SAAS,SAAS;AAC3C,SAAO,WAAW,QAAQ,KAAK,WAAW;GACzC,IAAI,mBAAmB;IACtB,SAAS,WAAW;IACpB,SAAS;KACR,SAAS;KACT,YAAY,MAAM;KAClB,UAAU,MA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ANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { blobIdFromInt, blobIdToInt } from "./utils/bcs.mjs";
|
|
2
|
+
import { StoredOnNodeStatus } from "./storage-node/types.mjs";
|
|
2
3
|
import { StorageNodeClientOptions } from "./storage-node/client.mjs";
|
|
3
4
|
import { FileReader, WalrusFile } from "./files/file.mjs";
|
|
4
|
-
import { CertifyBlobOptions, CommitteeInfo, ComputeBlobMetadataOptions, DeletableConfirmationOptions, DeleteBlobOptions, EncodingType, ExtendBlobOptions, GetBlobMetadataOptions, GetCertificationEpochOptions, GetSecondarySliverOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ProtocolMessageCertificate, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageNode, StorageWithSizeOptions, TipStrategy, UploadRelayConfig, UploadRelayTipConfig, WalrusClientConfig, WalrusClientExtensionOptions, WalrusClientRequestOptions, WalrusOptions, WalrusPackageConfig, WriteBlobAttributesOptions, WriteBlobFlow, WriteBlobFlowOptions, WriteBlobFlowRegisterOptions, WriteBlobFlowUploadOptions, WriteBlobOptions, WriteBlobToUploadRelayOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteFilesFlow, WriteFilesFlowOptions, WriteFilesFlowRegisterOptions, WriteFilesFlowUploadOptions, WriteFilesOptions, WriteMetadataOptions, WriteQuiltOptions, WriteSliverOptions, WriteSliversToNodeOptions } from "./types.mjs";
|
|
5
|
+
import { CertifyBlobOptions, CommitteeInfo, ComputeBlobMetadataOptions, DeletableConfirmationOptions, DeleteBlobOptions, EncodingType, ExtendBlobOptions, GetBlobMetadataOptions, GetCertificationEpochOptions, GetSecondarySliverOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ProtocolMessageCertificate, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageNode, StorageWithSizeOptions, TipStrategy, UploadRelayConfig, UploadRelayTipConfig, WalrusClientConfig, WalrusClientExtensionOptions, WalrusClientRequestOptions, WalrusOptions, WalrusPackageConfig, WriteBlobAttributesOptions, WriteBlobBaseOptions, WriteBlobFlow, WriteBlobFlowOptions, WriteBlobFlowRegisterOptions, WriteBlobFlowRunOptions, WriteBlobFlowUploadOptions, WriteBlobOptions, WriteBlobStep, WriteBlobStepCertified, WriteBlobStepEncoded, WriteBlobStepRegistered, WriteBlobStepUploaded, WriteBlobToUploadRelayOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteFilesFlow, WriteFilesFlowOptions, WriteFilesFlowRegisterOptions, WriteFilesFlowRunOptions, WriteFilesFlowUploadOptions, WriteFilesOptions, WriteMetadataOptions, WriteQuiltOptions, WriteSliverOptions, WriteSliversToNodeOptions } from "./types.mjs";
|
|
5
6
|
import { WalrusBlob } from "./files/blob.mjs";
|
|
6
7
|
import { WalrusClient, walrus } from "./client.mjs";
|
|
7
8
|
import { MAINNET_WALRUS_PACKAGE_CONFIG, TESTNET_WALRUS_PACKAGE_CONFIG } from "./constants.mjs";
|
|
8
9
|
import { AuthenticationError, BadRequestError, BlobNotRegisteredError, ConflictError, ConnectionError, ConnectionTimeoutError, InternalServerError, LegallyUnavailableError, NotFoundError, PermissionDeniedError, RateLimitError, StorageNodeAPIError, StorageNodeError, UnprocessableEntityError, UserAbortError } from "./storage-node/error.mjs";
|
|
9
10
|
import { BehindCurrentEpochError, BlobBlockedError, BlobNotCertifiedError, InconsistentBlobError, NoBlobMetadataReceivedError, NoBlobStatusReceivedError, NoVerifiedBlobStatusReceivedError, NotEnoughBlobConfirmationsError, NotEnoughSliversReceivedError, RetryableWalrusClientError, WalrusClientError } from "./error.mjs";
|
|
10
11
|
import { EncodeQuiltOptions, encodeQuilt } from "./utils/quilts.mjs";
|
|
11
|
-
export { AuthenticationError, BadRequestError, BehindCurrentEpochError, BlobBlockedError, BlobNotCertifiedError, BlobNotRegisteredError, CertifyBlobOptions, CommitteeInfo, ComputeBlobMetadataOptions, ConflictError, ConnectionError, ConnectionTimeoutError, DeletableConfirmationOptions, DeleteBlobOptions, type EncodeQuiltOptions, EncodingType, ExtendBlobOptions, type FileReader, GetBlobMetadataOptions, GetCertificationEpochOptions, GetSecondarySliverOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, InconsistentBlobError, InternalServerError, LegallyUnavailableError, MAINNET_WALRUS_PACKAGE_CONFIG, NoBlobMetadataReceivedError, NoBlobStatusReceivedError, NoVerifiedBlobStatusReceivedError, NotEnoughBlobConfirmationsError, NotEnoughSliversReceivedError, NotFoundError, PermissionDeniedError, ProtocolMessageCertificate, RateLimitError, ReadBlobOptions, RegisterBlobOptions, RetryableWalrusClientError, SliversForNode, StorageNode, StorageNodeAPIError, type StorageNodeClientOptions, StorageNodeError, StorageWithSizeOptions, TESTNET_WALRUS_PACKAGE_CONFIG, TipStrategy, UnprocessableEntityError, UploadRelayConfig, UploadRelayTipConfig, UserAbortError, WalrusBlob, WalrusClient, type WalrusClientConfig, WalrusClientError, WalrusClientExtensionOptions, WalrusClientRequestOptions, WalrusFile, type WalrusOptions, type WalrusPackageConfig, WriteBlobAttributesOptions, WriteBlobFlow, WriteBlobFlowOptions, WriteBlobFlowRegisterOptions, WriteBlobFlowUploadOptions, WriteBlobOptions, WriteBlobToUploadRelayOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteFilesFlow, WriteFilesFlowOptions, WriteFilesFlowRegisterOptions, WriteFilesFlowUploadOptions, WriteFilesOptions, WriteMetadataOptions, WriteQuiltOptions, WriteSliverOptions, WriteSliversToNodeOptions, blobIdFromInt, blobIdToInt, encodeQuilt, walrus };
|
|
12
|
+
export { AuthenticationError, BadRequestError, BehindCurrentEpochError, BlobBlockedError, BlobNotCertifiedError, BlobNotRegisteredError, CertifyBlobOptions, CommitteeInfo, ComputeBlobMetadataOptions, ConflictError, ConnectionError, ConnectionTimeoutError, DeletableConfirmationOptions, DeleteBlobOptions, type EncodeQuiltOptions, EncodingType, ExtendBlobOptions, type FileReader, GetBlobMetadataOptions, GetCertificationEpochOptions, GetSecondarySliverOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, InconsistentBlobError, InternalServerError, LegallyUnavailableError, MAINNET_WALRUS_PACKAGE_CONFIG, NoBlobMetadataReceivedError, NoBlobStatusReceivedError, NoVerifiedBlobStatusReceivedError, NotEnoughBlobConfirmationsError, NotEnoughSliversReceivedError, NotFoundError, PermissionDeniedError, ProtocolMessageCertificate, RateLimitError, ReadBlobOptions, RegisterBlobOptions, RetryableWalrusClientError, SliversForNode, StorageNode, StorageNodeAPIError, type StorageNodeClientOptions, StorageNodeError, StorageWithSizeOptions, type StoredOnNodeStatus, TESTNET_WALRUS_PACKAGE_CONFIG, TipStrategy, UnprocessableEntityError, UploadRelayConfig, UploadRelayTipConfig, UserAbortError, WalrusBlob, WalrusClient, type WalrusClientConfig, WalrusClientError, WalrusClientExtensionOptions, WalrusClientRequestOptions, WalrusFile, type WalrusOptions, type WalrusPackageConfig, WriteBlobAttributesOptions, WriteBlobBaseOptions, WriteBlobFlow, WriteBlobFlowOptions, WriteBlobFlowRegisterOptions, WriteBlobFlowRunOptions, WriteBlobFlowUploadOptions, WriteBlobOptions, WriteBlobStep, WriteBlobStepCertified, WriteBlobStepEncoded, WriteBlobStepRegistered, WriteBlobStepUploaded, WriteBlobToUploadRelayOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteFilesFlow, WriteFilesFlowOptions, WriteFilesFlowRegisterOptions, WriteFilesFlowRunOptions, WriteFilesFlowUploadOptions, WriteFilesOptions, WriteMetadataOptions, WriteQuiltOptions, WriteSliverOptions, WriteSliversToNodeOptions, blobIdFromInt, blobIdToInt, encodeQuilt, walrus };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","names":[],"sources":["../../src/storage-node/client.ts"],"
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":[],"sources":["../../src/storage-node/client.ts"],"mappings":";;;;KA+BY,KAAA,IAAS,GAAA,EAAK,WAAA,EAAa,IAAA,GAAO,WAAA,KAAgB,OAAA,CAAQ,QAAA;AAAA,KAE1D,wBAAA;EAFA;;;;;;;EAUX,KAAA,GAAQ,KAAA;EAV4D;;;;EAgBpE,OAAA;EAhB6D;;;EAqB7D,OAAA,IAAW,KAAA,EAAO,KAAA;AAAA;AAAA,KAGP,cAAA;EACX,OAAA;EACA,OAAA;EACA,OAAA,GAAU,UAAA,QAAkB,YAAA;AAAA,IACzB,IAAA,CAAK,WAAA"}
|
|
@@ -98,6 +98,20 @@ var StorageNodeClient = class {
|
|
|
98
98
|
async getPermanentBlobConfirmation({ blobId }, options) {
|
|
99
99
|
return await (await this.#request(`/v1/blobs/${blobId}/confirmation/permanent`, options)).json();
|
|
100
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Gets the storage status of a sliver at this storage node.
|
|
103
|
+
* Returns whether the sliver is stored, buffered (pending registration), or nonexistent.
|
|
104
|
+
*/
|
|
105
|
+
async getSliverStatus({ blobId, sliverPairIndex, sliverType }, options) {
|
|
106
|
+
return (await (await this.#request(`/v1/blobs/${blobId}/slivers/${sliverPairIndex}/${sliverType}/status`, options)).json()).success.data;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Gets the storage status of blob metadata at this storage node.
|
|
110
|
+
* Returns whether the metadata is stored, buffered (pending registration), or nonexistent.
|
|
111
|
+
*/
|
|
112
|
+
async getMetadataStatus({ blobId }, options) {
|
|
113
|
+
return (await (await this.#request(`/v1/blobs/${blobId}/metadata/status`, options)).json()).success.data;
|
|
114
|
+
}
|
|
101
115
|
async #request(path, options) {
|
|
102
116
|
const { nodeUrl, signal, timeout, ...init } = options;
|
|
103
117
|
if (signal?.aborted) throw new UserAbortError();
|