@0xio/sdk 2.7.1 → 2.8.1
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 +80 -39
- package/README.md +104 -280
- package/dist/index.d.ts +254 -45
- package/dist/index.esm.js +410 -79
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +419 -78
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +419 -78
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 0xio SDK
|
|
2
|
+
* 0xio SDK: Wallet Transport Adapter Interface
|
|
3
3
|
*
|
|
4
4
|
* Implement WalletTransportAdapter to add support for a new wallet without
|
|
5
5
|
* touching any core SDK code. Drop the adapter file in src/supports/ and
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
|
-
* Outbound request
|
|
20
|
+
* Outbound request: the SDK passes this to adapter.postRequest() for every
|
|
21
21
|
* outbound wallet call. Adapters translate this into their wallet-specific wire format.
|
|
22
22
|
*/
|
|
23
23
|
interface AdapterRequest {
|
|
@@ -63,8 +63,8 @@ interface AdapterIncomingMessage {
|
|
|
63
63
|
* - How to send requests (postRequest)
|
|
64
64
|
* - How to receive responses and events (listen)
|
|
65
65
|
*
|
|
66
|
-
* Everything else
|
|
67
|
-
* event routing
|
|
66
|
+
* Everything else (request lifecycle, timeouts, retries, rate limiting,
|
|
67
|
+
* event routing) is handled by the SDK core and does not change per wallet.
|
|
68
68
|
*
|
|
69
69
|
* @example Minimal adapter for a hypothetical wallet
|
|
70
70
|
* ```typescript
|
|
@@ -103,7 +103,7 @@ interface WalletTransportAdapter {
|
|
|
103
103
|
detect(): boolean;
|
|
104
104
|
/**
|
|
105
105
|
* Send a request to the wallet.
|
|
106
|
-
* Called once per outbound request
|
|
106
|
+
* Called once per outbound request: translate AdapterRequest into your
|
|
107
107
|
* wallet's wire format and post it (window.postMessage, direct API call, etc.).
|
|
108
108
|
*/
|
|
109
109
|
postRequest(request: AdapterRequest): void;
|
|
@@ -120,7 +120,7 @@ interface WalletTransportAdapter {
|
|
|
120
120
|
*
|
|
121
121
|
* @param handler Callback for responses and push events
|
|
122
122
|
* @param options SDK-level options, e.g. additional trusted parent origins
|
|
123
|
-
* @returns A teardown function
|
|
123
|
+
* @returns A teardown function. The SDK calls it on cleanup()
|
|
124
124
|
*/
|
|
125
125
|
listen(handler: (msg: AdapterIncomingMessage) => void, options?: {
|
|
126
126
|
trustedParentOrigins?: string[];
|
|
@@ -162,16 +162,21 @@ interface NetworkInfo {
|
|
|
162
162
|
}
|
|
163
163
|
interface TransactionData {
|
|
164
164
|
readonly to: string;
|
|
165
|
-
/**
|
|
166
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Raw amount in micro-OCT (1 OCT = 1000000), passed to the wallet unchanged. This is what
|
|
167
|
+
* the wallet and the RFC-O-1 provider expect. Prefer `amountOct` when you think in OCT.
|
|
168
|
+
*/
|
|
169
|
+
readonly amount?: string | number;
|
|
170
|
+
/** Amount in OCT. The SDK converts it to raw units exactly (at most 6 decimals). Use this or `amount`, not both. */
|
|
171
|
+
readonly amountOct?: string | number;
|
|
167
172
|
readonly message?: string;
|
|
168
173
|
readonly feeLevel?: 1 | 3;
|
|
169
174
|
readonly isPrivate?: boolean;
|
|
170
175
|
}
|
|
171
176
|
/**
|
|
172
|
-
* Contract method arguments
|
|
177
|
+
* Contract method arguments: flat array of AML-compatible values.
|
|
173
178
|
* Supports primitives and base64-encoded binary data (e.g. FHE ciphers, proofs).
|
|
174
|
-
* Use `[arg1, arg2]
|
|
179
|
+
* Use `[arg1, arg2]`, not `[[arg1, arg2]]`: flat, not nested.
|
|
175
180
|
*/
|
|
176
181
|
type ContractParam = string | number | boolean;
|
|
177
182
|
type ContractParams = ReadonlyArray<ContractParam>;
|
|
@@ -181,16 +186,18 @@ interface ContractCallData {
|
|
|
181
186
|
/** Contract method name (e.g. 'swap', 'open_private_account') */
|
|
182
187
|
readonly method: string;
|
|
183
188
|
/**
|
|
184
|
-
* Method arguments
|
|
189
|
+
* Method arguments: flat primitives, not array-wrapped.
|
|
185
190
|
* For FHE/PVAC operations, encode binary data as base64 strings:
|
|
186
191
|
* `[base64(pvacPubkey), base64(zeroCipher), base64(zeroProof)]`
|
|
187
192
|
*/
|
|
188
193
|
readonly params: ContractParams;
|
|
189
194
|
/**
|
|
190
|
-
* Native
|
|
191
|
-
*
|
|
195
|
+
* Native value to attach, in raw micro-OCT (1 OCT = 1000000), passed to the wallet unchanged.
|
|
196
|
+
* Omit or set '0' for calls that transfer nothing. Prefer `amountOct` when you think in OCT.
|
|
192
197
|
*/
|
|
193
198
|
readonly amount?: string | number;
|
|
199
|
+
/** Value to attach in OCT. The SDK converts it to raw units exactly. Use this or `amount`, not both. */
|
|
200
|
+
readonly amountOct?: string | number;
|
|
194
201
|
/**
|
|
195
202
|
* Operation units / gas limit (default: 10000).
|
|
196
203
|
* Higher values for complex contract operations.
|
|
@@ -203,7 +210,7 @@ interface ContractViewCallData {
|
|
|
203
210
|
readonly contract: string;
|
|
204
211
|
/** Contract method name (e.g. 'balance_of', 'get_active_bin', 'is_paused') */
|
|
205
212
|
readonly method: string;
|
|
206
|
-
/** Method arguments
|
|
213
|
+
/** Method arguments: flat primitives, not array-wrapped */
|
|
207
214
|
readonly params: ContractParams;
|
|
208
215
|
/** Caller address for view context (defaults to connected wallet) */
|
|
209
216
|
readonly caller?: string;
|
|
@@ -245,7 +252,7 @@ interface Transaction {
|
|
|
245
252
|
readonly hash: string;
|
|
246
253
|
readonly from: string;
|
|
247
254
|
readonly to: string;
|
|
248
|
-
/** Amount in OCT as returned by the node (
|
|
255
|
+
/** Amount in raw micro-OCT as returned by the node (string or number depending on the wallet version). */
|
|
249
256
|
readonly amount: string | number;
|
|
250
257
|
/** Fee in OCT as returned by the node (may be string or number depending on extension version). */
|
|
251
258
|
readonly fee: string | number;
|
|
@@ -271,8 +278,8 @@ interface ConnectOptions {
|
|
|
271
278
|
readonly requestPermissions?: Permission[];
|
|
272
279
|
readonly networkId?: string;
|
|
273
280
|
}
|
|
274
|
-
type Permission = 'read_address' | 'read_balance' | 'read_public_key' | 'send_transactions' | 'sign_messages' | 'contract_calls' | 'view_private_balance' | 'view_encrypted_balance' | 'private_transfers' | 'encrypt_balance' | 'decrypt_balance' | 'stealth_scan' | 'stealth_claim';
|
|
275
|
-
type WalletEventType = 'connect' | 'disconnect' | 'accountChanged' | 'balanceChanged' | 'networkChanged' | 'transactionConfirmed' | 'permissionsChanged' | 'message' | 'error' | 'extensionLocked' | 'extensionUnlocked';
|
|
281
|
+
type Permission = 'accounts' | 'public_transactions' | 'contract_views' | 'private_balance_read' | 'private_proofs' | 'private_claims' | 'read_address' | 'read_balance' | 'read_public_key' | 'send_transactions' | 'sign_messages' | 'contract_calls' | 'view_private_balance' | 'view_encrypted_balance' | 'private_transfers' | 'encrypt_balance' | 'decrypt_balance' | 'stealth_scan' | 'stealth_claim';
|
|
282
|
+
type WalletEventType = 'connect' | 'disconnect' | 'accountChanged' | 'balanceChanged' | 'networkChanged' | 'transactionConfirmed' | 'transactionFailed' | 'permissionsChanged' | 'message' | 'error' | 'extensionLocked' | 'extensionUnlocked';
|
|
276
283
|
interface WalletEvent<T = any> {
|
|
277
284
|
readonly type: WalletEventType;
|
|
278
285
|
readonly data: T;
|
|
@@ -331,7 +338,16 @@ declare enum ErrorCode {
|
|
|
331
338
|
INVALID_SIGNATURE = "INVALID_SIGNATURE",
|
|
332
339
|
DUPLICATE_TRANSACTION = "DUPLICATE_TRANSACTION",
|
|
333
340
|
NONCE_TOO_FAR = "NONCE_TOO_FAR",
|
|
334
|
-
INTERNAL_ERROR = "INTERNAL_ERROR"
|
|
341
|
+
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
342
|
+
NOT_CONNECTED = "NOT_CONNECTED",
|
|
343
|
+
INVALID_PARAMS = "INVALID_PARAMS",
|
|
344
|
+
METHOD_NOT_ALLOWED = "METHOD_NOT_ALLOWED",
|
|
345
|
+
NOT_AVAILABLE = "NOT_AVAILABLE",
|
|
346
|
+
PRIVATE_PROOF_FAILED = "PRIVATE_PROOF_FAILED",
|
|
347
|
+
PRIVATE_TRANSFER_FAILED = "PRIVATE_TRANSFER_FAILED",
|
|
348
|
+
CONTRACT_CALL_FAILED = "CONTRACT_CALL_FAILED",
|
|
349
|
+
SIGN_FAILED = "SIGN_FAILED",
|
|
350
|
+
RECIPIENT_NOT_REGISTERED = "RECIPIENT_NOT_REGISTERED"
|
|
335
351
|
}
|
|
336
352
|
declare class ZeroXIOWalletError extends Error {
|
|
337
353
|
readonly code: ErrorCode;
|
|
@@ -345,12 +361,21 @@ interface PrivateBalanceInfo {
|
|
|
345
361
|
}
|
|
346
362
|
interface PrivateTransferData {
|
|
347
363
|
readonly to: string;
|
|
348
|
-
/** Amount in OCT. Accepts string or number
|
|
364
|
+
/** Amount in OCT. Accepts string or number. Use string for amounts above 9 billion OCT to avoid JS number precision loss. */
|
|
349
365
|
readonly amount: string | number;
|
|
366
|
+
/** Exact amount in raw micro-OCT. When set, it is what the wallet uses; `amount` is then display only. */
|
|
367
|
+
readonly amountRaw?: string;
|
|
368
|
+
/** Not carried by the wallet today; private transfers have no memo on-chain. */
|
|
350
369
|
readonly message?: string;
|
|
351
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* A claimable stealth output as the wallet returns it. The 0xio extension fills `id` and
|
|
373
|
+
* `amount` (raw micro-OCT) from the node; the other fields depend on the wallet.
|
|
374
|
+
*/
|
|
352
375
|
interface PendingPrivateTransfer {
|
|
353
376
|
readonly id: string;
|
|
377
|
+
/** Raw micro-OCT, when the wallet exposes the amount. */
|
|
378
|
+
readonly amount?: number | string;
|
|
354
379
|
readonly from: string;
|
|
355
380
|
readonly encryptedAmount: string;
|
|
356
381
|
readonly message?: string;
|
|
@@ -368,7 +393,7 @@ interface SDKConfig {
|
|
|
368
393
|
readonly debug?: boolean;
|
|
369
394
|
/**
|
|
370
395
|
* Exact origins allowed as parent iframe bridge (e.g. 'https://app.example.com').
|
|
371
|
-
* When set, only these origins (plus tauri://) are trusted
|
|
396
|
+
* When set, only these origins (plus tauri://) are trusted: implicit localhost trust
|
|
372
397
|
* is disabled. Leave unset for development (all localhost trusted by default).
|
|
373
398
|
*/
|
|
374
399
|
readonly trustedParentOrigins?: string[];
|
|
@@ -444,9 +469,10 @@ declare class ZeroXIOWallet extends EventEmitter {
|
|
|
444
469
|
*/
|
|
445
470
|
getConnectionStatus(): Promise<ConnectionInfo>;
|
|
446
471
|
/**
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
472
|
+
* Ask the wallet to switch its active network (e.g. 'mainnet' to 'devnet').
|
|
473
|
+
* The wallet asks the user to confirm first; declining rejects with USER_REJECTED. The call is
|
|
474
|
+
* also refused while another request from this page is waiting for approval.
|
|
475
|
+
* On a switch the wallet emits 'networkChanged' to connected dApps.
|
|
450
476
|
*/
|
|
451
477
|
switchNetwork(networkId: string): Promise<{
|
|
452
478
|
network: string;
|
|
@@ -457,6 +483,11 @@ declare class ZeroXIOWallet extends EventEmitter {
|
|
|
457
483
|
*/
|
|
458
484
|
getNetworkId(): string | null;
|
|
459
485
|
getAddress(): string | null;
|
|
486
|
+
/**
|
|
487
|
+
* The connected account's Ed25519 public key (base64). Served from the session when the
|
|
488
|
+
* wallet reported it at connect, otherwise asked from the wallet.
|
|
489
|
+
*/
|
|
490
|
+
getPublicKey(): Promise<string>;
|
|
460
491
|
getBalance(forceRefresh?: boolean): Promise<Balance>;
|
|
461
492
|
getNetworkInfo(): Promise<NetworkInfo>;
|
|
462
493
|
sendTransaction(txData: TransactionData): Promise<TransactionResult>;
|
|
@@ -492,11 +523,15 @@ declare class ZeroXIOWallet extends EventEmitter {
|
|
|
492
523
|
getTransactionHistory(page?: number, limit?: number): Promise<TransactionHistory>;
|
|
493
524
|
getPrivateBalanceInfo(): Promise<PrivateBalanceInfo>;
|
|
494
525
|
/**
|
|
495
|
-
* Encrypt public balance to private
|
|
526
|
+
* Encrypt public balance to private.
|
|
527
|
+
* @deprecated The 0xio extension does not serve this through the bridge (it answers
|
|
528
|
+
* NOT_AVAILABLE); users encrypt from the extension's Privacy screen.
|
|
496
529
|
*/
|
|
497
530
|
encryptBalance(amount: string | number): Promise<TransactionResult>;
|
|
498
531
|
/**
|
|
499
|
-
* Decrypt private balance to public
|
|
532
|
+
* Decrypt private balance to public.
|
|
533
|
+
* @deprecated The 0xio extension does not serve this through the bridge (it answers
|
|
534
|
+
* NOT_AVAILABLE); users decrypt from the extension's Privacy screen.
|
|
500
535
|
*/
|
|
501
536
|
decryptBalance(amount: string | number): Promise<TransactionResult>;
|
|
502
537
|
/**
|
|
@@ -520,15 +555,121 @@ declare class ZeroXIOWallet extends EventEmitter {
|
|
|
520
555
|
*/
|
|
521
556
|
claimPrivateTransfer(transferId: string): Promise<TransactionResult>;
|
|
522
557
|
/**
|
|
523
|
-
*
|
|
524
|
-
*
|
|
558
|
+
* Send any wallet method + params through the bridge. Escape hatch for
|
|
559
|
+
* primitives that don't have a typed helper yet (no SDK upgrade needed).
|
|
560
|
+
* @since 2.8.0
|
|
561
|
+
*/
|
|
562
|
+
request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
563
|
+
/**
|
|
564
|
+
* Read-only node RPC through the wallet. Only the wallet's allow-listed public methods work
|
|
565
|
+
* (octra_balance, octra_transaction, contract_call and similar); writes are refused.
|
|
566
|
+
* @since 2.8.0
|
|
567
|
+
*/
|
|
568
|
+
rpcCall<T = unknown>(method: string, params?: unknown[]): Promise<T>;
|
|
569
|
+
/**
|
|
570
|
+
* Feature-detect which private capabilities the connected wallet supports.
|
|
571
|
+
* Lets a dapp render the correct UI (or fail closed) before any action.
|
|
572
|
+
* @since 2.8.0
|
|
573
|
+
*/
|
|
574
|
+
getPrivateCapabilities(): Promise<{
|
|
575
|
+
wallet: string;
|
|
576
|
+
version: string;
|
|
577
|
+
supports: Record<string, boolean>;
|
|
578
|
+
methods: string[];
|
|
579
|
+
required_permissions?: Record<string, string[]>;
|
|
580
|
+
}>;
|
|
581
|
+
/** Read-only contract view (no approval popup). @since 2.8.0 */
|
|
582
|
+
callContractView(params: {
|
|
583
|
+
contract: string;
|
|
584
|
+
method: string;
|
|
585
|
+
params?: unknown[];
|
|
586
|
+
caller?: string;
|
|
587
|
+
}): Promise<unknown>;
|
|
588
|
+
/** Encrypt a raw integer value to a contract-ready ciphertext (keys stay in wallet). @since 2.8.0 */
|
|
589
|
+
encryptValue(params: {
|
|
590
|
+
value_raw: string;
|
|
591
|
+
token?: string;
|
|
592
|
+
owner?: string;
|
|
593
|
+
asset?: string;
|
|
594
|
+
}): Promise<{
|
|
595
|
+
cipher: string;
|
|
596
|
+
commitment?: string;
|
|
597
|
+
encoding?: string;
|
|
598
|
+
}>;
|
|
599
|
+
/** Decrypt a ciphertext to a raw integer value. @since 2.8.0 */
|
|
600
|
+
decryptValue(params: {
|
|
601
|
+
cipher: string;
|
|
602
|
+
token?: string;
|
|
603
|
+
owner?: string;
|
|
604
|
+
}): Promise<{
|
|
605
|
+
value_raw: string;
|
|
606
|
+
display?: string;
|
|
607
|
+
decimals?: number;
|
|
608
|
+
}>;
|
|
609
|
+
/** Zero proof for a ciphertext (proves it encrypts the given value, default 0). @since 2.8.0 */
|
|
610
|
+
makeZeroProof(params: {
|
|
611
|
+
cipher: string;
|
|
612
|
+
value_raw?: string;
|
|
613
|
+
token?: string;
|
|
614
|
+
owner?: string;
|
|
615
|
+
}): Promise<{
|
|
616
|
+
proof: string;
|
|
617
|
+
commitment?: string;
|
|
618
|
+
blinding?: string;
|
|
619
|
+
encoding?: string;
|
|
620
|
+
}>;
|
|
621
|
+
/** Range proof for a ciphertext. @since 2.8.0 */
|
|
622
|
+
makeRangeProof(params: {
|
|
623
|
+
cipher: string;
|
|
624
|
+
value_raw: string;
|
|
625
|
+
token?: string;
|
|
626
|
+
owner?: string;
|
|
627
|
+
range?: {
|
|
628
|
+
min_raw: string;
|
|
629
|
+
max_raw: string;
|
|
630
|
+
};
|
|
631
|
+
}): Promise<{
|
|
632
|
+
proof: string;
|
|
633
|
+
encoding?: string;
|
|
634
|
+
}>;
|
|
635
|
+
/** Private OCT + private token balances (decrypted inside the wallet). @since 2.8.0 */
|
|
636
|
+
getPrivateBalance(params?: {
|
|
637
|
+
address?: string;
|
|
638
|
+
assets?: string[];
|
|
639
|
+
tokens?: string[];
|
|
640
|
+
include_claimable?: boolean;
|
|
641
|
+
}): Promise<unknown>;
|
|
642
|
+
/** Register a receive/view public key so an address can receive private transfers. @since 2.8.0 */
|
|
643
|
+
registerPrivateViewKey(params: {
|
|
644
|
+
address: string;
|
|
645
|
+
}): Promise<unknown>;
|
|
646
|
+
/** Submit an ordered multi-step public contract flow under one approval. @since 2.8.0 */
|
|
647
|
+
sendContractTransactionSequence(params: {
|
|
648
|
+
sequence_id?: string;
|
|
649
|
+
transactions: Array<{
|
|
650
|
+
contract: string;
|
|
651
|
+
method: string;
|
|
652
|
+
params?: unknown[];
|
|
653
|
+
amount?: string;
|
|
654
|
+
ou?: string;
|
|
655
|
+
}>;
|
|
656
|
+
}): Promise<unknown>;
|
|
657
|
+
/**
|
|
658
|
+
* Sign an arbitrary message with the wallet's private key.
|
|
659
|
+
* The user will be prompted to approve the signature request in the extension.
|
|
660
|
+
*
|
|
661
|
+
* The wallet does not sign the raw message: it signs the 0xio Signed Message framing
|
|
662
|
+
* (`"Octra Signed Message:\n" + byteLength + "\n" + message`) so a signed message can never be a
|
|
663
|
+
* transaction pre-image. Verify with `verifyMessage(message, signature, publicKey)`, or check an
|
|
664
|
+
* Ed25519 signature against `getSignedMessageBytes(message)` with your own library.
|
|
665
|
+
*
|
|
525
666
|
* @param message - The message to sign (non-empty string)
|
|
526
667
|
* @returns Promise resolving to the base64-encoded Ed25519 signature
|
|
527
668
|
* @throws ZeroXIOWalletError with code SIGNATURE_FAILED if signing fails
|
|
528
669
|
* @example
|
|
529
670
|
* ```typescript
|
|
530
671
|
* const signature = await wallet.signMessage('Hello, 0xio!');
|
|
531
|
-
*
|
|
672
|
+
* const ok = await verifyMessage('Hello, 0xio!', signature, await wallet.getPublicKey());
|
|
532
673
|
* ```
|
|
533
674
|
*/
|
|
534
675
|
signMessage(message: string): Promise<string>;
|
|
@@ -538,7 +679,7 @@ declare class ZeroXIOWallet extends EventEmitter {
|
|
|
538
679
|
* to the calling service and a one-time nonce, preventing cross-service replay attacks.
|
|
539
680
|
*
|
|
540
681
|
* @param service - Identifies the relying service (e.g. 'MyDApp' or 'api.mydapp.com')
|
|
541
|
-
* @param nonce - Unique one-time value
|
|
682
|
+
* @param nonce - Unique one-time value. Use a server-generated UUID or challenge
|
|
542
683
|
* @returns Promise resolving to the base64-encoded Ed25519 signature
|
|
543
684
|
*/
|
|
544
685
|
signAuthMessage(service: string, nonce: string): Promise<string>;
|
|
@@ -551,9 +692,14 @@ declare class ZeroXIOWallet extends EventEmitter {
|
|
|
551
692
|
private handleExtensionLocked;
|
|
552
693
|
private handleExtensionUnlocked;
|
|
553
694
|
private handleTransactionConfirmed;
|
|
695
|
+
/**
|
|
696
|
+
* The wallet takes raw micro-OCT. `amount` passes through unchanged (what every existing
|
|
697
|
+
* dapp sends today); `amountOct` is converted exactly. Never both.
|
|
698
|
+
*/
|
|
699
|
+
private resolveRawAmount;
|
|
554
700
|
/**
|
|
555
701
|
* Reject numeric amounts that cannot be represented exactly in micro-OCT.
|
|
556
|
-
* e.g. 0.1 + 0.2 = 0.30000000000000004
|
|
702
|
+
* e.g. 0.1 + 0.2 = 0.30000000000000004: the extension would sign the wrong value.
|
|
557
703
|
* String amounts bypass this check (caller is responsible for correctness).
|
|
558
704
|
*/
|
|
559
705
|
private assertExactOCTAmount;
|
|
@@ -568,7 +714,7 @@ declare class ExtensionCommunicator extends EventEmitter {
|
|
|
568
714
|
private isExtensionAvailableState;
|
|
569
715
|
private trustedOrigins;
|
|
570
716
|
private _parentOrigin;
|
|
571
|
-
/** Pluggable transport
|
|
717
|
+
/** Pluggable transport, defaults to the 0xio postMessage protocol. */
|
|
572
718
|
private adapter;
|
|
573
719
|
/** Teardown fn returned by adapter.listen() */
|
|
574
720
|
private _adapterTeardown;
|
|
@@ -576,14 +722,14 @@ declare class ExtensionCommunicator extends EventEmitter {
|
|
|
576
722
|
private _adapterReadyTeardown;
|
|
577
723
|
/**
|
|
578
724
|
* Set when a trusted walletReady has been received from window.parent.
|
|
579
|
-
* The polling fallback must
|
|
725
|
+
* The polling fallback must not clear this flag.
|
|
580
726
|
*/
|
|
581
727
|
private _parentTrusted;
|
|
582
728
|
/** walletReady postMessage listener stored for cleanup */
|
|
583
729
|
private _walletReadyMessageListener;
|
|
584
730
|
/**
|
|
585
731
|
* In-flight interactive request lock.
|
|
586
|
-
* Methods that open approval popups are serialized
|
|
732
|
+
* Methods that open approval popups are serialized: only one at a time.
|
|
587
733
|
*/
|
|
588
734
|
private _interactiveInFlight;
|
|
589
735
|
private readonly MAX_CONCURRENT_REQUESTS;
|
|
@@ -595,6 +741,8 @@ declare class ExtensionCommunicator extends EventEmitter {
|
|
|
595
741
|
initialize(): Promise<boolean>;
|
|
596
742
|
isExtensionAvailable(): boolean;
|
|
597
743
|
private static readonly NO_RETRY_METHODS;
|
|
744
|
+
private static readonly LONG_COMPUTE_METHODS;
|
|
745
|
+
private static readonly PROOF_METHODS;
|
|
598
746
|
private static readonly INTERACTIVE_METHODS;
|
|
599
747
|
sendRequest<T = any>(method: string, params?: any, timeout?: number): Promise<T>;
|
|
600
748
|
sendRequestWithRetry<T = any>(method: string, params?: any, maxRetries?: number, timeout?: number): Promise<T>;
|
|
@@ -614,7 +762,7 @@ declare class ExtensionCommunicator extends EventEmitter {
|
|
|
614
762
|
private getExtensionDiagnostics;
|
|
615
763
|
/**
|
|
616
764
|
* Clean up SDK resources.
|
|
617
|
-
* After cleanup() the instance is terminal
|
|
765
|
+
* After cleanup() the instance is terminal: do not call initialize() again.
|
|
618
766
|
* Construct a new instance instead.
|
|
619
767
|
*/
|
|
620
768
|
cleanup(): void;
|
|
@@ -639,7 +787,7 @@ declare class ExtensionCommunicator extends EventEmitter {
|
|
|
639
787
|
* window.postMessage({ source: '0xio-sdk-bridge', response: { id, success, data, error }, sessionNonce })
|
|
640
788
|
* window.postMessage({ source: '0xio-sdk-bridge', event: { type, data } })
|
|
641
789
|
*
|
|
642
|
-
*
|
|
790
|
+
* Session nonce validation: injected.ts broadcasts the nonce received from the
|
|
643
791
|
* isolated content script. Once set, any '0xio-sdk-bridge' response with a missing or
|
|
644
792
|
* mismatched nonce is rejected, preventing response injection by malicious page scripts.
|
|
645
793
|
*/
|
|
@@ -657,7 +805,7 @@ declare const ZeroXIOAdapter: WalletTransportAdapter;
|
|
|
657
805
|
*
|
|
658
806
|
* Targets any wallet that exposes `window.octra` per the RFC-O-1 specification:
|
|
659
807
|
* window.octra.isOctra === true
|
|
660
|
-
* window.octra.request({ method, params })
|
|
808
|
+
* window.octra.request({ method, params }) returns Promise<unknown>
|
|
661
809
|
* window.octra.on(event, listener) / removeListener(event, listener)
|
|
662
810
|
*
|
|
663
811
|
* This adapter translates the SDK's internal method names into RFC-O-1 method
|
|
@@ -672,7 +820,7 @@ declare function createOctraProviderAdapter(): WalletTransportAdapter;
|
|
|
672
820
|
declare const OctraProviderAdapter: WalletTransportAdapter;
|
|
673
821
|
|
|
674
822
|
/**
|
|
675
|
-
* 0xio SDK
|
|
823
|
+
* 0xio SDK: Wallet Adapter Registry
|
|
676
824
|
*
|
|
677
825
|
* Add new wallet adapters here. Detection order determines which wallet takes
|
|
678
826
|
* priority when multiple wallets are installed at the same time.
|
|
@@ -691,6 +839,19 @@ declare function detectWalletAdapter(): WalletTransportAdapter | null;
|
|
|
691
839
|
/** Returns all registered adapter instances. */
|
|
692
840
|
declare function getAllAdapters(): WalletTransportAdapter[];
|
|
693
841
|
|
|
842
|
+
/** Scope names the 0xio wallet enforces. Any other name is dropped at connect. */
|
|
843
|
+
declare const WALLET_PERMISSIONS: readonly ["accounts", "public_transactions", "contract_calls", "contract_views", "private_balance_read", "private_proofs", "private_transfers", "private_claims"];
|
|
844
|
+
type WalletPermission = (typeof WALLET_PERMISSIONS)[number];
|
|
845
|
+
/** Older SDK permission names and the wallet scope each one means. */
|
|
846
|
+
declare const LEGACY_PERMISSION_MAP: Record<string, WalletPermission>;
|
|
847
|
+
/** Translate any mix of old and new names into the wallet's scope names, without duplicates. */
|
|
848
|
+
declare function toWalletPermissions(perms: readonly string[] | undefined): WalletPermission[];
|
|
849
|
+
/**
|
|
850
|
+
* The granted wallet scopes plus every requested old name they satisfy, so a dapp that checks
|
|
851
|
+
* for the name it asked for (for example 'read_balance') keeps seeing it.
|
|
852
|
+
*/
|
|
853
|
+
declare function withLegacyAliases(granted: readonly string[] | undefined, requested: readonly string[] | undefined): Permission[];
|
|
854
|
+
|
|
694
855
|
/**
|
|
695
856
|
* Network configuration for 0xio SDK
|
|
696
857
|
*/
|
|
@@ -703,12 +864,12 @@ declare const NETWORKS: Readonly<Record<string, Readonly<NetworkInfo>>>;
|
|
|
703
864
|
declare const DEFAULT_NETWORK_ID = "mainnet";
|
|
704
865
|
/**
|
|
705
866
|
* Get network configuration by ID.
|
|
706
|
-
* Returns a frozen copy
|
|
867
|
+
* Returns a frozen copy, so callers cannot mutate SDK-internal state.
|
|
707
868
|
*/
|
|
708
869
|
declare function getNetworkConfig(networkId?: string): NetworkInfo;
|
|
709
870
|
/**
|
|
710
871
|
* Get all available networks.
|
|
711
|
-
* Returns frozen copies
|
|
872
|
+
* Returns frozen copies, so callers cannot mutate SDK-internal state.
|
|
712
873
|
*/
|
|
713
874
|
declare function getAllNetworks(): NetworkInfo[];
|
|
714
875
|
/**
|
|
@@ -718,11 +879,11 @@ declare function isValidNetworkId(networkId: string): boolean;
|
|
|
718
879
|
|
|
719
880
|
/**
|
|
720
881
|
* Default balance structure.
|
|
721
|
-
* Accepts a numeric total or undefined
|
|
882
|
+
* Accepts a numeric total or undefined. Never pass a Balance object here.
|
|
722
883
|
*/
|
|
723
884
|
declare function createDefaultBalance(total?: number): Balance;
|
|
724
885
|
declare const SDK_CONFIG: {
|
|
725
|
-
readonly version: "2.
|
|
886
|
+
readonly version: "2.8.0";
|
|
726
887
|
readonly defaultNetworkId: "mainnet";
|
|
727
888
|
readonly communicationTimeout: 30000;
|
|
728
889
|
readonly retryAttempts: 3;
|
|
@@ -741,7 +902,7 @@ declare function isValidMessage(message: string): boolean;
|
|
|
741
902
|
declare function isValidFeeLevel(feeLevel: number): boolean;
|
|
742
903
|
/**
|
|
743
904
|
* Derive the canonical Octra address from a base64-encoded Ed25519 public key.
|
|
744
|
-
* Algorithm: SHA-256
|
|
905
|
+
* Algorithm: SHA-256 of the pubkey bytes, base58-encoded, with "oct" prepended
|
|
745
906
|
* Source of truth: ocho-push-server/src/index.ts#deriveAddressFromPubkey
|
|
746
907
|
*/
|
|
747
908
|
declare function deriveOctraAddress(publicKeyBase64: string): Promise<string>;
|
|
@@ -750,6 +911,11 @@ declare function formatAddress(address: string, prefixLength?: number, suffixLen
|
|
|
750
911
|
declare function formatTimestamp(timestamp: number): string;
|
|
751
912
|
declare function formatTxHash(hash: string, length?: number): string;
|
|
752
913
|
declare function toMicroOCT(amount: number): string;
|
|
914
|
+
/**
|
|
915
|
+
* Exact OCT to raw micro-OCT conversion using string arithmetic (no float rounding).
|
|
916
|
+
* Accepts up to 6 decimals; anything else is rejected.
|
|
917
|
+
*/
|
|
918
|
+
declare function octToMicro(amount: string | number): string;
|
|
753
919
|
declare function fromMicroOCT(microAmount: string | number): number;
|
|
754
920
|
declare function createErrorMessage(code: ErrorCode, context?: string): string;
|
|
755
921
|
declare function isErrorType(error: any, code: ErrorCode): boolean;
|
|
@@ -789,7 +955,50 @@ declare function createLogger(prefix: string, debug: boolean): {
|
|
|
789
955
|
groupEnd: () => void;
|
|
790
956
|
};
|
|
791
957
|
|
|
792
|
-
|
|
958
|
+
/**
|
|
959
|
+
* 0xio Signed Message standard (v1).
|
|
960
|
+
*
|
|
961
|
+
* `wallet.signMessage(message)` never signs the raw message. The wallet frames it first so a signed
|
|
962
|
+
* "message" can never collide with a transaction pre-image (a transaction is canonical JSON that
|
|
963
|
+
* begins with '{'). The framing is:
|
|
964
|
+
*
|
|
965
|
+
* "Octra Signed Message:\n" + utf8ByteLength(message) + "\n" + message
|
|
966
|
+
*
|
|
967
|
+
* signed as an Ed25519 detached signature over the UTF-8 bytes of that string. The leading 'O'
|
|
968
|
+
* guarantees the signed bytes never begin with '{', so a personal-message signature can never be a
|
|
969
|
+
* valid transaction. Any verifier MUST reconstruct the same bytes: use `getSignedMessageBytes()`
|
|
970
|
+
* with any Ed25519 library, or `verifyMessage()` for a batteries-included check.
|
|
971
|
+
*/
|
|
972
|
+
/** Fixed prefix tag for the 0xio Signed Message scheme. */
|
|
973
|
+
declare const SIGNED_MESSAGE_PREFIX = "Octra Signed Message:";
|
|
974
|
+
/** Scheme version, bumped if the framing ever changes so verifiers can detect it. */
|
|
975
|
+
declare const SIGNED_MESSAGE_VERSION = 1;
|
|
976
|
+
/**
|
|
977
|
+
* The exact bytes that `wallet.signMessage(message)` produces a signature over. Verify a 0xio
|
|
978
|
+
* message signature by checking an Ed25519 signature against these bytes with the signer's public
|
|
979
|
+
* key. Zero-dependency - bring your own Ed25519 verifier, or use `verifyMessage`.
|
|
980
|
+
*/
|
|
981
|
+
declare function getSignedMessageBytes(message: string): Uint8Array;
|
|
982
|
+
/**
|
|
983
|
+
* Reconstruct the auth message that `wallet.signAuthMessage(service, nonce)` signs. A relying
|
|
984
|
+
* service verifies an auth signature with `verifyMessage(buildAuthMessage(service, nonce, origin),
|
|
985
|
+
* signature, publicKey)`, where `origin` is the caller's page origin.
|
|
986
|
+
*/
|
|
987
|
+
declare function buildAuthMessage(service: string, nonce: string, origin: string): string;
|
|
988
|
+
/**
|
|
989
|
+
* Verify a 0xio message signature produced by `wallet.signMessage`.
|
|
990
|
+
*
|
|
991
|
+
* @param message The original message passed to `wallet.signMessage`.
|
|
992
|
+
* @param signature Base64 Ed25519 signature returned by `wallet.signMessage`.
|
|
993
|
+
* @param publicKey Base64 Ed25519 public key of the signer (from `wallet.getPublicKey()`).
|
|
994
|
+
* @returns Whether the signature is valid for this message and key.
|
|
995
|
+
*
|
|
996
|
+
* Uses the Web Crypto Ed25519 primitive (Node 18+, Chrome 137+, Safari 17+, Firefox 129+). In an
|
|
997
|
+
* environment without it, verify `getSignedMessageBytes(message)` with your own Ed25519 library.
|
|
998
|
+
*/
|
|
999
|
+
declare function verifyMessage(message: string, signature: string, publicKey: string): Promise<boolean>;
|
|
1000
|
+
|
|
1001
|
+
declare const SDK_VERSION = "2.8.0";
|
|
793
1002
|
declare const MIN_EXTENSION_VERSION = "2.0.1";
|
|
794
1003
|
declare const MIN_EXTENSION_VERSION_DEVNET = "2.2.1";
|
|
795
1004
|
declare const SUPPORTED_EXTENSION_VERSIONS = "^2.0.1";
|
|
@@ -806,5 +1015,5 @@ declare function checkSDKCompatibility(): {
|
|
|
806
1015
|
recommendations: string[];
|
|
807
1016
|
};
|
|
808
1017
|
|
|
809
|
-
export { DEFAULT_NETWORK_ID, ErrorCode, EventEmitter, ExtensionCommunicator, MIN_EXTENSION_VERSION, MIN_EXTENSION_VERSION_DEVNET, NETWORKS, OctraProviderAdapter, SDK_CONFIG, SDK_VERSION, SUPPORTED_EXTENSION_VERSIONS, ZeroXIOAdapter, ZeroXIOWallet, ZeroXIOWalletError, checkBrowserSupport, checkSDKCompatibility, createDefaultBalance, createErrorMessage, createLogger, createOctraProviderAdapter, createZeroXIOAdapter, createZeroXIOWallet, delay, deriveOctraAddress, detectWalletAdapter, formatAddress, formatOCT, formatTimestamp, formatTxHash, formatOCT as formatZeroXIO, fromMicroOCT, fromMicroOCT as fromMicroZeroXIO, generateMockData, getAllAdapters, getAllNetworks, getDefaultNetwork, getNetworkConfig, isBrowser, isErrorType, isValidAddress, isValidAmount, isValidFeeLevel, isValidMessage, isValidNetworkId, toMicroOCT, toMicroOCT as toMicroZeroXIO };
|
|
810
|
-
export type { AccountChangedEvent, AdapterIncomingMessage, AdapterRequest, Balance, BalanceChangedEvent, ConnectEvent, ConnectOptions, ConnectionInfo, ContractCallData, ContractParam, ContractParams, ContractViewCallData, DisconnectEvent, ErrorEvent, ExtensionRequest, ExtensionResponse, NetworkChangedEvent, NetworkInfo, PendingPrivateTransfer, Permission, PrivateBalanceInfo, PrivateTransferData, SDKConfig, SignedTransaction, Transaction, TransactionConfirmedEvent, TransactionData, TransactionFinality, TransactionHistory, TransactionResult, WalletAddress, WalletEvent, WalletEventType, WalletTransportAdapter };
|
|
1018
|
+
export { DEFAULT_NETWORK_ID, ErrorCode, EventEmitter, ExtensionCommunicator, LEGACY_PERMISSION_MAP, MIN_EXTENSION_VERSION, MIN_EXTENSION_VERSION_DEVNET, NETWORKS, OctraProviderAdapter, SDK_CONFIG, SDK_VERSION, SIGNED_MESSAGE_PREFIX, SIGNED_MESSAGE_VERSION, SUPPORTED_EXTENSION_VERSIONS, WALLET_PERMISSIONS, ZeroXIOAdapter, ZeroXIOWallet, ZeroXIOWalletError, buildAuthMessage, checkBrowserSupport, checkSDKCompatibility, createDefaultBalance, createErrorMessage, createLogger, createOctraProviderAdapter, createZeroXIOAdapter, createZeroXIOWallet, delay, deriveOctraAddress, detectWalletAdapter, formatAddress, formatOCT, formatTimestamp, formatTxHash, formatOCT as formatZeroXIO, fromMicroOCT, fromMicroOCT as fromMicroZeroXIO, generateMockData, getAllAdapters, getAllNetworks, getDefaultNetwork, getNetworkConfig, getSignedMessageBytes, isBrowser, isErrorType, isValidAddress, isValidAmount, isValidFeeLevel, isValidMessage, isValidNetworkId, octToMicro, toMicroOCT, toMicroOCT as toMicroZeroXIO, toWalletPermissions, verifyMessage, withLegacyAliases };
|
|
1019
|
+
export type { AccountChangedEvent, AdapterIncomingMessage, AdapterRequest, Balance, BalanceChangedEvent, ConnectEvent, ConnectOptions, ConnectionInfo, ContractCallData, ContractParam, ContractParams, ContractViewCallData, DisconnectEvent, ErrorEvent, ExtensionRequest, ExtensionResponse, NetworkChangedEvent, NetworkInfo, PendingPrivateTransfer, Permission, PrivateBalanceInfo, PrivateTransferData, SDKConfig, SignedTransaction, Transaction, TransactionConfirmedEvent, TransactionData, TransactionFinality, TransactionHistory, TransactionResult, WalletAddress, WalletEvent, WalletEventType, WalletPermission, WalletTransportAdapter };
|