@arcadiasystems/morse-sdk 0.1.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.
Files changed (156) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +21 -0
  3. package/README.md +404 -0
  4. package/dist/clients.d.ts +12 -0
  5. package/dist/clients.d.ts.map +1 -0
  6. package/dist/clients.js +6 -0
  7. package/dist/clients.js.map +1 -0
  8. package/dist/codecs.d.ts +45 -0
  9. package/dist/codecs.d.ts.map +1 -0
  10. package/dist/codecs.js +132 -0
  11. package/dist/codecs.js.map +1 -0
  12. package/dist/compatibility.d.ts +22 -0
  13. package/dist/compatibility.d.ts.map +1 -0
  14. package/dist/compatibility.js +22 -0
  15. package/dist/compatibility.js.map +1 -0
  16. package/dist/config.d.ts +92 -0
  17. package/dist/config.d.ts.map +1 -0
  18. package/dist/config.js +85 -0
  19. package/dist/config.js.map +1 -0
  20. package/dist/errors.d.ts +101 -0
  21. package/dist/errors.d.ts.map +1 -0
  22. package/dist/errors.js +214 -0
  23. package/dist/errors.js.map +1 -0
  24. package/dist/index.d.ts +15 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +14 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/ops/cap.d.ts +79 -0
  29. package/dist/ops/cap.d.ts.map +1 -0
  30. package/dist/ops/cap.js +104 -0
  31. package/dist/ops/cap.js.map +1 -0
  32. package/dist/ops/collection.d.ts +50 -0
  33. package/dist/ops/collection.d.ts.map +1 -0
  34. package/dist/ops/collection.js +55 -0
  35. package/dist/ops/collection.js.map +1 -0
  36. package/dist/ops/entry-from-bytes.d.ts +129 -0
  37. package/dist/ops/entry-from-bytes.d.ts.map +1 -0
  38. package/dist/ops/entry-from-bytes.js +137 -0
  39. package/dist/ops/entry-from-bytes.js.map +1 -0
  40. package/dist/ops/entry.d.ts +173 -0
  41. package/dist/ops/entry.d.ts.map +1 -0
  42. package/dist/ops/entry.js +235 -0
  43. package/dist/ops/entry.js.map +1 -0
  44. package/dist/ops/index.d.ts +9 -0
  45. package/dist/ops/index.d.ts.map +1 -0
  46. package/dist/ops/index.js +9 -0
  47. package/dist/ops/index.js.map +1 -0
  48. package/dist/ops/internal.d.ts +21 -0
  49. package/dist/ops/internal.d.ts.map +1 -0
  50. package/dist/ops/internal.js +42 -0
  51. package/dist/ops/internal.js.map +1 -0
  52. package/dist/ops/publication.d.ts +74 -0
  53. package/dist/ops/publication.d.ts.map +1 -0
  54. package/dist/ops/publication.js +123 -0
  55. package/dist/ops/publication.js.map +1 -0
  56. package/dist/ptb/cap.d.ts +36 -0
  57. package/dist/ptb/cap.d.ts.map +1 -0
  58. package/dist/ptb/cap.js +44 -0
  59. package/dist/ptb/cap.js.map +1 -0
  60. package/dist/ptb/collection.d.ts +27 -0
  61. package/dist/ptb/collection.d.ts.map +1 -0
  62. package/dist/ptb/collection.js +33 -0
  63. package/dist/ptb/collection.js.map +1 -0
  64. package/dist/ptb/entry.d.ts +104 -0
  65. package/dist/ptb/entry.d.ts.map +1 -0
  66. package/dist/ptb/entry.js +155 -0
  67. package/dist/ptb/entry.js.map +1 -0
  68. package/dist/ptb/index.d.ts +9 -0
  69. package/dist/ptb/index.d.ts.map +1 -0
  70. package/dist/ptb/index.js +9 -0
  71. package/dist/ptb/index.js.map +1 -0
  72. package/dist/ptb/internal.d.ts +11 -0
  73. package/dist/ptb/internal.d.ts.map +1 -0
  74. package/dist/ptb/internal.js +12 -0
  75. package/dist/ptb/internal.js.map +1 -0
  76. package/dist/ptb/publication.d.ts +51 -0
  77. package/dist/ptb/publication.d.ts.map +1 -0
  78. package/dist/ptb/publication.js +61 -0
  79. package/dist/ptb/publication.js.map +1 -0
  80. package/dist/read/entry-bcs.d.ts +47 -0
  81. package/dist/read/entry-bcs.d.ts.map +1 -0
  82. package/dist/read/entry-bcs.js +36 -0
  83. package/dist/read/entry-bcs.js.map +1 -0
  84. package/dist/read/index.d.ts +5 -0
  85. package/dist/read/index.d.ts.map +1 -0
  86. package/dist/read/index.js +5 -0
  87. package/dist/read/index.js.map +1 -0
  88. package/dist/read/reader.d.ts +148 -0
  89. package/dist/read/reader.d.ts.map +1 -0
  90. package/dist/read/reader.js +403 -0
  91. package/dist/read/reader.js.map +1 -0
  92. package/dist/seal/adapter.d.ts +56 -0
  93. package/dist/seal/adapter.d.ts.map +1 -0
  94. package/dist/seal/adapter.js +7 -0
  95. package/dist/seal/adapter.js.map +1 -0
  96. package/dist/seal/default-adapter.d.ts +90 -0
  97. package/dist/seal/default-adapter.d.ts.map +1 -0
  98. package/dist/seal/default-adapter.js +187 -0
  99. package/dist/seal/default-adapter.js.map +1 -0
  100. package/dist/seal/identity.d.ts +31 -0
  101. package/dist/seal/identity.d.ts.map +1 -0
  102. package/dist/seal/identity.js +79 -0
  103. package/dist/seal/identity.js.map +1 -0
  104. package/dist/seal/index.d.ts +8 -0
  105. package/dist/seal/index.d.ts.map +1 -0
  106. package/dist/seal/index.js +7 -0
  107. package/dist/seal/index.js.map +1 -0
  108. package/dist/types.d.ts +160 -0
  109. package/dist/types.d.ts.map +1 -0
  110. package/dist/types.js +33 -0
  111. package/dist/types.js.map +1 -0
  112. package/dist/wallets/adapter.d.ts +34 -0
  113. package/dist/wallets/adapter.d.ts.map +1 -0
  114. package/dist/wallets/adapter.js +6 -0
  115. package/dist/wallets/adapter.js.map +1 -0
  116. package/dist/wallets/index.d.ts +7 -0
  117. package/dist/wallets/index.d.ts.map +1 -0
  118. package/dist/wallets/index.js +6 -0
  119. package/dist/wallets/index.js.map +1 -0
  120. package/dist/wallets/keypair-adapter.d.ts +31 -0
  121. package/dist/wallets/keypair-adapter.d.ts.map +1 -0
  122. package/dist/wallets/keypair-adapter.js +210 -0
  123. package/dist/wallets/keypair-adapter.js.map +1 -0
  124. package/dist/wallets/wallet-standard-signer.d.ts +118 -0
  125. package/dist/wallets/wallet-standard-signer.d.ts.map +1 -0
  126. package/dist/wallets/wallet-standard-signer.js +207 -0
  127. package/dist/wallets/wallet-standard-signer.js.map +1 -0
  128. package/dist/walrus/adapter.d.ts +91 -0
  129. package/dist/walrus/adapter.d.ts.map +1 -0
  130. package/dist/walrus/adapter.js +11 -0
  131. package/dist/walrus/adapter.js.map +1 -0
  132. package/dist/walrus/default-adapter.d.ts +104 -0
  133. package/dist/walrus/default-adapter.d.ts.map +1 -0
  134. package/dist/walrus/default-adapter.js +146 -0
  135. package/dist/walrus/default-adapter.js.map +1 -0
  136. package/dist/walrus/default-read-adapter.d.ts +89 -0
  137. package/dist/walrus/default-read-adapter.d.ts.map +1 -0
  138. package/dist/walrus/default-read-adapter.js +81 -0
  139. package/dist/walrus/default-read-adapter.js.map +1 -0
  140. package/dist/walrus/http-aggregator-read-adapter.d.ts +107 -0
  141. package/dist/walrus/http-aggregator-read-adapter.d.ts.map +1 -0
  142. package/dist/walrus/http-aggregator-read-adapter.js +174 -0
  143. package/dist/walrus/http-aggregator-read-adapter.js.map +1 -0
  144. package/dist/walrus/http-publisher-write-adapter.d.ts +97 -0
  145. package/dist/walrus/http-publisher-write-adapter.d.ts.map +1 -0
  146. package/dist/walrus/http-publisher-write-adapter.js +249 -0
  147. package/dist/walrus/http-publisher-write-adapter.js.map +1 -0
  148. package/dist/walrus/index.d.ts +11 -0
  149. package/dist/walrus/index.d.ts.map +1 -0
  150. package/dist/walrus/index.js +11 -0
  151. package/dist/walrus/index.js.map +1 -0
  152. package/dist/walrus/quilt-patch-id.d.ts +34 -0
  153. package/dist/walrus/quilt-patch-id.d.ts.map +1 -0
  154. package/dist/walrus/quilt-patch-id.js +103 -0
  155. package/dist/walrus/quilt-patch-id.js.map +1 -0
  156. package/package.json +72 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/seal/adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,QAAQ,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;CACxC;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;;;;;OAQG;IACH,OAAO,CACN,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,OAAO,CACN,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,UAAU,CAAC,CAAC;CACvB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Seal adapter interface: encrypt content under a publisher Seal identity
3
+ * and decrypt with a consumer-supplied `SessionKey`. Configuration
4
+ * (key servers, threshold, package id) is bound at construction time.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/seal/adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Default `SealAdapter` wrapping `@mysten/seal`'s `SealClient`. Constructed
3
+ * once with the morse package id (which Seal embeds into ciphertext
4
+ * envelopes), the key-server list, and the TSS threshold. Threshold lives on
5
+ * the config rather than per-call: ciphertexts encoded under one threshold
6
+ * are not decryptable under another, so per-call thresholds would
7
+ * silently break recoverability when changed.
8
+ */
9
+ import { type KeyServerConfig, type SealCompatibleClient, type SessionKey } from "@mysten/seal";
10
+ import type { PackageId } from "../types.js";
11
+ import type { SealAdapter, SealDecryptOptions, SealEncryptOptions, SealEncryptResult } from "./adapter.js";
12
+ /**
13
+ * Configuration for `DefaultSealAdapter`. `packageId` MUST be the deployment's
14
+ * `originalPackageId`: Seal binds the package address into ciphertext
15
+ * envelopes and into key-server proofs, so a post-upgrade `packageId` would
16
+ * make pre-upgrade ciphertexts undecryptable.
17
+ */
18
+ export interface SealAdapterConfig {
19
+ readonly packageId: PackageId;
20
+ readonly serverConfigs: readonly KeyServerConfig[];
21
+ readonly threshold: number;
22
+ readonly verifyKeyServers?: boolean;
23
+ readonly timeout?: number;
24
+ }
25
+ /** Narrow structural slice of `SealClient` actually used by the adapter. */
26
+ interface SealClientLike {
27
+ encrypt(args: {
28
+ threshold: number;
29
+ packageId: string;
30
+ id: string;
31
+ data: Uint8Array;
32
+ aad?: Uint8Array;
33
+ }): Promise<{
34
+ encryptedObject: Uint8Array;
35
+ key: Uint8Array;
36
+ }>;
37
+ decrypt(args: {
38
+ data: Uint8Array;
39
+ sessionKey: SessionKey;
40
+ txBytes: Uint8Array;
41
+ }): Promise<Uint8Array>;
42
+ }
43
+ interface DefaultSealAdapterOptions {
44
+ readonly client: SealClientLike;
45
+ readonly suiClient: SealCompatibleClient;
46
+ readonly packageId: PackageId;
47
+ readonly threshold: number;
48
+ }
49
+ /** `SealAdapter` implementation backed by `@mysten/seal`. */
50
+ export declare class DefaultSealAdapter implements SealAdapter {
51
+ private readonly client;
52
+ private readonly suiClient;
53
+ private readonly packageId;
54
+ private readonly threshold;
55
+ constructor(options: DefaultSealAdapterOptions);
56
+ /**
57
+ * Build an adapter from a morse package config (typically
58
+ * `morseConfig({ network })`). Defaults `serverConfigs` from
59
+ * `morseConfig.sealKeyServers` (the canonical testnet allowlist baked
60
+ * into morse-sdk) when omitted; defaults `threshold` to
61
+ * `min(2, serverConfigs.length)` when omitted. Picks
62
+ * `originalPackageId ?? packageId` internally; passing a post-upgrade
63
+ * `packageId` directly would silently produce ciphertexts that become
64
+ * undecryptable across upgrades.
65
+ *
66
+ * Pass `seal: {}` for the default path; supply `serverConfigs` when you
67
+ * want a custom set (paid plans, alternate trust assumptions, region
68
+ * pinning), or `threshold` when you want a non-default TSS shape.
69
+ *
70
+ * @throws {ConfigurationError} If neither `seal.serverConfigs` nor
71
+ * `morseConfig.sealKeyServers` provide any servers (e.g. mainnet
72
+ * pre-freeze).
73
+ */
74
+ static fromMorseConfig(morseConfig: {
75
+ packageId: PackageId;
76
+ originalPackageId?: PackageId;
77
+ sealKeyServers?: readonly KeyServerConfig[];
78
+ }, seal: Partial<Omit<SealAdapterConfig, "packageId">>, suiClient: SealCompatibleClient): DefaultSealAdapter;
79
+ /**
80
+ * Build an adapter from a `SealAdapterConfig` and a Sui-compatible client
81
+ * (a `SuiGrpcClient` satisfies the `SealCompatibleClient` shape). Use
82
+ * `fromMorseConfig` instead when you have a `morseConfig({network})`.
83
+ */
84
+ static fromConfig(config: SealAdapterConfig, suiClient: SealCompatibleClient): DefaultSealAdapter;
85
+ encrypt(plaintext: Uint8Array, options: SealEncryptOptions): Promise<SealEncryptResult>;
86
+ decrypt(ciphertext: Uint8Array, options: SealDecryptOptions): Promise<Uint8Array>;
87
+ private buildSealApproveTxBytes;
88
+ }
89
+ export {};
90
+ //# sourceMappingURL=default-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-adapter.d.ts","sourceRoot":"","sources":["../../src/seal/default-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAIN,KAAK,eAAe,EAGpB,KAAK,oBAAoB,EACzB,KAAK,UAAU,EAEf,MAAM,cAAc,CAAC;AAUtB,OAAO,KAAK,EACX,SAAS,EAIT,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACX,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,MAAM,cAA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,EAAE,yBAAyB;IAO9C;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,eAAe,CACrB,WAAW,EAAE;QACZ,SAAS,EAAE,SAAS,CAAC;QACrB,iBAAiB,CAAC,EAAE,SAAS,CAAC;QAC9B,cAAc,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;KAC5C,EACD,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC,EACnD,SAAS,EAAE,oBAAoB,GAC7B,kBAAkB;IAuBrB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAChB,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,oBAAoB,GAC7B,kBAAkB;IAiCf,OAAO,CACZ,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,iBAAiB,CAAC;IAcvB,OAAO,CACZ,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,UAAU,CAAC;YAgCR,uBAAuB;CAyBrC"}
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Default `SealAdapter` wrapping `@mysten/seal`'s `SealClient`. Constructed
3
+ * once with the morse package id (which Seal embeds into ciphertext
4
+ * envelopes), the key-server list, and the TSS threshold. Threshold lives on
5
+ * the config rather than per-call: ciphertexts encoded under one threshold
6
+ * are not decryptable under another, so per-call thresholds would
7
+ * silently break recoverability when changed.
8
+ */
9
+ import { DecryptionError, ExpiredSessionKeyError, InvalidCiphertextError, NoAccessError, SealClient, TooManyFailedFetchKeyRequestsError, } from "@mysten/seal";
10
+ import { Transaction } from "@mysten/sui/transactions";
11
+ import { ConfigurationError, SealError, TransportError, ValidationError, } from "../errors.js";
12
+ import { decodePublisherSealId } from "./identity.js";
13
+ /** `SealAdapter` implementation backed by `@mysten/seal`. */
14
+ export class DefaultSealAdapter {
15
+ client;
16
+ suiClient;
17
+ packageId;
18
+ threshold;
19
+ constructor(options) {
20
+ this.client = options.client;
21
+ this.suiClient = options.suiClient;
22
+ this.packageId = options.packageId;
23
+ this.threshold = options.threshold;
24
+ }
25
+ /**
26
+ * Build an adapter from a morse package config (typically
27
+ * `morseConfig({ network })`). Defaults `serverConfigs` from
28
+ * `morseConfig.sealKeyServers` (the canonical testnet allowlist baked
29
+ * into morse-sdk) when omitted; defaults `threshold` to
30
+ * `min(2, serverConfigs.length)` when omitted. Picks
31
+ * `originalPackageId ?? packageId` internally; passing a post-upgrade
32
+ * `packageId` directly would silently produce ciphertexts that become
33
+ * undecryptable across upgrades.
34
+ *
35
+ * Pass `seal: {}` for the default path; supply `serverConfigs` when you
36
+ * want a custom set (paid plans, alternate trust assumptions, region
37
+ * pinning), or `threshold` when you want a non-default TSS shape.
38
+ *
39
+ * @throws {ConfigurationError} If neither `seal.serverConfigs` nor
40
+ * `morseConfig.sealKeyServers` provide any servers (e.g. mainnet
41
+ * pre-freeze).
42
+ */
43
+ static fromMorseConfig(morseConfig, seal, suiClient) {
44
+ const serverConfigs = seal.serverConfigs ?? morseConfig.sealKeyServers ?? [];
45
+ if (serverConfigs.length === 0) {
46
+ throw new ConfigurationError("morseConfig has no canonical Seal key servers for this network and no override was supplied. Pass seal.serverConfigs explicitly, or use a network where the allowlist is pinned.");
47
+ }
48
+ const threshold = seal.threshold ?? Math.min(2, serverConfigs.length);
49
+ return DefaultSealAdapter.fromConfig({
50
+ packageId: morseConfig.originalPackageId ?? morseConfig.packageId,
51
+ serverConfigs,
52
+ threshold,
53
+ ...(seal.verifyKeyServers === undefined
54
+ ? {}
55
+ : { verifyKeyServers: seal.verifyKeyServers }),
56
+ ...(seal.timeout === undefined ? {} : { timeout: seal.timeout }),
57
+ }, suiClient);
58
+ }
59
+ /**
60
+ * Build an adapter from a `SealAdapterConfig` and a Sui-compatible client
61
+ * (a `SuiGrpcClient` satisfies the `SealCompatibleClient` shape). Use
62
+ * `fromMorseConfig` instead when you have a `morseConfig({network})`.
63
+ */
64
+ static fromConfig(config, suiClient) {
65
+ if (config.serverConfigs.length === 0) {
66
+ throw new ValidationError("SealAdapterConfig.serverConfigs must contain at least one entry", "serverConfigs");
67
+ }
68
+ if (!Number.isInteger(config.threshold) ||
69
+ config.threshold < 1 ||
70
+ config.threshold > config.serverConfigs.length) {
71
+ throw new ValidationError(`SealAdapterConfig.threshold must be an integer in [1, ${config.serverConfigs.length}]; got ${config.threshold}`, "threshold");
72
+ }
73
+ const client = new SealClient({
74
+ suiClient,
75
+ serverConfigs: [...config.serverConfigs],
76
+ ...(config.verifyKeyServers === undefined
77
+ ? {}
78
+ : { verifyKeyServers: config.verifyKeyServers }),
79
+ ...(config.timeout === undefined ? {} : { timeout: config.timeout }),
80
+ });
81
+ return new DefaultSealAdapter({
82
+ client,
83
+ suiClient,
84
+ packageId: config.packageId,
85
+ threshold: config.threshold,
86
+ });
87
+ }
88
+ async encrypt(plaintext, options) {
89
+ const id = bytesToHex(options.sealId);
90
+ const result = await runSealCall(() => this.client.encrypt({
91
+ threshold: this.threshold,
92
+ packageId: this.packageId,
93
+ id,
94
+ data: plaintext,
95
+ ...(options.aad === undefined ? {} : { aad: options.aad }),
96
+ }));
97
+ return { ciphertext: result.encryptedObject };
98
+ }
99
+ async decrypt(ciphertext, options) {
100
+ // `decodePublisherSealId` throws `ValidationError` on a malformed or
101
+ // tampered `SealId` (unknown policy tag). On-chain bytes are
102
+ // contract-enforced, but `Revision.sealId` from a reader brands the
103
+ // payload without re-validating client-side, and a hostile indexer
104
+ // could surface arbitrary bytes. Rewrap as `SealError("decrypt-failed")`
105
+ // so the throw matches `SealAdapter.decrypt`'s documented error contract.
106
+ let publicationId;
107
+ try {
108
+ ({ publicationId } = decodePublisherSealId(options.sealId));
109
+ }
110
+ catch (cause) {
111
+ throw new SealError("decrypt-failed", `Seal identity is malformed or uses an unsupported policy tag: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
112
+ }
113
+ const txBytes = await this.buildSealApproveTxBytes(publicationId, options.publisherCapId, options.sealId, options.sessionKey);
114
+ return runSealCall(() => this.client.decrypt({
115
+ data: ciphertext,
116
+ sessionKey: options.sessionKey,
117
+ txBytes,
118
+ }));
119
+ }
120
+ async buildSealApproveTxBytes(publicationId, publisherCapId, sealId, sessionKey) {
121
+ const tx = new Transaction();
122
+ tx.moveCall({
123
+ target: `${this.packageId}::publication::seal_approve_publisher`,
124
+ arguments: [
125
+ tx.pure.vector("u8", Array.from(sealId)),
126
+ tx.object(publicationId),
127
+ tx.object(publisherCapId),
128
+ ],
129
+ });
130
+ tx.setSender(sessionKey.getAddress());
131
+ try {
132
+ return await tx.build({
133
+ client: this.suiClient,
134
+ onlyTransactionKind: true,
135
+ });
136
+ }
137
+ catch (cause) {
138
+ throw new TransportError("Failed to build seal_approve PTB", { cause });
139
+ }
140
+ }
141
+ }
142
+ async function runSealCall(call) {
143
+ try {
144
+ return await call();
145
+ }
146
+ catch (cause) {
147
+ const mapped = mapSealError(cause);
148
+ if (mapped) {
149
+ throw mapped;
150
+ }
151
+ throw new TransportError(sealErrorMessage(cause), { cause });
152
+ }
153
+ }
154
+ function mapSealError(cause) {
155
+ if (cause instanceof NoAccessError) {
156
+ return new SealError("no-access", `Seal denied access: ${cause.message}`, {
157
+ cause,
158
+ });
159
+ }
160
+ if (cause instanceof ExpiredSessionKeyError) {
161
+ return new SealError("session-expired", "Seal session key expired", {
162
+ cause,
163
+ });
164
+ }
165
+ if (cause instanceof TooManyFailedFetchKeyRequestsError) {
166
+ return new SealError("rate-limited", "Seal key servers rejected too many requests", { cause });
167
+ }
168
+ if (cause instanceof DecryptionError ||
169
+ cause instanceof InvalidCiphertextError) {
170
+ return new SealError("decrypt-failed", `Seal decryption failed: ${cause.message}`, { cause });
171
+ }
172
+ return null;
173
+ }
174
+ function sealErrorMessage(cause) {
175
+ if (cause instanceof Error) {
176
+ return `Seal call failed: ${cause.message}`;
177
+ }
178
+ return "Seal call failed";
179
+ }
180
+ function bytesToHex(bytes) {
181
+ let hex = "0x";
182
+ for (const byte of bytes) {
183
+ hex += byte.toString(16).padStart(2, "0");
184
+ }
185
+ return hex;
186
+ }
187
+ //# sourceMappingURL=default-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-adapter.js","sourceRoot":"","sources":["../../src/seal/default-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EAEtB,aAAa,EACb,UAAU,EAGV,kCAAkC,GAClC,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACN,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,eAAe,GACf,MAAM,cAAc,CAAC;AAatB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAuCtD,6DAA6D;AAC7D,MAAM,OAAO,kBAAkB;IACb,MAAM,CAAiB;IACvB,SAAS,CAAuB;IAChC,SAAS,CAAY;IACrB,SAAS,CAAS;IAEnC,YAAY,OAAkC;QAC7C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACpC,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,eAAe,CACrB,WAIC,EACD,IAAmD,EACnD,SAA+B;QAE/B,MAAM,aAAa,GAClB,IAAI,CAAC,aAAa,IAAI,WAAW,CAAC,cAAc,IAAI,EAAE,CAAC;QACxD,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,kBAAkB,CAC3B,kLAAkL,CAClL,CAAC;QACH,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,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CAAC;IAC7C,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC3B,CAAC;AAED,SAAS,UAAU,CAAC,KAAiB;IACpC,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Seal identity (`SealId`) construction and inspection. The Move layer
3
+ * enforces the byte format on every encrypted revision and on the
4
+ * `seal_approve_publisher` entry, so both encode and decode here must match
5
+ * the contract byte-for-byte.
6
+ *
7
+ * Layout: `publication_id(32) || policy_tag(u8=1) || nonce(>=1)`. Total
8
+ * length > 33 bytes (`ESealInvalidId` otherwise).
9
+ */
10
+ import { type PublicationId, type SealId, SealPolicyTag } from "../types.js";
11
+ /** Structured view of a publisher Seal identity. */
12
+ export interface SealIdParts {
13
+ readonly publicationId: PublicationId;
14
+ readonly policyTag: SealPolicyTag;
15
+ readonly nonce: Uint8Array;
16
+ }
17
+ /**
18
+ * Build a publisher-policy Seal identity for a publication. The nonce must
19
+ * be at least 1 byte (the Move contract's `id.length() > 33` invariant);
20
+ * nonces of 16 random bytes are typical.
21
+ *
22
+ * @throws {ValidationError} If `publicationId` is not a 0x-prefixed 64-char
23
+ * hex string, or `nonce` is shorter than 1 byte.
24
+ */
25
+ export declare function buildPublisherSealId(publicationId: PublicationId, nonce: Uint8Array): SealId;
26
+ /**
27
+ * Decode the structural fields of a Seal identity. The brand guarantees the
28
+ * byte layout, so this never throws on a properly-built identity.
29
+ */
30
+ export declare function decodePublisherSealId(id: SealId): SealIdParts;
31
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/seal/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAO7E,oDAAoD;AACpD,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CACnC,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,UAAU,GACf,MAAM,CAaR;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,CAS7D"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Seal identity (`SealId`) construction and inspection. The Move layer
3
+ * enforces the byte format on every encrypted revision and on the
4
+ * `seal_approve_publisher` entry, so both encode and decode here must match
5
+ * the contract byte-for-byte.
6
+ *
7
+ * Layout: `publication_id(32) || policy_tag(u8=1) || nonce(>=1)`. Total
8
+ * length > 33 bytes (`ESealInvalidId` otherwise).
9
+ */
10
+ import { ValidationError } from "../errors.js";
11
+ import { SealPolicyTag } from "../types.js";
12
+ const PUBLICATION_ID_BYTES = 32;
13
+ const POLICY_TAG_OFFSET = PUBLICATION_ID_BYTES;
14
+ const NONCE_OFFSET = POLICY_TAG_OFFSET + 1;
15
+ const MIN_NONCE_BYTES = 1;
16
+ /**
17
+ * Build a publisher-policy Seal identity for a publication. The nonce must
18
+ * be at least 1 byte (the Move contract's `id.length() > 33` invariant);
19
+ * nonces of 16 random bytes are typical.
20
+ *
21
+ * @throws {ValidationError} If `publicationId` is not a 0x-prefixed 64-char
22
+ * hex string, or `nonce` is shorter than 1 byte.
23
+ */
24
+ export function buildPublisherSealId(publicationId, nonce) {
25
+ if (nonce.length < MIN_NONCE_BYTES) {
26
+ throw new ValidationError(`Seal nonce must be at least ${MIN_NONCE_BYTES} byte(s), got ${nonce.length}`, "nonce");
27
+ }
28
+ const prefix = publicationIdToBytes(publicationId);
29
+ const out = new Uint8Array(PUBLICATION_ID_BYTES + 1 + nonce.length);
30
+ out.set(prefix, 0);
31
+ out[POLICY_TAG_OFFSET] = SealPolicyTag.Publisher;
32
+ out.set(nonce, NONCE_OFFSET);
33
+ return out;
34
+ }
35
+ /**
36
+ * Decode the structural fields of a Seal identity. The brand guarantees the
37
+ * byte layout, so this never throws on a properly-built identity.
38
+ */
39
+ export function decodePublisherSealId(id) {
40
+ const prefix = id.subarray(0, PUBLICATION_ID_BYTES);
41
+ const policyTagByte = id[POLICY_TAG_OFFSET] ?? 0;
42
+ const nonce = id.slice(NONCE_OFFSET);
43
+ return {
44
+ publicationId: bytesToPublicationId(prefix),
45
+ policyTag: policyTagToEnum(policyTagByte),
46
+ nonce,
47
+ };
48
+ }
49
+ function policyTagToEnum(byte) {
50
+ if (byte === SealPolicyTag.Publisher) {
51
+ return SealPolicyTag.Publisher;
52
+ }
53
+ throw new ValidationError(`Unknown Seal policy tag: ${byte} (only ${SealPolicyTag.Publisher} = Publisher is defined)`, "policyTag");
54
+ }
55
+ function publicationIdToBytes(value) {
56
+ const stripped = value.startsWith("0x")
57
+ ? value.slice(2)
58
+ : value;
59
+ if (stripped.length > PUBLICATION_ID_BYTES * 2) {
60
+ throw new ValidationError(`PublicationId exceeds ${PUBLICATION_ID_BYTES} bytes`, "publicationId");
61
+ }
62
+ const padded = stripped.padStart(PUBLICATION_ID_BYTES * 2, "0");
63
+ if (!/^[0-9a-f]+$/i.test(padded)) {
64
+ throw new ValidationError(`PublicationId is not valid hex: ${value}`, "publicationId");
65
+ }
66
+ const out = new Uint8Array(PUBLICATION_ID_BYTES);
67
+ for (let i = 0; i < PUBLICATION_ID_BYTES; i += 1) {
68
+ out[i] = Number.parseInt(padded.slice(i * 2, i * 2 + 2), 16);
69
+ }
70
+ return out;
71
+ }
72
+ function bytesToPublicationId(bytes) {
73
+ let hex = "";
74
+ for (const byte of bytes) {
75
+ hex += byte.toString(16).padStart(2, "0");
76
+ }
77
+ return `0x${hex}`;
78
+ }
79
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/seal/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAmC,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AAC/C,MAAM,YAAY,GAAG,iBAAiB,GAAG,CAAC,CAAC;AAC3C,MAAM,eAAe,GAAG,CAAC,CAAC;AAS1B;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CACnC,aAA4B,EAC5B,KAAiB;IAEjB,IAAI,KAAK,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;QACpC,MAAM,IAAI,eAAe,CACxB,+BAA+B,eAAe,iBAAiB,KAAK,CAAC,MAAM,EAAE,EAC7E,OAAO,CACP,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GAAG,oBAAoB,CAAC,aAAa,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,oBAAoB,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IACpE,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACnB,GAAG,CAAC,iBAAiB,CAAC,GAAG,aAAa,CAAC,SAAS,CAAC;IACjD,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAC7B,OAAO,GAAa,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,EAAU;IAC/C,MAAM,MAAM,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,oBAAoB,CAA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,CAAC,IAAI,CAAC,EAAE,CAAC;QAClD,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAiB;IAC9C,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,KAAK,GAAG,EAAmB,CAAC;AACpC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Seal subpackage barrel: identity construction, the adapter interface, and
3
+ * the default adapter wrapping `@mysten/seal`.
4
+ */
5
+ export type { SealAdapter, SealDecryptOptions, SealEncryptOptions, SealEncryptResult, } from "./adapter.js";
6
+ export { DefaultSealAdapter, type SealAdapterConfig, } from "./default-adapter.js";
7
+ export { buildPublisherSealId, decodePublisherSealId, type SealIdParts, } from "./identity.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/seal/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACX,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,kBAAkB,EAClB,KAAK,iBAAiB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,WAAW,GAChB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Seal subpackage barrel: identity construction, the adapter interface, and
3
+ * the default adapter wrapping `@mysten/seal`.
4
+ */
5
+ export { DefaultSealAdapter, } from "./default-adapter.js";
6
+ export { buildPublisherSealId, decodePublisherSealId, } from "./identity.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/seal/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EACN,kBAAkB,GAElB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,oBAAoB,EACpB,qBAAqB,GAErB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Public domain types, mirroring `morse-contracts`.
3
+ *
4
+ * Mapping conventions: Move `u64` to `number`; Move `Option<T>` to `T | null`;
5
+ * Move enums to string-discriminated unions; object IDs are branded strings.
6
+ */
7
+ type Brand<T, Tag extends string> = T & {
8
+ readonly __brand: Tag;
9
+ };
10
+ /** Sui package ID of a deployed `publication` Move package. */
11
+ export type PackageId = Brand<string, "PackageId">;
12
+ /** Sui object ID of the shared `PublicationRegistry`. */
13
+ export type RegistryId = Brand<string, "RegistryId">;
14
+ /** Sui object ID of a `Publication`. */
15
+ export type PublicationId = Brand<string, "PublicationId">;
16
+ /** Sui object ID of an `OwnerCap`. */
17
+ export type OwnerCapId = Brand<string, "OwnerCapId">;
18
+ /** Sui object ID of a `PublisherCap`. */
19
+ export type PublisherCapId = Brand<string, "PublisherCapId">;
20
+ /** Sui object ID of a Walrus `Blob`. */
21
+ export type BlobObjectId = Brand<string, "BlobObjectId">;
22
+ /**
23
+ * Walrus content-addressed blob ID. URL-safe base64 of the 32-byte content
24
+ * digest, 43 chars without padding. Distinct from `BlobObjectId`, which is
25
+ * the Sui object holding the blob.
26
+ */
27
+ export type WalrusBlobId = Brand<string, "WalrusBlobId">;
28
+ /**
29
+ * 37-byte quilt patch ID: `quilt_id(32) || version(1) || start(2) || end(2)`,
30
+ * u16 indices little-endian (BCS canonical). Branded to prevent accidental
31
+ * passing of arbitrary byte arrays to APIs that expect a validated patch ID.
32
+ */
33
+ export type QuiltPatchId = Uint8Array & {
34
+ readonly __brand: "QuiltPatchId";
35
+ };
36
+ /**
37
+ * Seal identity bytes. Layout: `publication_id(32) || policy_tag(u8) || nonce(>=1)`.
38
+ * Total length must be > 33. Branded so callers cannot bypass the identity
39
+ * builder; construct via `buildPublisherSealId`.
40
+ */
41
+ export type SealId = Uint8Array & {
42
+ readonly __brand: "SealId";
43
+ };
44
+ /** Hex-encoded Sui account address. */
45
+ export type SuiAddress = Brand<string, "SuiAddress">;
46
+ /** Generic Sui object ID for objects without a more specific brand. */
47
+ export type SuiObjectId = Brand<string, "SuiObjectId">;
48
+ /**
49
+ * Collection content layout on Walrus: standalone blobs per entry (`blob`, u8=0)
50
+ * or patches in a shared quilt (`quilt`, u8=1).
51
+ */
52
+ export declare const StorageMode: {
53
+ readonly Blob: "blob";
54
+ readonly Quilt: "quilt";
55
+ };
56
+ export type StorageMode = (typeof StorageMode)[keyof typeof StorageMode];
57
+ /**
58
+ * Who may decrypt an entry revision. Move u8: public=0, publisher=1, subscription=2.
59
+ * `subscription` is reserved; the Move layer does not yet accept it.
60
+ */
61
+ export declare const AccessPolicy: {
62
+ readonly Public: "public";
63
+ readonly Publisher: "publisher";
64
+ readonly Subscription: "subscription";
65
+ };
66
+ export type AccessPolicy = (typeof AccessPolicy)[keyof typeof AccessPolicy];
67
+ /** Policy tag byte inside a Seal identity, identifying the approval entrypoint. */
68
+ export declare const SealPolicyTag: {
69
+ readonly Publisher: 1;
70
+ };
71
+ export type SealPolicyTag = (typeof SealPolicyTag)[keyof typeof SealPolicyTag];
72
+ /**
73
+ * Walrus content reference for a revision. `blob` holds a Sui object ID;
74
+ * `quilt` holds a 37-byte `QuiltPatchId`.
75
+ */
76
+ export type BlobRef = {
77
+ readonly kind: "blob";
78
+ readonly blobObjectId: BlobObjectId;
79
+ } | {
80
+ readonly kind: "quilt";
81
+ readonly patchId: QuiltPatchId;
82
+ };
83
+ /** Byte length of a QuiltPatchId, enforced by the Move layer. */
84
+ export declare const QUILT_PATCH_ID_LENGTH = 37;
85
+ /** One immutable revision of an entry. Mutations are appended, never edited in place. */
86
+ export interface Revision {
87
+ /** Zero-based index into the entry's revision vector. */
88
+ readonly id: number;
89
+ readonly blobRef: BlobRef;
90
+ /** MIME content type; casing is not enforced on-chain. */
91
+ readonly contentType: string;
92
+ readonly encrypted: boolean;
93
+ readonly accessPolicy: AccessPolicy;
94
+ /** Seal identity bound to encrypted revisions; `null` when unencrypted. */
95
+ readonly sealId: SealId | null;
96
+ /** Address that submitted the transaction creating this revision. */
97
+ readonly author: SuiAddress;
98
+ }
99
+ /** One entry within a collection; revisions are append-only with draft and public heads. */
100
+ export interface Entry {
101
+ /** Monotonic ID assigned on insert; stable across deletions. */
102
+ readonly id: number;
103
+ readonly name: string;
104
+ readonly revisions: readonly Revision[];
105
+ readonly draftHead: number | null;
106
+ readonly publicHead: number | null;
107
+ }
108
+ /** One collection within a publication. `storageMode` is immutable after creation. */
109
+ export interface Collection {
110
+ readonly name: string;
111
+ readonly storageMode: StorageMode;
112
+ readonly nextEntryId: number;
113
+ /** Sui object ID of the dynamic-field table holding entries. */
114
+ readonly entriesTableId: SuiObjectId;
115
+ }
116
+ /** Top-level container for collections. Slug is unique across active publications. */
117
+ export interface Publication {
118
+ readonly id: PublicationId;
119
+ readonly name: string;
120
+ readonly slug: string;
121
+ readonly collections: readonly Collection[];
122
+ /** Sui object ID of the denylist table tracking revoked PublisherCaps. */
123
+ readonly revokedPublisherCapsTableId: SuiObjectId;
124
+ }
125
+ /** Owner capability; issues and revokes PublisherCaps, deletes the publication. Transferable. */
126
+ export interface OwnerCap {
127
+ readonly id: OwnerCapId;
128
+ readonly publicationId: PublicationId;
129
+ }
130
+ /** Write-access capability bound to `holder`; multiple may exist per publication. */
131
+ export interface PublisherCap {
132
+ readonly id: PublisherCapId;
133
+ readonly publicationId: PublicationId;
134
+ readonly holder: SuiAddress;
135
+ }
136
+ /** One object created by a transaction. */
137
+ export interface TxCreatedObject {
138
+ readonly objectId: SuiObjectId;
139
+ /**
140
+ * Move type tag, e.g. `0x35b5..::publication::Publication`. Treat as opaque;
141
+ * use exact string match against a known type, not substring matching.
142
+ */
143
+ readonly objectType: string;
144
+ }
145
+ /** One object deleted by a transaction. */
146
+ export interface TxDeletedObject {
147
+ readonly objectId: SuiObjectId;
148
+ }
149
+ /**
150
+ * Result of a signed transaction. `gasUsedMist = computationCost + storageCost - storageRebate`;
151
+ * negative values are possible when storage is freed.
152
+ */
153
+ export interface TxReceipt {
154
+ readonly digest: string;
155
+ readonly gasUsedMist: bigint;
156
+ readonly createdObjects: readonly TxCreatedObject[];
157
+ readonly deletedObjects: readonly TxDeletedObject[];
158
+ }
159
+ export {};
160
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,KAAK,KAAK,CAAC,CAAC,EAAE,GAAG,SAAS,MAAM,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAElE,+DAA+D;AAC/D,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAEnD,yDAAyD;AACzD,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAErD,wCAAwC;AACxC,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3D,sCAAsC;AACtC,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAErD,yCAAyC;AACzC,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAE7D,wCAAwC;AACxC,MAAM,MAAM,YAAY,GAAG,K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