@arcadiasystems/morse-sdk 0.1.4 → 0.2.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/CHANGELOG.md +79 -0
- package/README.md +14 -2
- package/dist/codecs.d.ts +7 -1
- package/dist/codecs.d.ts.map +1 -1
- package/dist/codecs.js +12 -0
- package/dist/codecs.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.format.js +2 -0
- package/dist/errors.format.js.map +1 -1
- package/dist/errors.js +44 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/ops/allowlist.d.ts +79 -0
- package/dist/ops/allowlist.d.ts.map +1 -0
- package/dist/ops/allowlist.js +122 -0
- package/dist/ops/allowlist.js.map +1 -0
- package/dist/ops/file-from-bytes.d.ts +84 -0
- package/dist/ops/file-from-bytes.d.ts.map +1 -0
- package/dist/ops/file-from-bytes.js +133 -0
- package/dist/ops/file-from-bytes.js.map +1 -0
- package/dist/ops/file.d.ts +88 -0
- package/dist/ops/file.d.ts.map +1 -0
- package/dist/ops/file.js +142 -0
- package/dist/ops/file.js.map +1 -0
- package/dist/ops/index.d.ts +3 -0
- package/dist/ops/index.d.ts.map +1 -1
- package/dist/ops/index.js +3 -0
- package/dist/ops/index.js.map +1 -1
- package/dist/ptb/allowlist.d.ts +65 -0
- package/dist/ptb/allowlist.d.ts.map +1 -0
- package/dist/ptb/allowlist.js +75 -0
- package/dist/ptb/allowlist.js.map +1 -0
- package/dist/ptb/file.d.ts +58 -0
- package/dist/ptb/file.d.ts.map +1 -0
- package/dist/ptb/file.js +108 -0
- package/dist/ptb/file.js.map +1 -0
- package/dist/read/files-reader.d.ts +59 -0
- package/dist/read/files-reader.d.ts.map +1 -0
- package/dist/read/files-reader.js +247 -0
- package/dist/read/files-reader.js.map +1 -0
- package/dist/read/index.d.ts +1 -0
- package/dist/read/index.d.ts.map +1 -1
- package/dist/read/index.js +1 -0
- package/dist/read/index.js.map +1 -1
- package/dist/seal/adapter.d.ts +22 -1
- package/dist/seal/adapter.d.ts.map +1 -1
- package/dist/seal/allowlist-identity.d.ts +36 -0
- package/dist/seal/allowlist-identity.d.ts.map +1 -0
- package/dist/seal/allowlist-identity.js +81 -0
- package/dist/seal/allowlist-identity.js.map +1 -0
- package/dist/seal/default-adapter.d.ts +16 -1
- package/dist/seal/default-adapter.d.ts.map +1 -1
- package/dist/seal/default-adapter.js +56 -1
- package/dist/seal/default-adapter.js.map +1 -1
- package/dist/seal/index.d.ts +2 -1
- package/dist/seal/index.d.ts.map +1 -1
- package/dist/seal/index.js +1 -0
- package/dist/seal/index.js.map +1 -1
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/wallets/keypair-adapter.d.ts.map +1 -1
- package/dist/wallets/keypair-adapter.js +2 -0
- package/dist/wallets/keypair-adapter.js.map +1 -1
- package/package.json +1 -1
package/dist/ops/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ops/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAGN,mBAAmB,EAGnB,iBAAiB,EAGjB,kBAAkB,EAGlB,oBAAoB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAGN,gBAAgB,EAGhB,gBAAgB,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAMN,iBAAiB,EACjB,QAAQ,EACR,mBAAmB,EACnB,4BAA4B,EAG5B,WAAW,EAGX,aAAa,EACb,gBAAgB,GAEhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAIN,0BAA0B,EAC1B,iBAAiB,GAGjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGN,iBAAiB,EAGjB,iBAAiB,EAIjB,iBAAiB,GACjB,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ops/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAGN,SAAS,EAGT,eAAe,EAEf,eAAe,EAEf,YAAY,EAEZ,oBAAoB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGN,mBAAmB,EAGnB,iBAAiB,EAGjB,kBAAkB,EAGlB,oBAAoB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAGN,gBAAgB,EAGhB,gBAAgB,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAMN,iBAAiB,EACjB,QAAQ,EACR,mBAAmB,EACnB,4BAA4B,EAG5B,WAAW,EAGX,aAAa,EACb,gBAAgB,GAEhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAIN,0BAA0B,EAC1B,iBAAiB,GAGjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAIN,mBAAmB,EACnB,gBAAgB,EAEhB,UAAU,EAGV,qBAAqB,EAErB,kBAAkB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EAMN,4BAA4B,EAC5B,yBAAyB,GACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGN,iBAAiB,EAGjB,iBAAiB,EAIjB,iBAAiB,GACjB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PTB builders for `allowlist` module Move calls. Internal to the SDK;
|
|
3
|
+
* `ops/allowlist.ts` composes these into single atomic transactions.
|
|
4
|
+
*/
|
|
5
|
+
import type { Transaction, TransactionArgument, TransactionResult } from "@mysten/sui/transactions";
|
|
6
|
+
import type { AllowlistCapId, AllowlistId, PackageId, SuiAddress } from "../types.js";
|
|
7
|
+
export interface BuildNewAllowlistArgs {
|
|
8
|
+
readonly packageId: PackageId;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Add an `allowlist::new_allowlist` call. The result destructures into
|
|
13
|
+
* `[allowlist, cap]` in tuple order.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildNewAllowlist(tx: Transaction, args: BuildNewAllowlistArgs): TransactionResult;
|
|
16
|
+
export interface BuildShareAllowlistArgs {
|
|
17
|
+
readonly packageId: PackageId;
|
|
18
|
+
readonly allowlist: TransactionArgument;
|
|
19
|
+
}
|
|
20
|
+
/** Add an `allowlist::share_allowlist` call. Consumes the allowlist. */
|
|
21
|
+
export declare function buildShareAllowlist(tx: Transaction, args: BuildShareAllowlistArgs): TransactionResult;
|
|
22
|
+
export interface BuildTransferAllowlistCapArgs {
|
|
23
|
+
readonly packageId: PackageId;
|
|
24
|
+
readonly cap: TransactionArgument | AllowlistCapId;
|
|
25
|
+
readonly recipient: SuiAddress;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Add an `allowlist::transfer_cap` call. Use this instead of `tx.transferObjects`
|
|
29
|
+
* because `Cap` is key-only (no `store`); the contract's typed transfer is the
|
|
30
|
+
* only way to move it.
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildTransferAllowlistCap(tx: Transaction, args: BuildTransferAllowlistCapArgs): TransactionResult;
|
|
33
|
+
export interface BuildAddMemberArgs {
|
|
34
|
+
readonly packageId: PackageId;
|
|
35
|
+
readonly allowlistId: AllowlistId;
|
|
36
|
+
readonly capId: AllowlistCapId;
|
|
37
|
+
readonly member: SuiAddress;
|
|
38
|
+
}
|
|
39
|
+
export declare function buildAddMember(tx: Transaction, args: BuildAddMemberArgs): TransactionResult;
|
|
40
|
+
export interface BuildRemoveMemberArgs {
|
|
41
|
+
readonly packageId: PackageId;
|
|
42
|
+
readonly allowlistId: AllowlistId;
|
|
43
|
+
readonly capId: AllowlistCapId;
|
|
44
|
+
readonly member: SuiAddress;
|
|
45
|
+
}
|
|
46
|
+
export declare function buildRemoveMember(tx: Transaction, args: BuildRemoveMemberArgs): TransactionResult;
|
|
47
|
+
export interface BuildDeleteAllowlistArgs {
|
|
48
|
+
readonly packageId: PackageId;
|
|
49
|
+
readonly allowlistId: AllowlistId;
|
|
50
|
+
readonly capId: AllowlistCapId;
|
|
51
|
+
}
|
|
52
|
+
export declare function buildDeleteAllowlist(tx: Transaction, args: BuildDeleteAllowlistArgs): TransactionResult;
|
|
53
|
+
export interface BuildSealApproveAllowlistArgs {
|
|
54
|
+
readonly packageId: PackageId;
|
|
55
|
+
readonly identity: Uint8Array;
|
|
56
|
+
readonly allowlistId: AllowlistId;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Add a dry-run-only `allowlist::seal_approve` call. Seal key servers execute
|
|
60
|
+
* this against a dry-run of the PTB to decide whether to release decryption
|
|
61
|
+
* key shares; the transaction is not submitted on-chain. The `identity` bytes
|
|
62
|
+
* must be the same `SealId` used to encrypt the content.
|
|
63
|
+
*/
|
|
64
|
+
export declare function buildSealApproveAllowlist(tx: Transaction, args: BuildSealApproveAllowlistArgs): TransactionResult;
|
|
65
|
+
//# sourceMappingURL=allowlist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowlist.d.ts","sourceRoot":"","sources":["../../src/ptb/allowlist.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EACX,cAAc,EACd,WAAW,EACX,SAAS,EACT,UAAU,EACV,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,EAAE,EAAE,WAAW,EACf,IAAI,EA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AAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;CAC/B;AAED,wBAAgB,oBAAoB,CACnC,EAAE,EAAE,WAAW,EACf,IAAI,EAAE,wBAAwB,GAC5B,iBAAiB,CAKnB;AAED,MAAM,WAAW,6BAA6B;IAC7C,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CAClC;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACxC,EAAE,EAAE,WAAW,EACf,IAAI,EAAE,6BAA6B,GACjC,iBAAiB,CAQnB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PTB builders for `allowlist` module Move calls. Internal to the SDK;
|
|
3
|
+
* `ops/allowlist.ts` composes these into single atomic transactions.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Add an `allowlist::new_allowlist` call. The result destructures into
|
|
7
|
+
* `[allowlist, cap]` in tuple order.
|
|
8
|
+
*/
|
|
9
|
+
export function buildNewAllowlist(tx, args) {
|
|
10
|
+
return tx.moveCall({
|
|
11
|
+
target: `${args.packageId}::allowlist::new_allowlist`,
|
|
12
|
+
arguments: [tx.pure.string(args.name)],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/** Add an `allowlist::share_allowlist` call. Consumes the allowlist. */
|
|
16
|
+
export function buildShareAllowlist(tx, args) {
|
|
17
|
+
return tx.moveCall({
|
|
18
|
+
target: `${args.packageId}::allowlist::share_allowlist`,
|
|
19
|
+
arguments: [args.allowlist],
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Add an `allowlist::transfer_cap` call. Use this instead of `tx.transferObjects`
|
|
24
|
+
* because `Cap` is key-only (no `store`); the contract's typed transfer is the
|
|
25
|
+
* only way to move it.
|
|
26
|
+
*/
|
|
27
|
+
export function buildTransferAllowlistCap(tx, args) {
|
|
28
|
+
const cap = typeof args.cap === "string" ? tx.object(args.cap) : args.cap;
|
|
29
|
+
return tx.moveCall({
|
|
30
|
+
target: `${args.packageId}::allowlist::transfer_cap`,
|
|
31
|
+
arguments: [cap, tx.pure.address(args.recipient)],
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export function buildAddMember(tx, args) {
|
|
35
|
+
return tx.moveCall({
|
|
36
|
+
target: `${args.packageId}::allowlist::add_member`,
|
|
37
|
+
arguments: [
|
|
38
|
+
tx.object(args.allowlistId),
|
|
39
|
+
tx.object(args.capId),
|
|
40
|
+
tx.pure.address(args.member),
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function buildRemoveMember(tx, args) {
|
|
45
|
+
return tx.moveCall({
|
|
46
|
+
target: `${args.packageId}::allowlist::remove_member`,
|
|
47
|
+
arguments: [
|
|
48
|
+
tx.object(args.allowlistId),
|
|
49
|
+
tx.object(args.capId),
|
|
50
|
+
tx.pure.address(args.member),
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function buildDeleteAllowlist(tx, args) {
|
|
55
|
+
return tx.moveCall({
|
|
56
|
+
target: `${args.packageId}::allowlist::delete_allowlist`,
|
|
57
|
+
arguments: [tx.object(args.allowlistId), tx.object(args.capId)],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Add a dry-run-only `allowlist::seal_approve` call. Seal key servers execute
|
|
62
|
+
* this against a dry-run of the PTB to decide whether to release decryption
|
|
63
|
+
* key shares; the transaction is not submitted on-chain. The `identity` bytes
|
|
64
|
+
* must be the same `SealId` used to encrypt the content.
|
|
65
|
+
*/
|
|
66
|
+
export function buildSealApproveAllowlist(tx, args) {
|
|
67
|
+
return tx.moveCall({
|
|
68
|
+
target: `${args.packageId}::allowlist::seal_approve`,
|
|
69
|
+
arguments: [
|
|
70
|
+
tx.pure.vector("u8", Array.from(args.identity)),
|
|
71
|
+
tx.object(args.allowlistId),
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=allowlist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowlist.js","sourceRoot":"","sources":["../../src/ptb/allowlist.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAChC,EAAe,EACf,IAA2B;IAE3B,OAAO,EAAE,CAAC,QAAQ,CAAC;QAClB,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,4BAA4B;QACrD,SAAS,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACtC,CAAC,CAAC;AACJ,CAAC;AAOD,wEAAwE;AACxE,MAAM,UAAU,mBAAmB,CAClC,EAAe,EACf,IAA6B;IAE7B,OAAO,EAAE,CAAC,QAAQ,CAAC;QAClB,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,8BAA8B;QACvD,SAAS,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC;KAC3B,CAAC,CAAC;AACJ,CAAC;AAQD;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACxC,EAAe,EACf,IAAmC;IAEnC,MAAM,GAAG,GAAG,OAAO,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;IAC1E,OAAO,EAAE,CAAC,QAAQ,CAAC;QAClB,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,2BAA2B;QACpD,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KACjD,CAAC,CAAC;AACJ,CAAC;AASD,MAA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M,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC/C,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;SAC3B;KACD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PTB builders for `file` module Move calls. Internal to the SDK;
|
|
3
|
+
* `ops/file.ts` composes these into single atomic transactions.
|
|
4
|
+
*/
|
|
5
|
+
import type { Transaction, TransactionArgument, TransactionResult } from "@mysten/sui/transactions";
|
|
6
|
+
import type { AllowlistId, BlobObjectId, EncryptedFileId, PackageId, SuiAddress, WalrusBlobId } from "../types.js";
|
|
7
|
+
export interface BuildNewEncryptedFileArgs {
|
|
8
|
+
readonly packageId: PackageId;
|
|
9
|
+
readonly blobId: WalrusBlobId;
|
|
10
|
+
readonly blobObjectId?: BlobObjectId;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly contentType: string;
|
|
13
|
+
readonly size: bigint;
|
|
14
|
+
readonly allowlistId: AllowlistId;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Add a `file::new_encrypted_file` call. Returns the new EncryptedFile as the
|
|
18
|
+
* first result. The caller must follow with `share_file` to make it accessible
|
|
19
|
+
* from any wallet.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildNewEncryptedFile(tx: Transaction, args: BuildNewEncryptedFileArgs): TransactionResult;
|
|
22
|
+
export interface BuildNewPublicFileArgs {
|
|
23
|
+
readonly packageId: PackageId;
|
|
24
|
+
readonly blobId: WalrusBlobId;
|
|
25
|
+
readonly blobObjectId?: BlobObjectId;
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly contentType: string;
|
|
28
|
+
readonly size: bigint;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Add a `file::new_public_file` call. Returns the new EncryptedFile (the
|
|
32
|
+
* `encrypted` flag is false). Follow with `share_file`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildNewPublicFile(tx: Transaction, args: BuildNewPublicFileArgs): TransactionResult;
|
|
35
|
+
export interface BuildShareFileArgs {
|
|
36
|
+
readonly packageId: PackageId;
|
|
37
|
+
readonly file: TransactionArgument;
|
|
38
|
+
}
|
|
39
|
+
export declare function buildShareFile(tx: Transaction, args: BuildShareFileArgs): TransactionResult;
|
|
40
|
+
export interface BuildUpdateFileMetadataArgs {
|
|
41
|
+
readonly packageId: PackageId;
|
|
42
|
+
readonly fileId: EncryptedFileId;
|
|
43
|
+
readonly name: string;
|
|
44
|
+
readonly contentType: string;
|
|
45
|
+
}
|
|
46
|
+
export declare function buildUpdateFileMetadata(tx: Transaction, args: BuildUpdateFileMetadataArgs): TransactionResult;
|
|
47
|
+
export interface BuildTransferFileOwnershipArgs {
|
|
48
|
+
readonly packageId: PackageId;
|
|
49
|
+
readonly fileId: EncryptedFileId;
|
|
50
|
+
readonly newOwner: SuiAddress;
|
|
51
|
+
}
|
|
52
|
+
export declare function buildTransferFileOwnership(tx: Transaction, args: BuildTransferFileOwnershipArgs): TransactionResult;
|
|
53
|
+
export interface BuildDeleteFileArgs {
|
|
54
|
+
readonly packageId: PackageId;
|
|
55
|
+
readonly fileId: EncryptedFileId;
|
|
56
|
+
}
|
|
57
|
+
export declare function buildDeleteFile(tx: Transaction, args: BuildDeleteFileArgs): TransactionResult;
|
|
58
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/ptb/file.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,SAAS,EACT,UAAU,EACV,YAAY,EACZ,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,yBAA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,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,uBAAuB,CACtC,EAAE,EAAE,WAAW,EACf,IAAI,EAAE,2BAA2B,GAC/B,iBAAiB,CASnB;AAED,MAAM,WAAW,8BAA8B;IAC9C,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;CAC9B;AAED,wBAAgB,0BAA0B,CACzC,EAAE,EAAE,WAAW,EACf,IAAI,EAAE,8BAA8B,GAClC,iBAAiB,CAKnB;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;CACjC;AAED,wBAAgB,eAAe,CAC9B,EAAE,EAAE,WAAW,EACf,IAAI,EAAE,mBAAmB,GACvB,iBAAiB,CAKnB"}
|
package/dist/ptb/file.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PTB builders for `file` module Move calls. Internal to the SDK;
|
|
3
|
+
* `ops/file.ts` composes these into single atomic transactions.
|
|
4
|
+
*/
|
|
5
|
+
/** Canonical Sui clock shared object id. The `file::new_*` calls take it as input. */
|
|
6
|
+
const SUI_CLOCK_OBJECT_ID = "0x6";
|
|
7
|
+
/**
|
|
8
|
+
* Add a `file::new_encrypted_file` call. Returns the new EncryptedFile as the
|
|
9
|
+
* first result. The caller must follow with `share_file` to make it accessible
|
|
10
|
+
* from any wallet.
|
|
11
|
+
*/
|
|
12
|
+
export function buildNewEncryptedFile(tx, args) {
|
|
13
|
+
const blobIdBytes = walrusBlobIdToBytes(args.blobId);
|
|
14
|
+
return tx.moveCall({
|
|
15
|
+
target: `${args.packageId}::file::new_encrypted_file`,
|
|
16
|
+
arguments: [
|
|
17
|
+
tx.pure.vector("u8", Array.from(blobIdBytes)),
|
|
18
|
+
optionSomeId(tx, args.blobObjectId),
|
|
19
|
+
tx.pure.string(args.name),
|
|
20
|
+
tx.pure.string(args.contentType),
|
|
21
|
+
tx.pure.u64(args.size),
|
|
22
|
+
tx.pure.address(args.allowlistId),
|
|
23
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Add a `file::new_public_file` call. Returns the new EncryptedFile (the
|
|
29
|
+
* `encrypted` flag is false). Follow with `share_file`.
|
|
30
|
+
*/
|
|
31
|
+
export function buildNewPublicFile(tx, args) {
|
|
32
|
+
const blobIdBytes = walrusBlobIdToBytes(args.blobId);
|
|
33
|
+
return tx.moveCall({
|
|
34
|
+
target: `${args.packageId}::file::new_public_file`,
|
|
35
|
+
arguments: [
|
|
36
|
+
tx.pure.vector("u8", Array.from(blobIdBytes)),
|
|
37
|
+
optionSomeId(tx, args.blobObjectId),
|
|
38
|
+
tx.pure.string(args.name),
|
|
39
|
+
tx.pure.string(args.contentType),
|
|
40
|
+
tx.pure.u64(args.size),
|
|
41
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export function buildShareFile(tx, args) {
|
|
46
|
+
return tx.moveCall({
|
|
47
|
+
target: `${args.packageId}::file::share_file`,
|
|
48
|
+
arguments: [args.file],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export function buildUpdateFileMetadata(tx, args) {
|
|
52
|
+
return tx.moveCall({
|
|
53
|
+
target: `${args.packageId}::file::update_metadata`,
|
|
54
|
+
arguments: [
|
|
55
|
+
tx.object(args.fileId),
|
|
56
|
+
tx.pure.string(args.name),
|
|
57
|
+
tx.pure.string(args.contentType),
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export function buildTransferFileOwnership(tx, args) {
|
|
62
|
+
return tx.moveCall({
|
|
63
|
+
target: `${args.packageId}::file::transfer_ownership`,
|
|
64
|
+
arguments: [tx.object(args.fileId), tx.pure.address(args.newOwner)],
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export function buildDeleteFile(tx, args) {
|
|
68
|
+
return tx.moveCall({
|
|
69
|
+
target: `${args.packageId}::file::delete_file`,
|
|
70
|
+
arguments: [tx.object(args.fileId)],
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Walrus blob IDs are 43-char URL-safe base64 strings carrying a 32-byte
|
|
75
|
+
* content digest. The Move layer stores them as `vector<u8>`; we decode the
|
|
76
|
+
* 32 bytes here for the PTB so on-chain reads match what Walrus returns.
|
|
77
|
+
*/
|
|
78
|
+
function walrusBlobIdToBytes(blobId) {
|
|
79
|
+
const base64 = blobId
|
|
80
|
+
.replace(/-/g, "+")
|
|
81
|
+
.replace(/_/g, "/");
|
|
82
|
+
const padded = base64 + "=".repeat((4 - (base64.length % 4)) % 4);
|
|
83
|
+
const binary = atob(padded);
|
|
84
|
+
const out = new Uint8Array(binary.length);
|
|
85
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
86
|
+
out[i] = binary.charCodeAt(i);
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Build a Move `Option<ID>` argument. Sui's PTB layer does not have a native
|
|
92
|
+
* Option builder, so we go through the std::option helpers.
|
|
93
|
+
*/
|
|
94
|
+
function optionSomeId(tx, value) {
|
|
95
|
+
if (value === undefined) {
|
|
96
|
+
return tx.moveCall({
|
|
97
|
+
target: "0x1::option::none",
|
|
98
|
+
typeArguments: ["0x2::object::ID"],
|
|
99
|
+
arguments: [],
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return tx.moveCall({
|
|
103
|
+
target: "0x1::option::some",
|
|
104
|
+
typeArguments: ["0x2::object::ID"],
|
|
105
|
+
arguments: [tx.pure.id(value)],
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
//#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O,EAAE,CAAC,QAAQ,CAAC;QAClB,MAAM,EAAE,mBAAmB;QAC3B,aAAa,EAAE,CAAC,iBAAiB,CAAC;QAClC,SAAS,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;KAC9B,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RPC-backed reader for the allowlist + file modules. EncryptedFile objects
|
|
3
|
+
* are shared (every successful create_*_file flow calls share_file), so
|
|
4
|
+
* "list files owned by an address" is not exposed at the RPC layer — there
|
|
5
|
+
* is no on-chain owner field for `listOwnedObjects` to filter on. Listing
|
|
6
|
+
* accessible files requires event-based indexing; a future indexer-backed
|
|
7
|
+
* implementation will expose it through this same interface.
|
|
8
|
+
*/
|
|
9
|
+
import type { ObjectReader } from "../clients.js";
|
|
10
|
+
import type { Allowlist, AllowlistCap, AllowlistId, EncryptedFile, EncryptedFileId, PackageId, SuiAddress } from "../types.js";
|
|
11
|
+
/** Result of a single page of `listAllowlistCapsOwnedBy`. */
|
|
12
|
+
export interface AllowlistCapListPage {
|
|
13
|
+
readonly results: readonly AllowlistCap[];
|
|
14
|
+
readonly nextCursor: string | null;
|
|
15
|
+
}
|
|
16
|
+
/** Options for paginated list calls in `FilesReader`. */
|
|
17
|
+
export interface FilesListOptions {
|
|
18
|
+
readonly limit?: number;
|
|
19
|
+
readonly cursor?: string;
|
|
20
|
+
readonly signal?: AbortSignal;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Read-only access to the files domain: Allowlist objects, EncryptedFile
|
|
24
|
+
* metadata records, and the AllowlistCaps owned by a given address.
|
|
25
|
+
*
|
|
26
|
+
* Notably absent: there is no `listEncryptedFilesOwnedBy(address)` because
|
|
27
|
+
* EncryptedFile is a shared object with no on-chain owner field; `address`
|
|
28
|
+
* cannot index into anything. List the AllowlistCaps an address holds
|
|
29
|
+
* (admin access), then fetch each cap's `allowlistId` and inspect the
|
|
30
|
+
* allowlist's `members` set, or subscribe to the contract's events.
|
|
31
|
+
*/
|
|
32
|
+
export interface FilesReader {
|
|
33
|
+
getAllowlist(id: AllowlistId, signal?: AbortSignal): Promise<Allowlist>;
|
|
34
|
+
getEncryptedFile(id: EncryptedFileId, signal?: AbortSignal): Promise<EncryptedFile>;
|
|
35
|
+
listAllowlistCapsOwnedBy(address: SuiAddress, options?: FilesListOptions): Promise<AllowlistCapListPage>;
|
|
36
|
+
}
|
|
37
|
+
export declare class RpcFilesReader implements FilesReader {
|
|
38
|
+
private readonly client;
|
|
39
|
+
private readonly typePackageId;
|
|
40
|
+
constructor(client: ObjectReader, typePackageId: PackageId);
|
|
41
|
+
/**
|
|
42
|
+
* Build a reader from a morse package config. Uses `packageId` (the
|
|
43
|
+
* current published-at) for type filters because the allowlist + file
|
|
44
|
+
* modules were introduced in the v2 upgrade — Sui identifies a type by
|
|
45
|
+
* the package id where it was DEFINED, not by the package's genesis
|
|
46
|
+
* original-id. This differs from `RpcPublicationReader`, which uses
|
|
47
|
+
* `originalPackageId` because publication / collection / entry were
|
|
48
|
+
* defined in v1.
|
|
49
|
+
*/
|
|
50
|
+
static fromMorseConfig(config: {
|
|
51
|
+
packageId: PackageId;
|
|
52
|
+
originalPackageId?: PackageId;
|
|
53
|
+
}, client: ObjectReader): RpcFilesReader;
|
|
54
|
+
getAllowlist(id: AllowlistId, signal?: AbortSignal): Promise<Allowlist>;
|
|
55
|
+
getEncryptedFile(id: EncryptedFileId, signal?: AbortSignal): Promise<EncryptedFile>;
|
|
56
|
+
listAllowlistCapsOwnedBy(address: SuiAddress, options?: FilesListOptions): Promise<AllowlistCapListPage>;
|
|
57
|
+
private callClient;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=files-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files-reader.d.ts","sourceRoot":"","sources":["../../src/read/files-reader.ts"],"names":[],"mappings":"AAAA;;;;;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IAIX,YAAY,CACjB,EAAE,EAAE,WAAW,EACf,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,SAAS,CAAC;IA6Bf,gBAAgB,CACrB,EAAE,EAAE,eAAe,EACnB,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,aAAa,CAAC;IA6BnB,wBAAwB,CAC7B,OAAO,EAAE,UAAU,EACnB,OAAO,GAAE,gBAAqB,GAC5B,OAAO,CAAC,oBAAoB,CAAC;YAkBlB,UAAU;CAaxB"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RPC-backed reader for the allowlist + file modules. EncryptedFile objects
|
|
3
|
+
* are shared (every successful create_*_file flow calls share_file), so
|
|
4
|
+
* "list files owned by an address" is not exposed at the RPC layer — there
|
|
5
|
+
* is no on-chain owner field for `listOwnedObjects` to filter on. Listing
|
|
6
|
+
* accessible files requires event-based indexing; a future indexer-backed
|
|
7
|
+
* implementation will expose it through this same interface.
|
|
8
|
+
*/
|
|
9
|
+
import { toAllowlistCapId, toAllowlistId, toBlobObjectId, toEncryptedFileId, toSuiAddress, toWalrusBlobId, } from "../codecs.js";
|
|
10
|
+
import { NotFoundError, TransportError, ValidationError } from "../errors.js";
|
|
11
|
+
const DEFAULT_PAGE_LIMIT = 50;
|
|
12
|
+
export class RpcFilesReader {
|
|
13
|
+
client;
|
|
14
|
+
typePackageId;
|
|
15
|
+
constructor(client, typePackageId) {
|
|
16
|
+
this.client = client;
|
|
17
|
+
this.typePackageId = typePackageId;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Build a reader from a morse package config. Uses `packageId` (the
|
|
21
|
+
* current published-at) for type filters because the allowlist + file
|
|
22
|
+
* modules were introduced in the v2 upgrade — Sui identifies a type by
|
|
23
|
+
* the package id where it was DEFINED, not by the package's genesis
|
|
24
|
+
* original-id. This differs from `RpcPublicationReader`, which uses
|
|
25
|
+
* `originalPackageId` because publication / collection / entry were
|
|
26
|
+
* defined in v1.
|
|
27
|
+
*/
|
|
28
|
+
static fromMorseConfig(config, client) {
|
|
29
|
+
return new RpcFilesReader(client, config.packageId);
|
|
30
|
+
}
|
|
31
|
+
async getAllowlist(id, signal) {
|
|
32
|
+
const validated = toAllowlistId(id);
|
|
33
|
+
let response;
|
|
34
|
+
try {
|
|
35
|
+
response = await this.callClient("getObject", () => this.client.getObject({
|
|
36
|
+
objectId: validated,
|
|
37
|
+
include: { json: true },
|
|
38
|
+
...(signal === undefined ? {} : { signal }),
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error instanceof TransportError &&
|
|
43
|
+
isObjectNotFoundError(error.cause, validated)) {
|
|
44
|
+
throw new NotFoundError("allowlist", validated, {
|
|
45
|
+
cause: error.cause,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
const object = response.object;
|
|
51
|
+
if (!object) {
|
|
52
|
+
throw new NotFoundError("allowlist", validated);
|
|
53
|
+
}
|
|
54
|
+
return parseAllowlist(object);
|
|
55
|
+
}
|
|
56
|
+
async getEncryptedFile(id, signal) {
|
|
57
|
+
const validated = toEncryptedFileId(id);
|
|
58
|
+
let response;
|
|
59
|
+
try {
|
|
60
|
+
response = await this.callClient("getObject", () => this.client.getObject({
|
|
61
|
+
objectId: validated,
|
|
62
|
+
include: { json: true },
|
|
63
|
+
...(signal === undefined ? {} : { signal }),
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (error instanceof TransportError &&
|
|
68
|
+
isObjectNotFoundError(error.cause, validated)) {
|
|
69
|
+
throw new NotFoundError("encrypted-file", validated, {
|
|
70
|
+
cause: error.cause,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
const object = response.object;
|
|
76
|
+
if (!object) {
|
|
77
|
+
throw new NotFoundError("encrypted-file", validated);
|
|
78
|
+
}
|
|
79
|
+
return parseEncryptedFile(object);
|
|
80
|
+
}
|
|
81
|
+
async listAllowlistCapsOwnedBy(address, options = {}) {
|
|
82
|
+
const validated = toSuiAddress(address);
|
|
83
|
+
const { limit = DEFAULT_PAGE_LIMIT, cursor, signal } = options;
|
|
84
|
+
const capType = `${this.typePackageId}::allowlist::Cap`;
|
|
85
|
+
const response = await this.callClient("listOwnedObjects", () => this.client.listOwnedObjects({
|
|
86
|
+
owner: validated,
|
|
87
|
+
type: capType,
|
|
88
|
+
limit,
|
|
89
|
+
cursor: cursor ?? null,
|
|
90
|
+
include: { json: true },
|
|
91
|
+
...(signal === undefined ? {} : { signal }),
|
|
92
|
+
}));
|
|
93
|
+
const results = response.objects.map((object) => parseAllowlistCap(object));
|
|
94
|
+
return { results, nextCursor: response.cursor };
|
|
95
|
+
}
|
|
96
|
+
async callClient(operation, call) {
|
|
97
|
+
try {
|
|
98
|
+
return await call();
|
|
99
|
+
}
|
|
100
|
+
catch (cause) {
|
|
101
|
+
throw new TransportError(`${operation} failed`, {
|
|
102
|
+
cause,
|
|
103
|
+
operation: `sui.${operation}`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function parseAllowlist(object) {
|
|
109
|
+
const json = object.json;
|
|
110
|
+
if (!json || typeof json !== "object") {
|
|
111
|
+
throw new NotFoundError("allowlist", object.objectId);
|
|
112
|
+
}
|
|
113
|
+
const record = json;
|
|
114
|
+
const name = readString(record, "name", "allowlist.name");
|
|
115
|
+
const members = readMembers(record);
|
|
116
|
+
return {
|
|
117
|
+
id: toAllowlistId(object.objectId),
|
|
118
|
+
name,
|
|
119
|
+
members,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function parseAllowlistCap(object) {
|
|
123
|
+
const json = object.json;
|
|
124
|
+
if (!json || typeof json !== "object") {
|
|
125
|
+
throw new NotFoundError("allowlist", object.objectId);
|
|
126
|
+
}
|
|
127
|
+
const record = json;
|
|
128
|
+
const allowlistIdField = record.allowlist_id;
|
|
129
|
+
if (typeof allowlistIdField !== "string") {
|
|
130
|
+
throw new ValidationError("allowlist::Cap.allowlist_id missing or not a string", "cap.allowlist_id");
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
id: toAllowlistCapId(object.objectId),
|
|
134
|
+
allowlistId: toAllowlistId(allowlistIdField),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function parseEncryptedFile(object) {
|
|
138
|
+
const json = object.json;
|
|
139
|
+
if (!json || typeof json !== "object") {
|
|
140
|
+
throw new NotFoundError("encrypted-file", object.objectId);
|
|
141
|
+
}
|
|
142
|
+
const record = json;
|
|
143
|
+
const owner = toSuiAddress(readString(record, "owner", "file.owner"));
|
|
144
|
+
// Sui gRPC serializes vector<u8> either as a base64 string (standard JSON
|
|
145
|
+
// representation) or as a number array (older RPC variants). Accept both.
|
|
146
|
+
const blobId = toWalrusBlobId(parseBlobIdField(record.blob_id));
|
|
147
|
+
const blobObjectId = readOptionalString(record, "blob_object_id");
|
|
148
|
+
const name = readString(record, "name", "file.name");
|
|
149
|
+
const contentType = readString(record, "content_type", "file.content_type");
|
|
150
|
+
const size = readSafeIntFromBig(record, "size", "file.size");
|
|
151
|
+
const encrypted = record.encrypted === true;
|
|
152
|
+
const allowlistIdRaw = readOptionalString(record, "allowlist_id");
|
|
153
|
+
const createdAtMs = readSafeIntFromBig(record, "created_at_ms", "file.created_at_ms");
|
|
154
|
+
return {
|
|
155
|
+
id: toEncryptedFileId(object.objectId),
|
|
156
|
+
owner,
|
|
157
|
+
blobId,
|
|
158
|
+
blobObjectId: blobObjectId === null ? null : toBlobObjectId(blobObjectId),
|
|
159
|
+
name,
|
|
160
|
+
contentType,
|
|
161
|
+
size,
|
|
162
|
+
encrypted,
|
|
163
|
+
allowlistId: allowlistIdRaw === null ? null : toAllowlistId(allowlistIdRaw),
|
|
164
|
+
createdAtMs,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function readMembers(record) {
|
|
168
|
+
const raw = record.members;
|
|
169
|
+
if (!raw || typeof raw !== "object") {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
const contents = raw.contents;
|
|
173
|
+
if (!Array.isArray(contents)) {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
const out = [];
|
|
177
|
+
for (const entry of contents) {
|
|
178
|
+
if (typeof entry === "string") {
|
|
179
|
+
out.push(toSuiAddress(entry));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
function readString(record, field, errorField) {
|
|
185
|
+
const value = record[field];
|
|
186
|
+
if (typeof value !== "string") {
|
|
187
|
+
throw new ValidationError(`${errorField} missing or not a string`, errorField);
|
|
188
|
+
}
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
function readOptionalString(record, field) {
|
|
192
|
+
const value = record[field];
|
|
193
|
+
if (value === null || value === undefined) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
return typeof value === "string" ? value : null;
|
|
197
|
+
}
|
|
198
|
+
function readSafeIntFromBig(record, field, errorField) {
|
|
199
|
+
const value = record[field];
|
|
200
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
|
201
|
+
throw new ValidationError(`${errorField} missing or not a number`, errorField);
|
|
202
|
+
}
|
|
203
|
+
const big = BigInt(value);
|
|
204
|
+
if (big > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
205
|
+
throw new ValidationError(`${errorField} exceeds Number.MAX_SAFE_INTEGER`, errorField);
|
|
206
|
+
}
|
|
207
|
+
return Number(big);
|
|
208
|
+
}
|
|
209
|
+
function bytesArrayToBase64Url(bytes) {
|
|
210
|
+
let binary = "";
|
|
211
|
+
for (const byte of bytes) {
|
|
212
|
+
binary += String.fromCharCode(byte);
|
|
213
|
+
}
|
|
214
|
+
const b64 = btoa(binary);
|
|
215
|
+
return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Sui gRPC may serialize `vector<u8>` as:
|
|
219
|
+
* - a base64 string (standard JSON encoding)
|
|
220
|
+
* - a base64URL string (some RPC variants)
|
|
221
|
+
* - an array of numbers (older variants, or when the field is small)
|
|
222
|
+
* Return the URL-safe-base64 form Walrus uses for blob ids regardless of input shape.
|
|
223
|
+
*/
|
|
224
|
+
function parseBlobIdField(raw) {
|
|
225
|
+
if (Array.isArray(raw)) {
|
|
226
|
+
return bytesArrayToBase64Url(raw);
|
|
227
|
+
}
|
|
228
|
+
if (typeof raw !== "string") {
|
|
229
|
+
throw new ValidationError("file.blob_id must be a byte array or base64 string", "file.blob_id");
|
|
230
|
+
}
|
|
231
|
+
// Already URL-safe? Strip padding and return.
|
|
232
|
+
if (/^[A-Za-z0-9_-]+={0,2}$/.test(raw)) {
|
|
233
|
+
return raw.replace(/=+$/g, "");
|
|
234
|
+
}
|
|
235
|
+
// Standard base64 with + and / — convert to URL-safe.
|
|
236
|
+
if (/^[A-Za-z0-9+/]+={0,2}$/.test(raw)) {
|
|
237
|
+
return raw.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
238
|
+
}
|
|
239
|
+
throw new ValidationError("file.blob_id is not a recognized base64 string", "file.blob_id");
|
|
240
|
+
}
|
|
241
|
+
function isObjectNotFoundError(cause, _objectId) {
|
|
242
|
+
if (!(cause instanceof Error)) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
return /not found|NotFound|object.*not.*exist/i.test(cause.message);
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=files-reader.js.map
|