@0xobelisk/sui-client 1.2.0-pre.115 → 1.2.0-pre.118

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dubhe.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Transaction, TransactionResult } from '@mysten/sui/transactions';
1
+ import { Transaction } from '@mysten/sui/transactions';
2
2
  import type { SuiTransactionBlockResponse, DevInspectResults, SuiMoveNormalizedModules, SuiObjectData } from '@mysten/sui/client';
3
3
  import { SuiAccountManager } from './libs/suiAccountManager';
4
4
  import { SuiTx } from './libs/suiTxBuilder';
@@ -24,9 +24,12 @@ export declare class Dubhe {
24
24
  contractFactory: SuiContractFactory;
25
25
  dubheChannelClient: DubheChannelClient;
26
26
  packageId: string | undefined;
27
+ /** Fully-qualified Move type string for this DApp's DappKey, e.g. `<64-hex>::dapp_key::DappKey`. */
28
+ dappKey: string | undefined;
27
29
  metadata: SuiMoveNormalizedModules | undefined;
28
30
  projectName: string | undefined;
29
31
  frameworkPackageId: string | undefined;
32
+ dappStorageId: string | undefined;
30
33
  /**
31
34
  * Support the following ways to init the DubheClient:
32
35
  * 1. mnemonics
@@ -42,7 +45,7 @@ export declare class Dubhe {
42
45
  * @param channelUrl, the base URL for Dubhe Channel API, optional
43
46
  * @param frameworkPackageId, the published package ID of the dubhe framework, required for proxy operations
44
47
  */
45
- constructor({ mnemonics, secretKey, networkType, fullnodeUrls, packageId, metadata, channelUrl, frameworkPackageId }?: DubheParams);
48
+ constructor({ mnemonics, secretKey, networkType, fullnodeUrls, packageId, metadata, channelUrl, frameworkPackageId, dappStorageId }?: DubheParams);
46
49
  get query(): MapMoudleFuncQuery;
47
50
  get tx(): MapMoudleFuncTx;
48
51
  get object(): MapObjectStruct;
@@ -65,7 +68,7 @@ export declare class Dubhe {
65
68
  * it will generate signer from the mnemonic with the given derivePathParams.
66
69
  * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
67
70
  */
68
- getSigner(derivePathParams?: DerivePathParams): import("@mysten/sui/keypairs/ed25519").Ed25519Keypair;
71
+ getSigner(derivePathParams?: DerivePathParams): import("@mysten/sui/dist/cjs/keypairs/ed25519").Ed25519Keypair;
69
72
  /**
70
73
  * @description Switch the current account with the given derivePathParams
71
74
  * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
@@ -78,6 +81,25 @@ export declare class Dubhe {
78
81
  getAddress(derivePathParams?: DerivePathParams): string;
79
82
  currentAddress(): string;
80
83
  getPackageId(): string;
84
+ /**
85
+ * Return the fully-qualified Move type string for this DApp's `DappKey`.
86
+ *
87
+ * The format matches what `std::type_name::get<DappKey>()` returns on-chain:
88
+ * `<64-char-zero-padded-address>::dapp_key::DappKey`
89
+ *
90
+ * Use this whenever you need to pass a type argument or build a `target`
91
+ * string that references the DApp's DappKey type.
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * tx.moveCall({
96
+ * target: `${frameworkPackageId}::dapp_system::settle_writes`,
97
+ * typeArguments: [contract.getDappKey()],
98
+ * arguments: [...],
99
+ * });
100
+ * ```
101
+ */
102
+ getDappKey(): string | undefined;
81
103
  getMetadata(): SuiMoveNormalizedModules | undefined;
82
104
  getNetwork(): NetworkType | undefined;
83
105
  getNetworkConfig(): NetworkConfig;
@@ -150,7 +172,7 @@ export declare class Dubhe {
150
172
  * { onMessage: (data) => console.log(data) }
151
173
  * );
152
174
  */
153
- subscribeChannelTable({ packageId, account, table, key }?: {
175
+ subscribeChannelTable({ packageId: _packageId, account, table, key }?: {
154
176
  packageId?: string;
155
177
  account?: string;
156
178
  table?: string;
@@ -224,244 +246,154 @@ export declare class Dubhe {
224
246
  entity_key_from_address_with_u256(objectId: string, x: number): Promise<string | undefined>;
225
247
  entity_key_from_u256(x: number): Promise<string>;
226
248
  /**
227
- * Return the default network configuration for the given network type.
228
- *
229
- * Useful for reading `frameworkPackageId` without instantiating a full client:
230
- *
231
- * ```ts
232
- * const { frameworkPackageId } = Dubhe.getDefaultConfig('testnet');
233
- * // → '0x8817b...' (known constant for testnet/mainnet)
234
- * // → undefined (for localnet/devnet — supply after local deployment)
235
- * ```
236
- */
237
- static getDefaultConfig(networkType: NetworkType): NetworkConfig;
238
- /**
239
- * Derive the Sui address that corresponds to a raw Ed25519 public key.
240
- *
241
- * Matches the on-chain `derive_sui_address_from_pubkey` helper in
242
- * `proxy_system.move`:
243
- * address = SHA3-256( [0x00] || publicKey )
244
- * where 0x00 is the Ed25519 scheme flag.
245
- *
246
- * @param publicKey Raw 32-byte Ed25519 public key
247
- * @returns 64-character lowercase hex string (without 0x prefix), matching
248
- * the format returned by Move's `address::to_ascii_string()`
249
- */
250
- deriveSuiAddressFromEd25519PublicKey(publicKey: Uint8Array): string;
251
- /**
252
- * Build the canonical proxy registration message.
249
+ * Call the DApp's generated `user_storage_init::init_user_storage` entry function,
250
+ * which creates and shares a `UserStorage` object for the signer.
253
251
  *
254
- * Mirrors `build_expected_message` in `proxy_system.move`:
255
- * "dubhe proxy:<owner_hex>:<proxy_hex>:<dapp_key_str>:<expires_at>"
252
+ * Each DApp exposes this entry point under its own package ID.
253
+ * On Sui, the `UserStorage` object is shared immediately so all transactions
254
+ * can reference it without knowing the object ID in advance.
256
255
  *
257
- * The proxy wallet must sign this message before `createProxy` is called.
258
- *
259
- * @param ownerAddress Owner wallet's Sui address (with or without 0x prefix)
260
- * @param proxyPublicKey Raw 32-byte Ed25519 public key of the proxy wallet
261
- * @param expiresAt Expiry time — either a `Date` object or a millisecond
262
- * timestamp number (e.g. `Date.now() + 86_400_000`)
263
- * @param dappKeyType Full DappKey type string — defaults to
264
- * `<packageId>::dapp_key::DappKey`
265
- */
266
- buildProxyMessage({ ownerAddress, proxyPublicKey, expiresAt, dappKeyType }: {
267
- ownerAddress: string;
268
- proxyPublicKey: Uint8Array;
269
- expiresAt: number | Date;
270
- dappKeyType?: string;
271
- }): Uint8Array;
272
- /**
273
- * Sign the proxy registration message using this client's current account.
274
- *
275
- * The proxy wallet creates a Dubhe instance with its own secret key and calls
276
- * this method to produce the `publicKey` and `signature` that the owner then
277
- * passes to `createProxy`.
278
- *
279
- * @param ownerAddress Sui address of the owner wallet
280
- * @param expiresAt Expiry time — either a `Date` object or a millisecond
281
- * timestamp number (e.g. `new Date(Date.now() + 86_400_000)`)
282
- * @param dappKeyType Optional DApp key type override
283
- * @returns `{ publicKey, signature, message }` — all as `Uint8Array`
284
- */
285
- signProxyMessage({ ownerAddress, expiresAt, dappKeyType }: {
286
- ownerAddress: string;
287
- expiresAt: number | Date;
288
- dappKeyType?: string;
289
- }): Promise<{
290
- publicKey: Uint8Array;
291
- signature: Uint8Array;
292
- message: Uint8Array;
293
- }>;
294
- /**
295
- * Register a proxy wallet binding on-chain.
296
- *
297
- * Follows the same `tx` + `isRaw` convention as `contract.tx.*`:
298
- * - `isRaw: true` — appends the Move call to the provided `tx` and returns
299
- * a `TransactionResult`. The caller controls signing and submission.
300
- * Useful for wallet-based signers (e.g. `useSignAndExecuteTransaction`).
301
- * - `isRaw` omitted — creates a fresh `Transaction` internally, signs with
302
- * the Dubhe instance's own keypair, and submits automatically.
303
- *
304
- * The current signer (owner) submits this transaction. The proxy wallet must
305
- * have already signed the canonical message via `signProxyMessage`, producing
306
- * the `publicKey` and `signature` parameters.
307
- *
308
- * Calls `<frameworkPackageId>::proxy_system::create_proxy<DappKey>`.
309
- *
310
- * @example Wallet signer (browser dApp)
311
- * ```typescript
312
- * const { publicKey, signature } = await proxyDubhe.signProxyMessage({ ownerAddress, expiresAt });
313
- * const tx = new Transaction();
314
- * await proxyDubhe.createProxy({ tx, dappHubId, publicKey, signature, expiresAt, isRaw: true });
315
- * await signAndExecuteTransaction({ transaction: tx.serialize(), chain: `sui:${network}` });
316
- * ```
317
- *
318
- * @param tx Existing Transaction to append to (required when `isRaw: true`)
319
- * @param dappHubId Object ID of the DappHub shared object
320
- * @param publicKey Raw 32-byte Ed25519 public key of the proxy wallet
321
- * @param signature 64-byte Ed25519 signature from the proxy wallet
322
- * @param expiresAt Expiry time — either a `Date` object or a millisecond timestamp
323
- * @param isRaw When true, appends the call and returns without submitting
324
- * @param frameworkPackageId Override the dubhe framework package ID
325
- * @param dappKeyType Override the DApp key type string
256
+ * @param dappHubId Object ID of the DappHub shared object
257
+ * @param dappStorageId Object ID of the DApp's DappStorage shared object
326
258
  */
327
- createProxy({ tx: txIn, dappHubId, publicKey, signature, expiresAt, isRaw, frameworkPackageId, dappKeyType, derivePathParams, onSuccess, onError }: {
328
- tx?: Transaction;
259
+ initUserStorage({ dappHubId, dappStorageId: dappStorageIdParam, derivePathParams, onSuccess, onError }: {
329
260
  dappHubId: string;
330
- publicKey: Uint8Array;
331
- signature: Uint8Array;
332
- expiresAt: number | Date;
333
- isRaw?: boolean;
334
- frameworkPackageId?: string;
335
- dappKeyType?: string;
261
+ dappStorageId?: string;
336
262
  derivePathParams?: DerivePathParams;
337
263
  onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
338
264
  onError?: (error: Error) => void | Promise<void>;
339
- }): Promise<SuiTransactionBlockResponse | TransactionResult>;
265
+ }): Promise<SuiTransactionBlockResponse>;
340
266
  /**
341
- * Extend (or shorten) the expiry of an existing proxy binding.
342
- *
343
- * Follows the same `tx` + `isRaw` convention as `contract.tx.*`:
344
- * - `isRaw: true` — appends the Move call to the provided `tx` and returns
345
- * a `TransactionResult`. The caller controls signing and submission.
346
- * Useful for wallet-based signers (e.g. `useSignAndExecuteTransaction`).
347
- * - `isRaw` omitted — creates a fresh `Transaction` internally, signs with
348
- * the Dubhe instance's own keypair, and submits automatically.
267
+ * Activate a session key for the signer's `UserStorage`.
349
268
  *
350
- * Only the owner who created the binding may call this. The binding must
351
- * still be active (not expired) — use `createProxy` with a fresh signature
352
- * to re-establish an expired proxy.
269
+ * The signer must be the `canonical_owner` of the `UserStorage` object.
270
+ * Calls `<frameworkPackageId>::dapp_system::activate_session<DappKey>`.
353
271
  *
354
- * Calls `<frameworkPackageId>::proxy_system::extend_proxy<DappKey>`.
355
- *
356
- * @example Wallet signer (browser dApp)
357
- * ```typescript
358
- * const tx = new Transaction();
359
- * await proxyDubhe.extendProxy({ tx, dappHubId, proxyAddress, newExpiresAt, isRaw: true });
360
- * await signAndExecuteTransaction({ transaction: tx.serialize(), chain: `sui:${network}` });
361
- * ```
272
+ * @param userStorageId Object ID of the UserStorage to activate a session for
273
+ * @param sessionWallet Sui address of the session wallet
274
+ * @param durationMs Session duration in milliseconds ([60_000, 604_800_000])
275
+ * @param clockObjectId Object ID of the Sui Clock (default: 0x6)
362
276
  */
363
- extendProxy({ tx: txIn, dappHubId, proxyAddress, newExpiresAt, isRaw, frameworkPackageId, dappKeyType, derivePathParams, onSuccess, onError }: {
364
- tx?: Transaction;
365
- dappHubId: string;
366
- proxyAddress: string;
367
- newExpiresAt: number | Date;
368
- isRaw?: boolean;
369
- frameworkPackageId?: string;
370
- dappKeyType?: string;
277
+ activateSession({ userStorageId, sessionWallet, durationMs, clockObjectId, derivePathParams, onSuccess, onError }: {
278
+ userStorageId: string;
279
+ sessionWallet: string;
280
+ durationMs: number;
281
+ clockObjectId?: string;
371
282
  derivePathParams?: DerivePathParams;
372
283
  onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
373
284
  onError?: (error: Error) => void | Promise<void>;
374
- }): Promise<SuiTransactionBlockResponse | TransactionResult>;
285
+ }): Promise<SuiTransactionBlockResponse>;
375
286
  /**
376
- * Remove an existing proxy binding.
377
- *
378
- * Follows the same `tx` + `isRaw` convention as `contract.tx.*`:
379
- * - `isRaw: true` — appends the Move call to the provided `tx` and returns
380
- * a `TransactionResult`. The caller controls signing and submission.
381
- * - `isRaw` omitted — creates a fresh `Transaction`, signs with this
382
- * instance's keypair, and submits automatically.
287
+ * Deactivate the current session key on a `UserStorage`.
383
288
  *
384
- * Only the owner who originally created the proxy may remove it. Expired
385
- * proxies can also be removed to reclaim storage.
289
+ * Allowed callers:
290
+ * - The `canonical_owner` (revoke at any time).
291
+ * - The session key itself (voluntary sign-out).
292
+ * - Anyone, once the session has expired.
386
293
  *
387
- * Calls `<frameworkPackageId>::proxy_system::remove_proxy<DappKey>`.
294
+ * Calls `<frameworkPackageId>::dapp_system::deactivate_session<DappKey>`.
388
295
  *
389
- * @example Wallet signer (browser dApp)
390
- * ```typescript
391
- * const tx = new Transaction();
392
- * await proxyDubhe.removeProxy({ tx, dappHubId, proxyAddress, isRaw: true });
393
- * await signAndExecuteTransaction({ transaction: tx.serialize(), chain: `sui:${network}` });
394
- * ```
296
+ * @param userStorageId Object ID of the UserStorage to deactivate the session on
395
297
  */
396
- removeProxy({ tx: txIn, dappHubId, proxyAddress, isRaw, frameworkPackageId, dappKeyType, derivePathParams, onSuccess, onError }: {
397
- tx?: Transaction;
398
- dappHubId: string;
399
- proxyAddress: string;
400
- isRaw?: boolean;
401
- frameworkPackageId?: string;
402
- dappKeyType?: string;
298
+ deactivateSession({ userStorageId, derivePathParams, onSuccess, onError }: {
299
+ userStorageId: string;
403
300
  derivePathParams?: DerivePathParams;
404
301
  onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
405
302
  onError?: (error: Error) => void | Promise<void>;
406
- }): Promise<SuiTransactionBlockResponse | TransactionResult>;
303
+ }): Promise<SuiTransactionBlockResponse>;
407
304
  /**
408
- * Check whether a proxy wallet is currently active (bound and not expired).
305
+ * Look up the `UserStorage` object ID for the given address in this DApp.
409
306
  *
410
- * Uses `devInspect` no gas required. The check uses the precise Clock
411
- * timestamp, so accuracy is better than `epoch_timestamp_ms`.
307
+ * Scans the transaction history for `user_storage_init::init_user_storage`
308
+ * calls from the given address and extracts the created `UserStorage` object
309
+ * ID from the transaction's object changes.
412
310
  *
413
- * Calls `<frameworkPackageId>::proxy_system::is_proxy_active<DappKey>`.
311
+ * Returns the object ID on success, or `null` when:
312
+ * - `packageId` or `frameworkPackageId` is not set.
313
+ * - The user has not yet called `initUserStorage`.
414
314
  *
415
- * @param dappHubId Object ID of the DappHub shared object
416
- * @param proxyAddress Sui address of the proxy wallet (with or without 0x)
417
- * @param clockObjectId Object ID of the Sui Clock (default: 0x6)
418
- * @returns `true` if the proxy binding exists and `clock < expires_at`
315
+ * @param userAddress Sui address to look up (with or without 0x prefix).
419
316
  */
420
- isProxyActive({ dappHubId, proxyAddress, clockObjectId, frameworkPackageId, dappKeyType }: {
421
- dappHubId: string;
422
- proxyAddress: string;
423
- clockObjectId?: string;
424
- frameworkPackageId?: string;
425
- dappKeyType?: string;
426
- }): Promise<boolean>;
317
+ getUserStorageId(userAddress: string): Promise<string | null>;
427
318
  /**
428
- * Check whether a proxy binding record exists (regardless of expiry).
319
+ * Fetch and return the on-chain fields of a `UserStorage` shared object.
429
320
  *
430
- * Uses `devInspect` no gas required.
321
+ * The returned object mirrors Move's `UserStorage` struct plus two
322
+ * convenience fields computed from the raw counters:
323
+ * - `unsettled_count` = write_count − settled_count
324
+ * - `unsettled_bytes` = write_bytes − settled_bytes
431
325
  *
432
- * Calls `<frameworkPackageId>::proxy_config::has`.
326
+ * @param userStorageId Object ID of the UserStorage to inspect.
327
+ */
328
+ getUserStorageFields(userStorageId: string): Promise<{
329
+ objectId: string;
330
+ dapp_key: string;
331
+ canonical_owner: string;
332
+ session_key: string;
333
+ session_expires_at: bigint;
334
+ write_count: bigint;
335
+ settled_count: bigint;
336
+ write_bytes: bigint;
337
+ settled_bytes: bigint;
338
+ unsettled_count: bigint;
339
+ unsettled_bytes: bigint;
340
+ }>;
341
+ /**
342
+ * Fetch and return the on-chain fields of a `DappStorage` shared object.
433
343
  *
434
- * @param dappHubId Object ID of the DappHub shared object
435
- * @param proxyAddress Sui address of the proxy wallet (with or without 0x)
436
- * @returns `true` if a binding record exists (may be expired)
344
+ * Covers the full metadata + fee/credit subset of the Move struct.
345
+ *
346
+ * @param dappStorageId Object ID of the DappStorage to inspect.
437
347
  */
438
- hasProxy({ dappHubId, proxyAddress, frameworkPackageId, dappKeyType }: {
439
- dappHubId: string;
440
- proxyAddress: string;
441
- frameworkPackageId?: string;
442
- dappKeyType?: string;
443
- }): Promise<boolean>;
348
+ getDappStorageFields(dappStorageId: string): Promise<{
349
+ objectId: string;
350
+ dapp_key: string;
351
+ name: string;
352
+ description: string;
353
+ website_url: string;
354
+ admin: string;
355
+ version: number;
356
+ paused: boolean;
357
+ free_credit: bigint;
358
+ free_credit_expires_at: bigint;
359
+ credit_pool: bigint;
360
+ min_credit_to_unsuspend: bigint;
361
+ suspended: boolean;
362
+ total_settled: bigint;
363
+ base_fee_per_write: bigint;
364
+ bytes_fee_per_byte: bigint;
365
+ }>;
444
366
  /**
445
- * Fetch the proxy binding record for a given proxy wallet address.
367
+ * Settle accumulated write debt for a user.
446
368
  *
447
- * Uses `devInspect` no gas required.
448
- * Returns `null` if no binding exists for the given proxy address.
369
+ * Calls `<frameworkPackageId>::dapp_system::settle_writes<DappKey>` with the
370
+ * given DappHub, DappStorage, and UserStorage objects.
449
371
  *
450
- * Calls `<frameworkPackageId>::proxy_config::get`.
372
+ * This is safe to prepend to any PTB — the framework function never aborts
373
+ * due to insufficient credit; it silently skips or partially settles.
451
374
  *
452
- * @param dappHubId Object ID of the DappHub shared object
453
- * @param proxyAddress Sui address of the proxy wallet (with or without 0x)
454
- * @returns `{ owner, expiresAt }` where `owner` is the bound owner's Sui address
455
- * (with 0x prefix) and `expiresAt` is the expiry timestamp in milliseconds,
456
- * or `null` if no binding record exists.
375
+ * @param dappHubId Object ID of the DappHub shared object.
376
+ * @param dappStorageId Object ID of the DApp's DappStorage shared object.
377
+ * @param userStorageId Object ID of the user's UserStorage shared object.
457
378
  */
458
- getProxyBinding({ dappHubId, proxyAddress, frameworkPackageId, dappKeyType }: {
379
+ settleWrites({ dappHubId, dappStorageId: dappStorageIdParam, userStorageId, derivePathParams, onSuccess, onError }: {
459
380
  dappHubId: string;
460
- proxyAddress: string;
461
- frameworkPackageId?: string;
462
- dappKeyType?: string;
463
- }): Promise<{
464
- owner: string;
465
- expiresAt: number;
466
- } | null>;
381
+ dappStorageId?: string;
382
+ userStorageId: string;
383
+ derivePathParams?: DerivePathParams;
384
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
385
+ onError?: (error: Error) => void | Promise<void>;
386
+ }): Promise<SuiTransactionBlockResponse>;
387
+ /**
388
+ * Return the default network configuration for the given network type.
389
+ *
390
+ * Useful for reading `frameworkPackageId` without instantiating a full client:
391
+ *
392
+ * ```ts
393
+ * const { frameworkPackageId } = Dubhe.getDefaultConfig('testnet');
394
+ * // → '0x8817b...' (known constant for testnet/mainnet)
395
+ * // → undefined (for localnet/devnet — supply after local deployment)
396
+ * ```
397
+ */
398
+ static getDefaultConfig(networkType: NetworkType): NetworkConfig;
467
399
  }