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

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 } from '@mysten/sui/transactions';
1
+ import { Transaction, TransactionResult } 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';
@@ -7,7 +7,7 @@ import { MapObjectStruct } from './types';
7
7
  import { SuiContractFactory } from './libs/suiContractFactory';
8
8
  import { SuiMoveMoudleFuncType } from './libs/suiContractFactory/types';
9
9
  import { NetworkConfig } from './libs/suiInteractor';
10
- import { DerivePathParams, FaucetNetworkType, MapMoudleFuncQuery, MapMoudleFuncTx, DubheParams, SuiTxArg, SuiObjectArg, SuiVecTxArg } from './types';
10
+ import { DerivePathParams, FaucetNetworkType, MapMoudleFuncQuery, MapMoudleFuncTx, DubheParams, SuiTxArg, SuiObjectArg, SuiVecTxArg, NetworkType } from './types';
11
11
  import { DubheChannelClient } from './libs/dubheChannel';
12
12
  export declare function isUndefined(value?: unknown): value is undefined;
13
13
  export declare function withMeta<T extends {
@@ -26,6 +26,7 @@ export declare class Dubhe {
26
26
  packageId: string | undefined;
27
27
  metadata: SuiMoveNormalizedModules | undefined;
28
28
  projectName: string | undefined;
29
+ frameworkPackageId: string | undefined;
29
30
  /**
30
31
  * Support the following ways to init the DubheClient:
31
32
  * 1. mnemonics
@@ -39,8 +40,9 @@ export declare class Dubhe {
39
40
  * @param packageId
40
41
  * @param metadata
41
42
  * @param channelUrl, the base URL for Dubhe Channel API, optional
43
+ * @param frameworkPackageId, the published package ID of the dubhe framework, required for proxy operations
42
44
  */
43
- constructor({ mnemonics, secretKey, networkType, fullnodeUrls, packageId, metadata, channelUrl }?: DubheParams);
45
+ constructor({ mnemonics, secretKey, networkType, fullnodeUrls, packageId, metadata, channelUrl, frameworkPackageId }?: DubheParams);
44
46
  get query(): MapMoudleFuncQuery;
45
47
  get tx(): MapMoudleFuncTx;
46
48
  get object(): MapObjectStruct;
@@ -63,7 +65,7 @@ export declare class Dubhe {
63
65
  * it will generate signer from the mnemonic with the given derivePathParams.
64
66
  * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
65
67
  */
66
- getSigner(derivePathParams?: DerivePathParams): import("@mysten/sui/dist/cjs/keypairs/ed25519").Ed25519Keypair;
68
+ getSigner(derivePathParams?: DerivePathParams): import("@mysten/sui/keypairs/ed25519").Ed25519Keypair;
67
69
  /**
68
70
  * @description Switch the current account with the given derivePathParams
69
71
  * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
@@ -77,7 +79,7 @@ export declare class Dubhe {
77
79
  currentAddress(): string;
78
80
  getPackageId(): string;
79
81
  getMetadata(): SuiMoveNormalizedModules | undefined;
80
- getNetwork(): import("./types").NetworkType | undefined;
82
+ getNetwork(): NetworkType | undefined;
81
83
  getNetworkConfig(): NetworkConfig;
82
84
  getTxExplorerUrl(txHash: string): string;
83
85
  getAccountExplorerUrl(address: string): string;
@@ -221,4 +223,245 @@ export declare class Dubhe {
221
223
  entity_key_from_address_with_seed(objectId: string, seed: string): Promise<string | undefined>;
222
224
  entity_key_from_address_with_u256(objectId: string, x: number): Promise<string | undefined>;
223
225
  entity_key_from_u256(x: number): Promise<string>;
226
+ /**
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.
253
+ *
254
+ * Mirrors `build_expected_message` in `proxy_system.move`:
255
+ * "dubhe proxy:<owner_hex>:<proxy_hex>:<dapp_key_str>:<expires_at>"
256
+ *
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
326
+ */
327
+ createProxy({ tx: txIn, dappHubId, publicKey, signature, expiresAt, isRaw, frameworkPackageId, dappKeyType, derivePathParams, onSuccess, onError }: {
328
+ tx?: Transaction;
329
+ dappHubId: string;
330
+ publicKey: Uint8Array;
331
+ signature: Uint8Array;
332
+ expiresAt: number | Date;
333
+ isRaw?: boolean;
334
+ frameworkPackageId?: string;
335
+ dappKeyType?: string;
336
+ derivePathParams?: DerivePathParams;
337
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
338
+ onError?: (error: Error) => void | Promise<void>;
339
+ }): Promise<SuiTransactionBlockResponse | TransactionResult>;
340
+ /**
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.
349
+ *
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.
353
+ *
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
+ * ```
362
+ */
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;
371
+ derivePathParams?: DerivePathParams;
372
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
373
+ onError?: (error: Error) => void | Promise<void>;
374
+ }): Promise<SuiTransactionBlockResponse | TransactionResult>;
375
+ /**
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.
383
+ *
384
+ * Only the owner who originally created the proxy may remove it. Expired
385
+ * proxies can also be removed to reclaim storage.
386
+ *
387
+ * Calls `<frameworkPackageId>::proxy_system::remove_proxy<DappKey>`.
388
+ *
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
+ * ```
395
+ */
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;
403
+ derivePathParams?: DerivePathParams;
404
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
405
+ onError?: (error: Error) => void | Promise<void>;
406
+ }): Promise<SuiTransactionBlockResponse | TransactionResult>;
407
+ /**
408
+ * Check whether a proxy wallet is currently active (bound and not expired).
409
+ *
410
+ * Uses `devInspect` — no gas required. The check uses the precise Clock
411
+ * timestamp, so accuracy is better than `epoch_timestamp_ms`.
412
+ *
413
+ * Calls `<frameworkPackageId>::proxy_system::is_proxy_active<DappKey>`.
414
+ *
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`
419
+ */
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>;
427
+ /**
428
+ * Check whether a proxy binding record exists (regardless of expiry).
429
+ *
430
+ * Uses `devInspect` — no gas required.
431
+ *
432
+ * Calls `<frameworkPackageId>::proxy_config::has`.
433
+ *
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)
437
+ */
438
+ hasProxy({ dappHubId, proxyAddress, frameworkPackageId, dappKeyType }: {
439
+ dappHubId: string;
440
+ proxyAddress: string;
441
+ frameworkPackageId?: string;
442
+ dappKeyType?: string;
443
+ }): Promise<boolean>;
444
+ /**
445
+ * Fetch the proxy binding record for a given proxy wallet address.
446
+ *
447
+ * Uses `devInspect` — no gas required.
448
+ * Returns `null` if no binding exists for the given proxy address.
449
+ *
450
+ * Calls `<frameworkPackageId>::proxy_config::get`.
451
+ *
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.
457
+ */
458
+ getProxyBinding({ dappHubId, proxyAddress, frameworkPackageId, dappKeyType }: {
459
+ dappHubId: string;
460
+ proxyAddress: string;
461
+ frameworkPackageId?: string;
462
+ dappKeyType?: string;
463
+ }): Promise<{
464
+ owner: string;
465
+ expiresAt: number;
466
+ } | null>;
224
467
  }
package/dist/index.d.ts CHANGED
@@ -14,3 +14,5 @@ export { MultiSigClient } from './libs/multiSig';
14
14
  export { SuiContractFactory } from './libs/suiContractFactory';
15
15
  export { loadMetadata } from './metadata';
16
16
  export type * from './types';
17
+ export { getDefaultConfig, getDefaultURL, TESTNET_DUBHE_FRAMEWORK_PACKAGE_ID, TESTNET_DUBHE_HUB_OBJECT_ID, MAINNET_DUBHE_FRAMEWORK_PACKAGE_ID, MAINNET_DUBHE_HUB_OBJECT_ID } from './libs/suiInteractor/defaultConfig';
18
+ export type { NetworkConfig } from './libs/suiInteractor/defaultConfig';