@arcadiasystems/morse-sdk 0.1.4 → 0.3.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 +118 -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 +11 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +11 -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-events.d.ts +87 -0
- package/dist/read/files-events.d.ts.map +1 -0
- package/dist/read/files-events.js +194 -0
- package/dist/read/files-events.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 +2 -0
- package/dist/read/index.d.ts.map +1 -1
- package/dist/read/index.js +2 -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 +85 -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
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level allowlist ops: build a PTB, sign and execute via the wallet
|
|
3
|
+
* adapter, parse the receipt into a typed result.
|
|
4
|
+
*/
|
|
5
|
+
import type { MorsePackageConfig } from "../config.js";
|
|
6
|
+
import type { AllowlistCapId, AllowlistId, SuiAddress } from "../types.js";
|
|
7
|
+
import type { WalletAdapter } from "../wallets/adapter.js";
|
|
8
|
+
export interface CreateAllowlistArgs {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
export interface CreateAllowlistResult {
|
|
13
|
+
readonly digest: string;
|
|
14
|
+
readonly gasUsedMist: bigint;
|
|
15
|
+
readonly allowlistId: AllowlistId;
|
|
16
|
+
readonly capId: AllowlistCapId;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create an allowlist, share it, and transfer the admin Cap to `adapter.address`
|
|
20
|
+
* in one atomic PTB. The caller can immediately use the returned `capId`
|
|
21
|
+
* for member ops.
|
|
22
|
+
*
|
|
23
|
+
* @throws {ValidationError} If `name` is empty or exceeds 256 chars.
|
|
24
|
+
* @throws {ContractAbortError} On Move abort.
|
|
25
|
+
* @throws {TransportError} On RPC, network, or response-parsing failure.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createAllowlist(adapter: WalletAdapter, config: MorsePackageConfig, args: CreateAllowlistArgs): Promise<CreateAllowlistResult>;
|
|
28
|
+
export interface AddMemberArgs {
|
|
29
|
+
readonly allowlistId: AllowlistId;
|
|
30
|
+
readonly capId: AllowlistCapId;
|
|
31
|
+
readonly member: SuiAddress;
|
|
32
|
+
readonly signal?: AbortSignal;
|
|
33
|
+
}
|
|
34
|
+
export interface AllowlistOpResult {
|
|
35
|
+
readonly digest: string;
|
|
36
|
+
readonly gasUsedMist: bigint;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Add an address to the allowlist. Idempotent: adding an existing member
|
|
40
|
+
* aborts with `EMemberAlreadyPresent`.
|
|
41
|
+
*
|
|
42
|
+
* @throws {ContractAbortError} On Move abort (wrong cap, duplicate member).
|
|
43
|
+
* @throws {TransportError} On RPC, network, or response-parsing failure.
|
|
44
|
+
*/
|
|
45
|
+
export declare function addMember(adapter: WalletAdapter, config: MorsePackageConfig, args: AddMemberArgs): Promise<AllowlistOpResult>;
|
|
46
|
+
export interface RemoveMemberArgs {
|
|
47
|
+
readonly allowlistId: AllowlistId;
|
|
48
|
+
readonly capId: AllowlistCapId;
|
|
49
|
+
readonly member: SuiAddress;
|
|
50
|
+
readonly signal?: AbortSignal;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Remove an address from the allowlist. Aborts with `EMemberNotPresent` if
|
|
54
|
+
* the address is not a member.
|
|
55
|
+
*/
|
|
56
|
+
export declare function removeMember(adapter: WalletAdapter, config: MorsePackageConfig, args: RemoveMemberArgs): Promise<AllowlistOpResult>;
|
|
57
|
+
export interface TransferAllowlistCapArgs {
|
|
58
|
+
readonly capId: AllowlistCapId;
|
|
59
|
+
readonly recipient: SuiAddress;
|
|
60
|
+
readonly signal?: AbortSignal;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Transfer the admin Cap to a new address. The new holder gains full admin
|
|
64
|
+
* rights; the previous holder loses them.
|
|
65
|
+
*/
|
|
66
|
+
export declare function transferAllowlistCap(adapter: WalletAdapter, config: MorsePackageConfig, args: TransferAllowlistCapArgs): Promise<AllowlistOpResult>;
|
|
67
|
+
export interface DeleteAllowlistArgs {
|
|
68
|
+
readonly allowlistId: AllowlistId;
|
|
69
|
+
readonly capId: AllowlistCapId;
|
|
70
|
+
readonly signal?: AbortSignal;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Delete an allowlist. Any `EncryptedFile` still referencing this allowlist
|
|
74
|
+
* becomes unusable for decryption (`seal_approve` dry-run will fail with
|
|
75
|
+
* `ESealInvalidId` because the allowlist object no longer exists). Delete
|
|
76
|
+
* dependent files first or migrate them before deleting the allowlist.
|
|
77
|
+
*/
|
|
78
|
+
export declare function deleteAllowlist(adapter: WalletAdapter, config: MorsePackageConfig, args: DeleteAllowlistArgs): Promise<AllowlistOpResult>;
|
|
79
|
+
//# sourceMappingURL=allowlist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowlist.d.ts","sourceRoot":"","sources":["../../src/ops/allowlist.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,KAAK,EAAE,kBAAkB,EAAE,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AAc,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAsB,YAAY,CACjC,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EAAE,gBAAgB,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAU5B;AAED,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EAAE,wBAAwB,GAC5B,OAAO,CAAC,iBAAiB,CAAC,CAS5B;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACpC,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EAAE,mBAAmB,GACvB,OAAO,CAAC,iBAAiB,CAAC,CAS5B"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level allowlist ops: build a PTB, sign and execute via the wallet
|
|
3
|
+
* adapter, parse the receipt into a typed result.
|
|
4
|
+
*/
|
|
5
|
+
import { Transaction, } from "@mysten/sui/transactions";
|
|
6
|
+
import { toAllowlistCapId, toAllowlistId } from "../codecs.js";
|
|
7
|
+
import { ValidationError } from "../errors.js";
|
|
8
|
+
import { buildAddMember, buildDeleteAllowlist, buildNewAllowlist, buildRemoveMember, buildShareAllowlist, buildTransferAllowlistCap, } from "../ptb/allowlist.js";
|
|
9
|
+
import { findCreatedId } from "./internal.js";
|
|
10
|
+
const MAX_ALLOWLIST_NAME_LENGTH = 256;
|
|
11
|
+
/**
|
|
12
|
+
* Create an allowlist, share it, and transfer the admin Cap to `adapter.address`
|
|
13
|
+
* in one atomic PTB. The caller can immediately use the returned `capId`
|
|
14
|
+
* for member ops.
|
|
15
|
+
*
|
|
16
|
+
* @throws {ValidationError} If `name` is empty or exceeds 256 chars.
|
|
17
|
+
* @throws {ContractAbortError} On Move abort.
|
|
18
|
+
* @throws {TransportError} On RPC, network, or response-parsing failure.
|
|
19
|
+
*/
|
|
20
|
+
export async function createAllowlist(adapter, config, args) {
|
|
21
|
+
validateAllowlistName(args.name);
|
|
22
|
+
const tx = new Transaction();
|
|
23
|
+
const created = buildNewAllowlist(tx, {
|
|
24
|
+
packageId: config.packageId,
|
|
25
|
+
name: args.name,
|
|
26
|
+
});
|
|
27
|
+
const allowlistArg = created[0];
|
|
28
|
+
const capArg = created[1];
|
|
29
|
+
buildShareAllowlist(tx, {
|
|
30
|
+
packageId: config.packageId,
|
|
31
|
+
allowlist: allowlistArg,
|
|
32
|
+
});
|
|
33
|
+
buildTransferAllowlistCap(tx, {
|
|
34
|
+
packageId: config.packageId,
|
|
35
|
+
cap: capArg,
|
|
36
|
+
recipient: adapter.address,
|
|
37
|
+
});
|
|
38
|
+
const receipt = await adapter.signAndExecuteTransaction(tx, args.signal);
|
|
39
|
+
// Sui types are identified by the package id where the type was DEFINED.
|
|
40
|
+
// allowlist::Allowlist was introduced in the v2 upgrade, so its type
|
|
41
|
+
// identity is rooted at config.packageId (v2 published-at), not at
|
|
42
|
+
// originalPackageId (v1 genesis, used by publication / collection / entry).
|
|
43
|
+
const typePrefix = config.packageId;
|
|
44
|
+
return {
|
|
45
|
+
digest: receipt.digest,
|
|
46
|
+
gasUsedMist: receipt.gasUsedMist,
|
|
47
|
+
allowlistId: toAllowlistId(findCreatedId(receipt, `${typePrefix}::allowlist::Allowlist`)),
|
|
48
|
+
capId: toAllowlistCapId(findCreatedId(receipt, `${typePrefix}::allowlist::Cap`)),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Add an address to the allowlist. Idempotent: adding an existing member
|
|
53
|
+
* aborts with `EMemberAlreadyPresent`.
|
|
54
|
+
*
|
|
55
|
+
* @throws {ContractAbortError} On Move abort (wrong cap, duplicate member).
|
|
56
|
+
* @throws {TransportError} On RPC, network, or response-parsing failure.
|
|
57
|
+
*/
|
|
58
|
+
export async function addMember(adapter, config, args) {
|
|
59
|
+
const tx = new Transaction();
|
|
60
|
+
buildAddMember(tx, {
|
|
61
|
+
packageId: config.packageId,
|
|
62
|
+
allowlistId: args.allowlistId,
|
|
63
|
+
capId: args.capId,
|
|
64
|
+
member: args.member,
|
|
65
|
+
});
|
|
66
|
+
const receipt = await adapter.signAndExecuteTransaction(tx, args.signal);
|
|
67
|
+
return { digest: receipt.digest, gasUsedMist: receipt.gasUsedMist };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Remove an address from the allowlist. Aborts with `EMemberNotPresent` if
|
|
71
|
+
* the address is not a member.
|
|
72
|
+
*/
|
|
73
|
+
export async function removeMember(adapter, config, args) {
|
|
74
|
+
const tx = new Transaction();
|
|
75
|
+
buildRemoveMember(tx, {
|
|
76
|
+
packageId: config.packageId,
|
|
77
|
+
allowlistId: args.allowlistId,
|
|
78
|
+
capId: args.capId,
|
|
79
|
+
member: args.member,
|
|
80
|
+
});
|
|
81
|
+
const receipt = await adapter.signAndExecuteTransaction(tx, args.signal);
|
|
82
|
+
return { digest: receipt.digest, gasUsedMist: receipt.gasUsedMist };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Transfer the admin Cap to a new address. The new holder gains full admin
|
|
86
|
+
* rights; the previous holder loses them.
|
|
87
|
+
*/
|
|
88
|
+
export async function transferAllowlistCap(adapter, config, args) {
|
|
89
|
+
const tx = new Transaction();
|
|
90
|
+
buildTransferAllowlistCap(tx, {
|
|
91
|
+
packageId: config.packageId,
|
|
92
|
+
cap: args.capId,
|
|
93
|
+
recipient: args.recipient,
|
|
94
|
+
});
|
|
95
|
+
const receipt = await adapter.signAndExecuteTransaction(tx, args.signal);
|
|
96
|
+
return { digest: receipt.digest, gasUsedMist: receipt.gasUsedMist };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Delete an allowlist. Any `EncryptedFile` still referencing this allowlist
|
|
100
|
+
* becomes unusable for decryption (`seal_approve` dry-run will fail with
|
|
101
|
+
* `ESealInvalidId` because the allowlist object no longer exists). Delete
|
|
102
|
+
* dependent files first or migrate them before deleting the allowlist.
|
|
103
|
+
*/
|
|
104
|
+
export async function deleteAllowlist(adapter, config, args) {
|
|
105
|
+
const tx = new Transaction();
|
|
106
|
+
buildDeleteAllowlist(tx, {
|
|
107
|
+
packageId: config.packageId,
|
|
108
|
+
allowlistId: args.allowlistId,
|
|
109
|
+
capId: args.capId,
|
|
110
|
+
});
|
|
111
|
+
const receipt = await adapter.signAndExecuteTransaction(tx, args.signal);
|
|
112
|
+
return { digest: receipt.digest, gasUsedMist: receipt.gasUsedMist };
|
|
113
|
+
}
|
|
114
|
+
function validateAllowlistName(name) {
|
|
115
|
+
if (name.length === 0) {
|
|
116
|
+
throw new ValidationError("Allowlist name cannot be empty", "name");
|
|
117
|
+
}
|
|
118
|
+
if (name.length > MAX_ALLOWLIST_NAME_LENGTH) {
|
|
119
|
+
throw new ValidationError(`Allowlist name exceeds ${MAX_ALLOWLIST_NAME_LENGTH} chars`, "name");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=allowlist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowlist.js","sourceRoot":"","sources":["../../src/ops/allowlist.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,WAAW,GAEX,MAAM,0BAA0B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KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,eAAe,CAAC,gCAAgC,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,yBAAyB,EAAE,CAAC;QAC7C,MAAM,IAAI,eAAe,CACxB,0BAA0B,yBAAyB,QAAQ,EAC3D,MAAM,CACN,CAAC;IACH,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level "upload + register" flows for the file module. Combines Walrus
|
|
3
|
+
* upload with on-chain metadata registration in a single PTB so the user
|
|
4
|
+
* sees one signing popup for the storage step plus one for the on-chain
|
|
5
|
+
* write (rather than three separate popups).
|
|
6
|
+
*
|
|
7
|
+
* Mirrors `entry-from-bytes.ts`'s shape but targets `file::new_encrypted_file`
|
|
8
|
+
* / `file::new_public_file` instead of `add_entry_to_collection`.
|
|
9
|
+
*/
|
|
10
|
+
import type { MorsePackageConfig } from "../config.js";
|
|
11
|
+
import type { SealAdapter } from "../seal/adapter.js";
|
|
12
|
+
import type { AllowlistId, BlobObjectId, EncryptedFileId, SealId, WalrusBlobId } from "../types.js";
|
|
13
|
+
import type { WalletAdapter } from "../wallets/adapter.js";
|
|
14
|
+
import type { UploadBlobOptions, WalrusFlowCapable, WalrusWriteAdapter } from "../walrus/adapter.js";
|
|
15
|
+
export type FileUploadProgressEvent = {
|
|
16
|
+
readonly phase: "encrypting";
|
|
17
|
+
} | {
|
|
18
|
+
readonly phase: "uploading";
|
|
19
|
+
} | {
|
|
20
|
+
readonly phase: "submitting";
|
|
21
|
+
} | {
|
|
22
|
+
readonly phase: "complete";
|
|
23
|
+
};
|
|
24
|
+
export type FileUploadProgressCallback = (event: FileUploadProgressEvent) => void;
|
|
25
|
+
export interface UploadFileResult {
|
|
26
|
+
readonly digest: string;
|
|
27
|
+
readonly gasUsedMist: bigint;
|
|
28
|
+
readonly fileId: EncryptedFileId;
|
|
29
|
+
readonly blobId: WalrusBlobId;
|
|
30
|
+
readonly blobObjectId: BlobObjectId;
|
|
31
|
+
}
|
|
32
|
+
export interface UploadEncryptedFileFromBytesArgs {
|
|
33
|
+
readonly walrus: WalrusWriteAdapter & WalrusFlowCapable;
|
|
34
|
+
readonly seal: SealAdapter;
|
|
35
|
+
readonly allowlistId: AllowlistId;
|
|
36
|
+
/** Caller-supplied Seal identity. Must derive from `buildAllowlistSealId(allowlistId, nonce)`. */
|
|
37
|
+
readonly sealId: SealId;
|
|
38
|
+
readonly plaintext: Uint8Array;
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly contentType: string;
|
|
41
|
+
readonly upload: UploadBlobOptions;
|
|
42
|
+
readonly signal?: AbortSignal;
|
|
43
|
+
readonly onProgress?: FileUploadProgressCallback;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Encrypt `plaintext` via Seal under the allowlist's identity, upload the
|
|
47
|
+
* ciphertext to Walrus, and register an `EncryptedFile` metadata record in
|
|
48
|
+
* one combined transaction. Two wallet popups: register_blob, then
|
|
49
|
+
* certify_blob + new_encrypted_file + share_file.
|
|
50
|
+
*
|
|
51
|
+
* The caller supplies `sealId` rather than having the flow construct it,
|
|
52
|
+
* so the decryption side can use the same identity bytes without an
|
|
53
|
+
* implicit shared-secret round-trip. Build via:
|
|
54
|
+
*
|
|
55
|
+
* const nonce = crypto.getRandomValues(new Uint8Array(16));
|
|
56
|
+
* const sealId = buildAllowlistSealId(allowlistId, nonce);
|
|
57
|
+
*
|
|
58
|
+
* Reuse the same nonce-derived sealId when decrypting (consumers can
|
|
59
|
+
* recover it by reading the encrypted ciphertext header — Seal stores the
|
|
60
|
+
* identity in the ciphertext envelope).
|
|
61
|
+
*
|
|
62
|
+
* @throws {SealError} If encryption fails (no popup yet).
|
|
63
|
+
* @throws {UncertifiedBlobError} If the combined popup fails after upload
|
|
64
|
+
* succeeded. The blob is on Walrus but uncertified; retry the full flow.
|
|
65
|
+
* @throws {ContractAbortError} On Move abort during simulation.
|
|
66
|
+
* @throws {TransportError} On RPC, network, or pre-upload failure.
|
|
67
|
+
*/
|
|
68
|
+
export declare function uploadEncryptedFileFromBytes(adapter: WalletAdapter, config: MorsePackageConfig, args: UploadEncryptedFileFromBytesArgs): Promise<UploadFileResult>;
|
|
69
|
+
export interface UploadPublicFileFromBytesArgs {
|
|
70
|
+
readonly walrus: WalrusWriteAdapter & WalrusFlowCapable;
|
|
71
|
+
readonly bytes: Uint8Array;
|
|
72
|
+
readonly name: string;
|
|
73
|
+
readonly contentType: string;
|
|
74
|
+
readonly upload: UploadBlobOptions;
|
|
75
|
+
readonly signal?: AbortSignal;
|
|
76
|
+
readonly onProgress?: FileUploadProgressCallback;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Upload `bytes` to Walrus unencrypted and register a public `EncryptedFile`
|
|
80
|
+
* metadata record (`encrypted: false`, `allowlistId: null`) in one combined
|
|
81
|
+
* transaction. Two wallet popups; no Seal involvement.
|
|
82
|
+
*/
|
|
83
|
+
export declare function uploadPublicFileFromBytes(adapter: WalletAdapter, config: MorsePackageConfig, args: UploadPublicFileFromBytesArgs): Promise<UploadFileResult>;
|
|
84
|
+
//# sourceMappingURL=file-from-bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-from-bytes.d.ts","sourceRoot":"","sources":["../../src/ops/file-from-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAOvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,MAAM,EACN,YAAY,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EACX,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,E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AAkB,EAC1B,IAAI,EAAE,gCAAgC,GACpC,OAAO,CAAC,gBAAgB,CAAC,CAiD3B;AAID,MAAM,WAAW,6BAA6B;IAC7C,QAAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,iBAAiB,CAAC;IACxD,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,0BAA0B,CAAC;CACjD;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EAAE,6BAA6B,GACjC,OAAO,CAAC,gBAAgB,CAAC,CA2C3B"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level "upload + register" flows for the file module. Combines Walrus
|
|
3
|
+
* upload with on-chain metadata registration in a single PTB so the user
|
|
4
|
+
* sees one signing popup for the storage step plus one for the on-chain
|
|
5
|
+
* write (rather than three separate popups).
|
|
6
|
+
*
|
|
7
|
+
* Mirrors `entry-from-bytes.ts`'s shape but targets `file::new_encrypted_file`
|
|
8
|
+
* / `file::new_public_file` instead of `add_entry_to_collection`.
|
|
9
|
+
*/
|
|
10
|
+
import { toEncryptedFileId } from "../codecs.js";
|
|
11
|
+
import { TransportError, UncertifiedBlobError } from "../errors.js";
|
|
12
|
+
import { buildNewEncryptedFile, buildNewPublicFile, buildShareFile, } from "../ptb/file.js";
|
|
13
|
+
import { isWalrusFlowCapable } from "../walrus/adapter.js";
|
|
14
|
+
import { findCreatedId } from "./internal.js";
|
|
15
|
+
/**
|
|
16
|
+
* Encrypt `plaintext` via Seal under the allowlist's identity, upload the
|
|
17
|
+
* ciphertext to Walrus, and register an `EncryptedFile` metadata record in
|
|
18
|
+
* one combined transaction. Two wallet popups: register_blob, then
|
|
19
|
+
* certify_blob + new_encrypted_file + share_file.
|
|
20
|
+
*
|
|
21
|
+
* The caller supplies `sealId` rather than having the flow construct it,
|
|
22
|
+
* so the decryption side can use the same identity bytes without an
|
|
23
|
+
* implicit shared-secret round-trip. Build via:
|
|
24
|
+
*
|
|
25
|
+
* const nonce = crypto.getRandomValues(new Uint8Array(16));
|
|
26
|
+
* const sealId = buildAllowlistSealId(allowlistId, nonce);
|
|
27
|
+
*
|
|
28
|
+
* Reuse the same nonce-derived sealId when decrypting (consumers can
|
|
29
|
+
* recover it by reading the encrypted ciphertext header — Seal stores the
|
|
30
|
+
* identity in the ciphertext envelope).
|
|
31
|
+
*
|
|
32
|
+
* @throws {SealError} If encryption fails (no popup yet).
|
|
33
|
+
* @throws {UncertifiedBlobError} If the combined popup fails after upload
|
|
34
|
+
* succeeded. The blob is on Walrus but uncertified; retry the full flow.
|
|
35
|
+
* @throws {ContractAbortError} On Move abort during simulation.
|
|
36
|
+
* @throws {TransportError} On RPC, network, or pre-upload failure.
|
|
37
|
+
*/
|
|
38
|
+
export async function uploadEncryptedFileFromBytes(adapter, config, args) {
|
|
39
|
+
assertFlowCapable(args.walrus);
|
|
40
|
+
args.onProgress?.({ phase: "encrypting" });
|
|
41
|
+
const { ciphertext } = await args.seal.encrypt(args.plaintext, {
|
|
42
|
+
sealId: args.sealId,
|
|
43
|
+
});
|
|
44
|
+
args.onProgress?.({ phase: "uploading" });
|
|
45
|
+
const upload = await args.walrus.startBlobUpload(ciphertext, args.upload);
|
|
46
|
+
try {
|
|
47
|
+
const tx = upload.certifyTransaction;
|
|
48
|
+
const created = buildNewEncryptedFile(tx, {
|
|
49
|
+
packageId: config.packageId,
|
|
50
|
+
blobId: upload.blobId,
|
|
51
|
+
blobObjectId: upload.blobObjectId,
|
|
52
|
+
name: args.name,
|
|
53
|
+
contentType: args.contentType,
|
|
54
|
+
size: BigInt(args.plaintext.length),
|
|
55
|
+
allowlistId: args.allowlistId,
|
|
56
|
+
});
|
|
57
|
+
buildShareFile(tx, {
|
|
58
|
+
packageId: config.packageId,
|
|
59
|
+
file: created,
|
|
60
|
+
});
|
|
61
|
+
args.onProgress?.({ phase: "submitting" });
|
|
62
|
+
const receipt = await adapter.signAndExecuteTransaction(tx, args.signal);
|
|
63
|
+
// See ops/allowlist.ts: file::EncryptedFile was introduced in v2.
|
|
64
|
+
const typePrefix = config.packageId;
|
|
65
|
+
const fileId = toEncryptedFileId(findCreatedId(receipt, `${typePrefix}::file::EncryptedFile`));
|
|
66
|
+
args.onProgress?.({ phase: "complete" });
|
|
67
|
+
return {
|
|
68
|
+
digest: receipt.digest,
|
|
69
|
+
gasUsedMist: receipt.gasUsedMist,
|
|
70
|
+
fileId,
|
|
71
|
+
blobId: upload.blobId,
|
|
72
|
+
blobObjectId: upload.blobObjectId,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
catch (cause) {
|
|
76
|
+
if (cause instanceof UncertifiedBlobError)
|
|
77
|
+
throw cause;
|
|
78
|
+
throw new UncertifiedBlobError(upload.blobObjectId, upload.blobId, {
|
|
79
|
+
cause,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Upload `bytes` to Walrus unencrypted and register a public `EncryptedFile`
|
|
85
|
+
* metadata record (`encrypted: false`, `allowlistId: null`) in one combined
|
|
86
|
+
* transaction. Two wallet popups; no Seal involvement.
|
|
87
|
+
*/
|
|
88
|
+
export async function uploadPublicFileFromBytes(adapter, config, args) {
|
|
89
|
+
assertFlowCapable(args.walrus);
|
|
90
|
+
args.onProgress?.({ phase: "uploading" });
|
|
91
|
+
const upload = await args.walrus.startBlobUpload(args.bytes, args.upload);
|
|
92
|
+
try {
|
|
93
|
+
const tx = upload.certifyTransaction;
|
|
94
|
+
const created = buildNewPublicFile(tx, {
|
|
95
|
+
packageId: config.packageId,
|
|
96
|
+
blobId: upload.blobId,
|
|
97
|
+
blobObjectId: upload.blobObjectId,
|
|
98
|
+
name: args.name,
|
|
99
|
+
contentType: args.contentType,
|
|
100
|
+
size: BigInt(args.bytes.length),
|
|
101
|
+
});
|
|
102
|
+
buildShareFile(tx, {
|
|
103
|
+
packageId: config.packageId,
|
|
104
|
+
file: created,
|
|
105
|
+
});
|
|
106
|
+
args.onProgress?.({ phase: "submitting" });
|
|
107
|
+
const receipt = await adapter.signAndExecuteTransaction(tx, args.signal);
|
|
108
|
+
// See ops/allowlist.ts: file::EncryptedFile was introduced in v2.
|
|
109
|
+
const typePrefix = config.packageId;
|
|
110
|
+
const fileId = toEncryptedFileId(findCreatedId(receipt, `${typePrefix}::file::EncryptedFile`));
|
|
111
|
+
args.onProgress?.({ phase: "complete" });
|
|
112
|
+
return {
|
|
113
|
+
digest: receipt.digest,
|
|
114
|
+
gasUsedMist: receipt.gasUsedMist,
|
|
115
|
+
fileId,
|
|
116
|
+
blobId: upload.blobId,
|
|
117
|
+
blobObjectId: upload.blobObjectId,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (cause) {
|
|
121
|
+
if (cause instanceof UncertifiedBlobError)
|
|
122
|
+
throw cause;
|
|
123
|
+
throw new UncertifiedBlobError(upload.blobObjectId, upload.blobId, {
|
|
124
|
+
cause,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function assertFlowCapable(walrus) {
|
|
129
|
+
if (!isWalrusFlowCapable(walrus)) {
|
|
130
|
+
throw new TransportError("uploadEncryptedFileFromBytes / uploadPublicFileFromBytes require a WalrusWriteAdapter that implements WalrusFlowCapable (i.e. exposes startBlobUpload). The default DefaultWalrusWriteAdapter does. Custom adapters that do not implement the capability should compose walrus.uploadBlob + create_*_file (3 popups) instead.", { operation: "sdk.uploadFileFromBytes" });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=file-from-bytes.js.map
|
|
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ACtB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,MAAM;YACN,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,YAAY,EAAE,MAAM,CAAC,YAAY;SACjC,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,KAAK,YAAY,oBAAoB;YAAE,MAAM,KAAK,CAAC;QACvD,MAAM,IAAI,oBAAoB,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;YAClE,KAAK;SACL,CAAC,CAAC;IACJ,CAAC;AACF,CAAC;AAED,SAAS,iBAAiB,CACzB,MAA0B;IAE1B,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,cAAc,CACvB,+TAA+T,EAC/T,EAAE,SAAS,EAAE,yBAAyB,EAAE,CACxC,CAAC;IACH,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level file ops: build a PTB, sign and execute via the wallet adapter,
|
|
3
|
+
* parse the receipt into a typed result.
|
|
4
|
+
*
|
|
5
|
+
* Encrypted-file creation here registers the metadata record assuming the
|
|
6
|
+
* encrypted bytes are already on Walrus. The all-in-one upload+register
|
|
7
|
+
* flow is `uploadEncryptedFileFromBytes` in `file-from-bytes.ts`.
|
|
8
|
+
*/
|
|
9
|
+
import type { MorsePackageConfig } from "../config.js";
|
|
10
|
+
import type { AllowlistId, BlobObjectId, EncryptedFileId, SuiAddress, WalrusBlobId } from "../types.js";
|
|
11
|
+
import type { WalletAdapter } from "../wallets/adapter.js";
|
|
12
|
+
export interface CreateEncryptedFileArgs {
|
|
13
|
+
readonly allowlistId: AllowlistId;
|
|
14
|
+
readonly blobId: WalrusBlobId;
|
|
15
|
+
readonly blobObjectId?: BlobObjectId;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly contentType: string;
|
|
18
|
+
readonly size: bigint;
|
|
19
|
+
readonly signal?: AbortSignal;
|
|
20
|
+
}
|
|
21
|
+
export interface CreateFileResult {
|
|
22
|
+
readonly digest: string;
|
|
23
|
+
readonly gasUsedMist: bigint;
|
|
24
|
+
readonly fileId: EncryptedFileId;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Register on-chain metadata for an encrypted file already uploaded to Walrus.
|
|
28
|
+
* The bytes at `blobId` MUST be Seal-encrypted under an identity built from
|
|
29
|
+
* `allowlistId` (see `buildAllowlistSealId`); otherwise consumers will fail
|
|
30
|
+
* to decrypt. The SDK does not verify this binding.
|
|
31
|
+
*
|
|
32
|
+
* @throws {ValidationError} If `name` or `contentType` is empty or exceeds length limits.
|
|
33
|
+
* @throws {ContractAbortError} On Move abort (e.g. empty blob_id).
|
|
34
|
+
* @throws {TransportError} On RPC, network, or response-parsing failure.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createEncryptedFile(adapter: WalletAdapter, config: MorsePackageConfig, args: CreateEncryptedFileArgs): Promise<CreateFileResult>;
|
|
37
|
+
export interface CreatePublicFileArgs {
|
|
38
|
+
readonly blobId: WalrusBlobId;
|
|
39
|
+
readonly blobObjectId?: BlobObjectId;
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly contentType: string;
|
|
42
|
+
readonly size: bigint;
|
|
43
|
+
readonly signal?: AbortSignal;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Register on-chain metadata for an unencrypted file. The bytes at `blobId`
|
|
47
|
+
* are publicly readable via the Walrus aggregator.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createPublicFile(adapter: WalletAdapter, config: MorsePackageConfig, args: CreatePublicFileArgs): Promise<CreateFileResult>;
|
|
50
|
+
export interface UpdateFileMetadataArgs {
|
|
51
|
+
readonly fileId: EncryptedFileId;
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly contentType: string;
|
|
54
|
+
readonly signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
export interface FileOpResult {
|
|
57
|
+
readonly digest: string;
|
|
58
|
+
readonly gasUsedMist: bigint;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Update the file's `name` and `content_type`. Other fields are immutable
|
|
62
|
+
* post-creation; create a new file record to swap the blob or change the
|
|
63
|
+
* allowlist. Owner only (sender must equal `file.owner` on-chain).
|
|
64
|
+
*/
|
|
65
|
+
export declare function updateFileMetadata(adapter: WalletAdapter, config: MorsePackageConfig, args: UpdateFileMetadataArgs): Promise<FileOpResult>;
|
|
66
|
+
export interface TransferFileOwnershipArgs {
|
|
67
|
+
readonly fileId: EncryptedFileId;
|
|
68
|
+
readonly newOwner: SuiAddress;
|
|
69
|
+
readonly signal?: AbortSignal;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Transfer the metadata-mutation right to a new address. Decryption access
|
|
73
|
+
* is governed separately by the file's allowlist; the new owner must be
|
|
74
|
+
* added to that allowlist (and the previous owner removed, if desired) by
|
|
75
|
+
* the Cap holder. The two operations can be composed in one PTB by the
|
|
76
|
+
* caller if both rights need to move together.
|
|
77
|
+
*/
|
|
78
|
+
export declare function transferFileOwnership(adapter: WalletAdapter, config: MorsePackageConfig, args: TransferFileOwnershipArgs): Promise<FileOpResult>;
|
|
79
|
+
export interface DeleteFileArgs {
|
|
80
|
+
readonly fileId: EncryptedFileId;
|
|
81
|
+
readonly signal?: AbortSignal;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Delete the on-chain metadata record. Does NOT delete the Walrus blob;
|
|
85
|
+
* that follows the Walrus lease lifecycle independently.
|
|
86
|
+
*/
|
|
87
|
+
export declare function deleteFile(adapter: WalletAdapter, config: MorsePackageConfig, args: DeleteFileArgs): Promise<FileOpResult>;
|
|
88
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/ops/file.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,KAA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