@sodax/wallet-sdk-core 2.0.0-rc.1 → 2.0.0-rc.2

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 (50) hide show
  1. package/ai-exported/AGENTS.md +139 -0
  2. package/ai-exported/integration/README.md +108 -0
  3. package/ai-exported/integration/ai-rules.md +141 -0
  4. package/ai-exported/integration/architecture.md +212 -0
  5. package/ai-exported/integration/features/README.md +22 -0
  6. package/ai-exported/integration/features/bitcoin.md +103 -0
  7. package/ai-exported/integration/features/evm.md +102 -0
  8. package/ai-exported/integration/features/icon.md +88 -0
  9. package/ai-exported/integration/features/injective.md +92 -0
  10. package/ai-exported/integration/features/near.md +92 -0
  11. package/ai-exported/integration/features/solana.md +104 -0
  12. package/ai-exported/integration/features/stacks.md +91 -0
  13. package/ai-exported/integration/features/stellar.md +95 -0
  14. package/ai-exported/integration/features/sui.md +96 -0
  15. package/ai-exported/integration/quickstart.md +259 -0
  16. package/ai-exported/integration/recipes/README.md +15 -0
  17. package/ai-exported/integration/recipes/bridge-to-sdk.md +145 -0
  18. package/ai-exported/integration/recipes/defaults-and-overrides.md +159 -0
  19. package/ai-exported/integration/recipes/library-exports.md +129 -0
  20. package/ai-exported/integration/recipes/setup-browser-extension.md +137 -0
  21. package/ai-exported/integration/recipes/setup-private-key.md +115 -0
  22. package/ai-exported/integration/recipes/sign-and-broadcast.md +201 -0
  23. package/ai-exported/integration/recipes/testing.md +163 -0
  24. package/ai-exported/integration/reference/README.md +13 -0
  25. package/ai-exported/integration/reference/chain-support.md +65 -0
  26. package/ai-exported/integration/reference/glossary.md +28 -0
  27. package/ai-exported/integration/reference/interfaces.md +131 -0
  28. package/ai-exported/integration/reference/provider-classes.md +54 -0
  29. package/ai-exported/integration/reference/public-api.md +128 -0
  30. package/ai-exported/migration/README.md +84 -0
  31. package/ai-exported/migration/ai-rules.md +139 -0
  32. package/ai-exported/migration/breaking-changes/README.md +14 -0
  33. package/ai-exported/migration/breaking-changes/base-wallet-provider.md +52 -0
  34. package/ai-exported/migration/breaking-changes/defaults-config.md +57 -0
  35. package/ai-exported/migration/breaking-changes/folder-layout.md +99 -0
  36. package/ai-exported/migration/breaking-changes/library-exports.md +58 -0
  37. package/ai-exported/migration/checklist.md +62 -0
  38. package/ai-exported/migration/recipes/README.md +12 -0
  39. package/ai-exported/migration/recipes/adopt-defaults.md +84 -0
  40. package/ai-exported/migration/recipes/adopt-library-exports.md +99 -0
  41. package/ai-exported/migration/reference/README.md +12 -0
  42. package/ai-exported/migration/reference/added-fields.md +71 -0
  43. package/ai-exported/migration/reference/deleted-exports.md +35 -0
  44. package/ai-exported/migration/reference/renamed-symbols.md +31 -0
  45. package/ai-exported/migration/reference/return-shapes.md +23 -0
  46. package/dist/index.cjs +1 -1
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.mjs +1 -1
  49. package/dist/index.mjs.map +1 -1
  50. package/package.json +5 -4
@@ -0,0 +1,103 @@
1
+ # Bitcoin — `BitcoinWalletProvider`
2
+
3
+ Backed by `bitcoinjs-lib` (PSBT signing), `ecpair`, and `@bitcoinerlab/secp256k1`.
4
+
5
+ | | |
6
+ |---|---|
7
+ | Class | `BitcoinWalletProvider` |
8
+ | Interface | `IBitcoinWalletProvider` (from `@sodax/types`) |
9
+ | Discriminant style | **Explicit uppercase `type`** (`'PRIVATE_KEY' \| 'BROWSER_EXTENSION'`) |
10
+ | Underlying SDK | `bitcoinjs-lib`, `ecpair`, `bip322-js` |
11
+
12
+ ---
13
+
14
+ ## Config
15
+
16
+ ```ts
17
+ type BitcoinWalletConfig = PrivateKeyBitcoinWalletConfig | BrowserExtensionBitcoinWalletConfig;
18
+
19
+ type PrivateKeyBitcoinWalletConfig = {
20
+ type: 'PRIVATE_KEY';
21
+ privateKey: Hex; // `0x…` from @sodax/types
22
+ network: 'TESTNET' | 'MAINNET';
23
+ addressType?: BtcAddressType; // P2WPKH / P2TR / P2SH / P2PKH — default chosen by lib
24
+ defaults?: BitcoinWalletDefaults;
25
+ };
26
+
27
+ type BrowserExtensionBitcoinWalletConfig = {
28
+ type: 'BROWSER_EXTENSION';
29
+ walletsKit: BitcoinWalletsKit; // consumer-provided adapter
30
+ network: 'TESTNET' | 'MAINNET';
31
+ defaults?: BitcoinWalletDefaults;
32
+ };
33
+
34
+ interface BitcoinWalletsKit {
35
+ getAccounts(): Promise<string[]>;
36
+ signPsbt(psbtHex: string): Promise<{ psbtHex: string }>;
37
+ signMessage(message: string): Promise<string>;
38
+ signEcdsaMessage(message: string): Promise<string>;
39
+ signBip322Message(message: string): Promise<string>;
40
+ getPublicKey(): Promise<string>;
41
+ sendBitcoin?(toAddress: string, satoshis: number): Promise<string>;
42
+ }
43
+ ```
44
+
45
+ | Mode discriminant | How to detect |
46
+ |---|---|
47
+ | Private-key | `config.type === 'PRIVATE_KEY'` |
48
+ | Browser-extension | `config.type === 'BROWSER_EXTENSION'` |
49
+
50
+ ---
51
+
52
+ ## `BitcoinWalletDefaults`
53
+
54
+ ```ts
55
+ type BitcoinWalletDefaults = {
56
+ defaultFinalize?: boolean; // default true — finalise after signing
57
+ };
58
+ ```
59
+
60
+ Read directly via `this.defaults.defaultFinalize` — no `mergePolicy` / `mergeDefaults` call. Per-call `finalize` argument on `signTransaction` overrides the default; if both are omitted the implementation falls back to `true`.
61
+
62
+ ---
63
+
64
+ ## Methods
65
+
66
+ | Method | Signature | Returns |
67
+ |---|---|---|
68
+ | `getWalletAddress` | `() => Promise<string>` | BTC address (per address type) |
69
+ | `getPublicKey` | `() => Promise<string>` | hex public key |
70
+ | `getAddressType` | `(address: string) => Promise<BtcAddressType>` | inferred type |
71
+ | `signTransaction` | `(psbtBase64: string, finalize?: boolean) => Promise<string>` | signed PSBT (or finalised tx hex) |
72
+ | `signEcdsaMessage` | `(message: string) => Promise<string>` | ECDSA signature |
73
+ | `signBip322Message` | `(message: string) => Promise<string>` | BIP-322 signature |
74
+ | `getPayment` | `(keyPair, addressType) => bitcoin.Payment` | bitcoinjs `Payment` (PK mode helper) |
75
+ | `sendBitcoin` | `(toAddress: string, satoshis: bigint) => Promise<string>` | tx hash — only available in browser-extension mode if `walletsKit.sendBitcoin` is implemented |
76
+
77
+ ---
78
+
79
+ ## Public fields
80
+
81
+ | Field | Type | Notes |
82
+ |---|---|---|
83
+ | `chainType` | `'BITCOIN'` (literal) | Discriminant. |
84
+
85
+ `wallet`, `network` are private. Read the network via the constructor argument.
86
+
87
+ ---
88
+
89
+ ## Gotchas
90
+
91
+ - **The discriminant is `type`, uppercase.** Bitcoin and Stellar use this style — every other chain uses field presence. Easy to confuse.
92
+ - **`addressType` is optional in PK mode.** If you omit it, bitcoinjs picks a default (typically P2WPKH on mainnet). Browser-extension mode infers it from the wallet kit.
93
+ - **PSBT inputs are base64-encoded** when passed to `signTransaction`. In browser-extension mode the same base64 string is forwarded to `walletsKit.signPsbt`; the kit's parameter is misleadingly named `psbtHex` but receives base64. The kit returns a signed PSBT which the provider parses as hex when finalising.
94
+ - **`sendBitcoin` is optional on the wallet kit.** Some browser-extension wallets (Xverse / Unisat) implement it; others don't. Guard on its presence.
95
+ - **`signEcdsaMessage` vs `signBip322Message`** — choose based on what your verifier expects. BIP-322 is the more modern, structured signature spec; ECDSA is the legacy `signmessage` RPC behavior.
96
+
97
+ ---
98
+
99
+ ## See also
100
+
101
+ - [`recipes/setup-private-key.md`](../recipes/setup-private-key.md)
102
+ - [`recipes/setup-browser-extension.md`](../recipes/setup-browser-extension.md)
103
+ - [`recipes/sign-and-broadcast.md`](../recipes/sign-and-broadcast.md)
@@ -0,0 +1,102 @@
1
+ # EVM — `EvmWalletProvider`
2
+
3
+ Backed by [viem](https://viem.sh). One class covers all **12** SODAX EVM spoke chains via `getEvmViemChain()`.
4
+
5
+ | | |
6
+ |---|---|
7
+ | Class | `EvmWalletProvider` |
8
+ | Interface | `IEvmWalletProvider` (from `@sodax/types`) |
9
+ | Discriminant style | **Field presence** (no `type` field) |
10
+ | Underlying SDK | `viem` |
11
+ | Supported chains | Sonic (hub), Ethereum, Arbitrum, Base, BSC, Optimism, Polygon, Avalanche, HyperEVM, Lightlink, Redbelly, Kaia |
12
+
13
+ ---
14
+
15
+ ## Config
16
+
17
+ ```ts
18
+ type EvmWalletConfig = PrivateKeyEvmWalletConfig | BrowserExtensionEvmWalletConfig;
19
+
20
+ type PrivateKeyEvmWalletConfig = {
21
+ privateKey: `0x${string}`;
22
+ chainId: EvmChainKey; // ChainKeys.SONIC_MAINNET, …
23
+ rpcUrl?: `http${string}`; // defaults to viem chain's first public RPC
24
+ defaults?: EvmWalletDefaults;
25
+ };
26
+
27
+ type BrowserExtensionEvmWalletConfig = {
28
+ walletClient: WalletClient<Transport, Chain, Account>; // pre-built by wagmi / consumer
29
+ publicClient: PublicClient;
30
+ defaults?: EvmWalletDefaults;
31
+ };
32
+ ```
33
+
34
+ | Mode discriminant | How to detect |
35
+ |---|---|
36
+ | Private-key | `'privateKey' in config` AND `config.privateKey.startsWith('0x')` |
37
+ | Browser-extension | `'walletClient' in config` AND `'publicClient' in config` |
38
+
39
+ Helper predicates `isPrivateKeyEvmWalletConfig` and `isBrowserExtensionEvmWalletConfig` are exported.
40
+
41
+ ---
42
+
43
+ ## `EvmWalletDefaults`
44
+
45
+ ```ts
46
+ type EvmWalletDefaults = {
47
+ publicClient?: Partial<Omit<PublicClientConfig, 'transport' | 'chain'>>;
48
+ walletClient?: Partial<Omit<WalletClientConfig, 'transport' | 'chain' | 'account'>>;
49
+ transport?: HttpTransportConfig;
50
+ sendTransaction?: EvmSendTransactionPolicy; // Omit<Partial<SendTransactionParameters>, keyof EvmRawTransaction>
51
+ waitForTransactionReceipt?: EvmWaitForTransactionReceiptPolicy; // Partial<Omit<WaitForTransactionReceiptParameters, 'hash'>>
52
+ };
53
+ ```
54
+
55
+ | Default slice | Used by | Effective only in |
56
+ |---|---|---|
57
+ | `publicClient`, `walletClient`, `transport` | constructor | Private-key mode |
58
+ | `sendTransaction` | `sendTransaction()` | Both modes |
59
+ | `waitForTransactionReceipt` | `waitForTransactionReceipt()` | Both modes |
60
+
61
+ > In browser-extension mode, `publicClient` / `walletClient` / `transport` defaults are **ignored** — the provider logs a one-time `console.warn`. Pass them only in private-key mode.
62
+
63
+ ---
64
+
65
+ ## Methods
66
+
67
+ | Method | Signature | Returns | Default slice merged |
68
+ |---|---|---|---|
69
+ | `getWalletAddress` | `() => Promise<Address>` | viem `Address` (`` `0x${string}` ``) | — |
70
+ | `sendTransaction` | `(txData: EvmRawTransaction, options?: EvmSendTransactionPolicy) => Promise<Hash>` | viem `Hash` | `defaults.sendTransaction` |
71
+ | `waitForTransactionReceipt` | `(txHash: Hash, options?: EvmWaitForTransactionReceiptPolicy) => Promise<EvmRawTransactionReceipt>` | bigint-stringified receipt | `defaults.waitForTransactionReceipt` |
72
+
73
+ The serialised receipt converts all `bigint` fields to `string` so it can be `JSON.stringify`'d safely. This is enforced at the type level — `EvmRawTransactionReceipt` (from `@sodax/types`) is the stringified shape.
74
+
75
+ ---
76
+
77
+ ## Public fields
78
+
79
+ | Field | Type | Notes |
80
+ |---|---|---|
81
+ | `chainType` | `'EVM'` (literal) | Discriminant for `IXxxWalletProvider` unions. |
82
+ | `publicClient` | `PublicClient` | Either built from `rpcUrl` (PK mode) or the caller's instance (browser mode). |
83
+
84
+ `walletClient` is private — call `sendTransaction()` instead of touching it directly.
85
+
86
+ ---
87
+
88
+ ## Gotchas
89
+
90
+ - **`getEvmViemChain` is exhaustive.** If `@sodax/types` adds a new `EvmChainKey`, this function fails to typecheck until the case is added — by design.
91
+ - **HyperEVM is defined inside this package.** `viem/chains` does not ship a HyperEVM config; `wallet-providers/evm/EvmWalletProvider.ts` exports `hyper` via `defineChain`. You shouldn't need it directly — `getEvmViemChain(ChainKeys.HYPEREVM_MAINNET)` returns it.
92
+ - **`rpcUrl` falls back to the viem chain's first public RPC.** Fine for testing — replace with a private RPC for production.
93
+ - **No nonce management.** The provider does not auto-increment / serialise sends. If you fire multiple txs in parallel from the same account, manage nonces yourself via `defaults.sendTransaction.nonce` or per-call `options.nonce`.
94
+
95
+ ---
96
+
97
+ ## See also
98
+
99
+ - [`recipes/setup-private-key.md`](../recipes/setup-private-key.md)
100
+ - [`recipes/setup-browser-extension.md`](../recipes/setup-browser-extension.md)
101
+ - [`recipes/sign-and-broadcast.md`](../recipes/sign-and-broadcast.md)
102
+ - [`recipes/defaults-and-overrides.md`](../recipes/defaults-and-overrides.md)
@@ -0,0 +1,88 @@
1
+ # ICON — `IconWalletProvider`
2
+
3
+ Backed by `icon-sdk-js`. Browser-extension mode targets the Hana wallet's `postMessage` JSON-RPC bridge.
4
+
5
+ | | |
6
+ |---|---|
7
+ | Class | `IconWalletProvider` |
8
+ | Interface | `IIconWalletProvider` (from `@sodax/types`) |
9
+ | Discriminant style | **Field presence** (no `type` field) |
10
+ | Underlying SDK | `icon-sdk-js` |
11
+
12
+ ---
13
+
14
+ ## Config
15
+
16
+ ```ts
17
+ type IconWalletConfig = PrivateKeyIconWalletConfig | BrowserExtensionIconWalletConfig;
18
+
19
+ type PrivateKeyIconWalletConfig = {
20
+ privateKey: `0x${string}`;
21
+ rpcUrl: `http${string}`;
22
+ defaults?: IconWalletDefaults;
23
+ };
24
+
25
+ type BrowserExtensionIconWalletConfig = {
26
+ walletAddress?: IconEoaAddress; // `hx…` — optional; resolved at first sign call if omitted
27
+ rpcUrl: `http${string}`;
28
+ defaults?: IconWalletDefaults;
29
+ };
30
+ ```
31
+
32
+ | Mode discriminant | How to detect |
33
+ |---|---|
34
+ | Private-key | `'privateKey' in config` |
35
+ | Browser-extension | `'walletAddress' in config` OR `!('privateKey' in config)` (defaults to browser-extension when key absent) |
36
+
37
+ > `rpcUrl` is **required in both modes** — ICON has no public-RPC fallback in the provider.
38
+
39
+ ---
40
+
41
+ ## `IconWalletDefaults`
42
+
43
+ ```ts
44
+ type IconWalletDefaults = {
45
+ stepLimit?: number; // default 3_000_000
46
+ version?: string; // default '0x3'
47
+ timestampProvider?: () => number; // default Date.now() * 1000 (microseconds)
48
+ jsonRpcId?: number; // default 99999 (browser-extension event ID)
49
+ };
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Methods
55
+
56
+ | Method | Signature | Returns | Default slice merged |
57
+ |---|---|---|---|
58
+ | `getWalletAddress` | `() => Promise<IconEoaAddress>` | `hx…` address | — |
59
+ | `sendTransaction` | `(tx: IcxCallTransaction, options?: IconWalletDefaults) => Promise<Hash>` | tx hash | `defaults` (flat merge via `mergeDefaults`) |
60
+ | `waitForTransactionReceipt` | `(txHash: Hash) => Promise<IconTransactionResult>` | tx result | — |
61
+
62
+ ---
63
+
64
+ ## Public fields
65
+
66
+ | Field | Type | Notes |
67
+ |---|---|---|
68
+ | `chainType` | `'ICON'` (literal) | Discriminant. |
69
+ | `iconService` | `IconService` | Underlying SDK service — exposed for advanced use. |
70
+
71
+ `wallet` is private.
72
+
73
+ ---
74
+
75
+ ## Gotchas
76
+
77
+ - **Browser-extension mode talks to Hana via `window.postMessage`.** Events use a request-ID — collisions can occur if you fire many parallel calls; tune `defaults.jsonRpcId` if you control the consumer.
78
+ - **`walletAddress` is optional in browser-extension mode.** When omitted, the provider issues a `REQUEST_ADDRESS` event on first use to resolve it. For deterministic behavior in scripts, pass it explicitly.
79
+ - **Address type is branded — `IconEoaAddress` (`hx…`) vs `IconAddress` (`hx… | cx…`).** EOA only at the wallet level; contracts (`cx…`) appear inside tx params, not as the signer.
80
+ - **Timestamps are microseconds.** `timestampProvider` returns microseconds, not milliseconds — the default is `Date.now() * 1000`.
81
+
82
+ ---
83
+
84
+ ## See also
85
+
86
+ - [`recipes/setup-private-key.md`](../recipes/setup-private-key.md)
87
+ - [`recipes/setup-browser-extension.md`](../recipes/setup-browser-extension.md)
88
+ - [`recipes/sign-and-broadcast.md`](../recipes/sign-and-broadcast.md)
@@ -0,0 +1,92 @@
1
+ # Injective — `InjectiveWalletProvider`
2
+
3
+ Backed by `@injectivelabs/sdk-ts` (signing / msg construction) and `@injectivelabs/wallet-core` (`MsgBroadcaster` for browser flows).
4
+
5
+ | | |
6
+ |---|---|
7
+ | Class | `InjectiveWalletProvider` |
8
+ | Interface | `IInjectiveWalletProvider` (from `@sodax/types`) |
9
+ | Discriminant style | **Field presence** — but PK variant uses a nested `secret` wrapper |
10
+ | Underlying SDK | `@injectivelabs/sdk-ts`, `@injectivelabs/wallet-core`, `@injectivelabs/networks`, `@injectivelabs/ts-types` |
11
+
12
+ ---
13
+
14
+ ## Config
15
+
16
+ ```ts
17
+ type InjectiveWalletConfig = BrowserExtensionInjectiveWalletConfig | SecretInjectiveWalletConfig;
18
+
19
+ type BrowserExtensionInjectiveWalletConfig = {
20
+ msgBroadcaster: MsgBroadcaster; // pre-configured by consumer
21
+ defaults?: InjectiveWalletDefaults;
22
+ };
23
+
24
+ type SecretInjectiveWalletConfig = {
25
+ secret: { privateKey: string } | { mnemonics: string };
26
+ chainId: ChainId; // from @injectivelabs/ts-types
27
+ network: Network; // from @injectivelabs/networks
28
+ evmOptions?: { evmChainId: EvmChainId; rpcUrl: `http${string}` }; // reserved — currently unused
29
+ defaults?: InjectiveWalletDefaults;
30
+ };
31
+ ```
32
+
33
+ | Mode discriminant | How to detect |
34
+ |---|---|
35
+ | Browser-extension | `'msgBroadcaster' in config` |
36
+ | Secret (private-key OR mnemonics) | `'secret' in config` |
37
+
38
+ > Note the naming: the second variant is `SecretInjectiveWalletConfig` (not `PrivateKey…`) because it accepts **either** a private key **or** a BIP-39 mnemonic at the `secret` slot. The dual credential shape mirrors `PrivateKey.fromPrivateKey` / `PrivateKey.fromMnemonic` in `@injectivelabs/sdk-ts`.
39
+
40
+ ---
41
+
42
+ ## `InjectiveWalletDefaults`
43
+
44
+ ```ts
45
+ type InjectiveWalletDefaults = {
46
+ defaultFunds?: InjectiveCoin[]; // attached to getRawTransaction/execute if caller omits
47
+ defaultMemo?: string; // default tx memo
48
+ sequence?: number; // createTransaction override — default 0
49
+ accountNumber?: number; // createTransaction override — default 0
50
+ };
51
+ ```
52
+
53
+ > `MsgBroadcaster` options apply at **construction time only** (private-key path). The upstream `MsgBroadcasterWithPk` does not support post-construction reconfig.
54
+
55
+ ---
56
+
57
+ ## Methods
58
+
59
+ | Method | Signature | Returns |
60
+ |---|---|---|
61
+ | `getWalletAddress` | `() => Promise<InjectiveEoaAddress>` | `inj1…` address |
62
+ | `getWalletPubKey` | `() => Promise<string>` | hex pubkey |
63
+ | `getRawTransaction` | `(…) => Promise<…>` | unsigned tx — useful for inspection / external signing |
64
+ | `execute` | `(…) => Promise<…>` | broadcast result |
65
+
66
+ `getRawTransaction` and `execute` merge `defaults.defaultFunds`, `defaults.defaultMemo`, `defaults.sequence`, `defaults.accountNumber` into the produced tx where the caller omits them.
67
+
68
+ ---
69
+
70
+ ## Public fields
71
+
72
+ | Field | Type | Notes |
73
+ |---|---|---|
74
+ | `chainType` | `'INJECTIVE'` (literal) | Discriminant. |
75
+ | `wallet` | `InjectiveWallet` | `{ msgBroadcaster: MsgBroadcaster \| MsgBroadcasterWithPk }` — exposed for advanced consumers. |
76
+
77
+ ---
78
+
79
+ ## Gotchas
80
+
81
+ - **`secret` is mandatory in the PK variant.** A top-level `privateKey` field is **not** accepted — wrap in `{ secret: { privateKey } }`. Same shape in v1 and v2; if you see top-level `privateKey` in user code, it was always wrong.
82
+ - **`evmOptions` is reserved.** It is declared in the type but **not currently read** by the provider. It exists to keep the config shape stable while EVM sidecar support on Injective is in development.
83
+ - **`chainId` and `network` must agree.** Pass `Mainnet` + `injective-1` for mainnet, `Testnet` + `injective-888` for testnet. Mismatched pairs cause broadcasting errors that look like RPC failures.
84
+ - **`sequence` / `accountNumber` defaults are zero.** Override via `defaults` or per call when the on-chain account state differs (otherwise broadcasting fails with "incorrect account sequence").
85
+
86
+ ---
87
+
88
+ ## See also
89
+
90
+ - [`recipes/setup-private-key.md`](../recipes/setup-private-key.md)
91
+ - [`recipes/setup-browser-extension.md`](../recipes/setup-browser-extension.md)
92
+ - [`recipes/sign-and-broadcast.md`](../recipes/sign-and-broadcast.md)
@@ -0,0 +1,92 @@
1
+ # NEAR — `NearWalletProvider`
2
+
3
+ Backed by `near-api-js` (PK signing) and `@hot-labs/near-connect` (browser-extension `NearConnector`).
4
+
5
+ | | |
6
+ |---|---|
7
+ | Class | `NearWalletProvider` |
8
+ | Interface | `INearWalletProvider` (from `@sodax/types`) |
9
+ | Discriminant style | **Field presence** (no `type` field) |
10
+ | Underlying SDK | `near-api-js`, `@hot-labs/near-connect` |
11
+
12
+ ---
13
+
14
+ ## Config
15
+
16
+ ```ts
17
+ type NearWalletConfig = PrivateKeyNearWalletConfig | BrowserExtensionNearWalletConfig;
18
+
19
+ type PrivateKeyNearWalletConfig = {
20
+ rpcUrl: string;
21
+ accountId: string; // e.g. 'alice.near'
22
+ privateKey: string; // 'ed25519:…' format
23
+ defaults?: NearWalletDefaults;
24
+ };
25
+
26
+ type BrowserExtensionNearWalletConfig = {
27
+ wallet: NearConnector; // from @hot-labs/near-connect
28
+ defaults?: NearWalletDefaults;
29
+ };
30
+ ```
31
+
32
+ | Mode discriminant | How to detect |
33
+ |---|---|
34
+ | Private-key | `'privateKey' in config` (also `accountId`, `rpcUrl`) |
35
+ | Browser-extension | `'wallet' in config` |
36
+
37
+ ---
38
+
39
+ ## `NearWalletDefaults`
40
+
41
+ ```ts
42
+ type NearWalletDefaults = {
43
+ throwOnFailure?: boolean; // default true — PK path only
44
+ waitUntil?: NearTxExecutionStatus; // default 'FINAL'
45
+ gasDefault?: bigint; // applied if tx omits gas
46
+ depositDefault?: bigint; // applied if tx omits deposit
47
+ };
48
+
49
+ type NearTxExecutionStatus =
50
+ | 'NONE' | 'INCLUDED' | 'EXECUTED_OPTIMISTIC' | 'INCLUDED_FINAL' | 'EXECUTED' | 'FINAL';
51
+ ```
52
+
53
+ ---
54
+
55
+ ## Methods
56
+
57
+ | Method | Signature | Returns |
58
+ |---|---|---|
59
+ | `getWalletAddress` | `() => Promise<string>` | accountId (e.g. `alice.near`) |
60
+ | `getRawTransaction` | `(params: CallContractParams) => Promise<NearRawTransaction>` | unsigned tx — useful for inspection |
61
+ | `signAndSubmitTxn` | `(transaction: NearRawTransaction, options?: NearWalletDefaults) => Promise<string>` | tx hash |
62
+
63
+ `signAndSubmitTxn` merges `defaults` (flat) over per-call `options`.
64
+
65
+ ---
66
+
67
+ ## Public fields
68
+
69
+ | Field | Type | Notes |
70
+ |---|---|---|
71
+ | `chainType` | `'NEAR'` (literal) | Discriminant. |
72
+ | `account` | `Account \| undefined` | PK mode only — `near-api-js` `Account`. |
73
+ | `rpcProvider` | `JsonRpcProvider \| undefined` | PK mode only. |
74
+
75
+ `wallet` (`NearConnector`) is private. Browser-extension mode exposes neither `account` nor `rpcProvider`.
76
+
77
+ ---
78
+
79
+ ## Gotchas
80
+
81
+ - **`privateKey` is the full `ed25519:…` string**, not just the bytes. NEAR stores keys with the algorithm prefix.
82
+ - **`accountId` is mandatory in PK mode.** NEAR keys don't determine the account — accounts can hold multiple keys. The provider needs both.
83
+ - **`waitUntil` defaults to `'FINAL'`.** Slowest but safest. Lower (`'EXECUTED'`) for faster scripts, with the usual caveats about reverts.
84
+ - **Browser-extension mode uses `@hot-labs/near-connect`'s `NearConnector`.** It already abstracts over multiple NEAR wallets (Meteor, MyNearWallet, …) — pass the connector instance, not a lower-level wallet object.
85
+
86
+ ---
87
+
88
+ ## See also
89
+
90
+ - [`recipes/setup-private-key.md`](../recipes/setup-private-key.md)
91
+ - [`recipes/setup-browser-extension.md`](../recipes/setup-browser-extension.md)
92
+ - [`recipes/sign-and-broadcast.md`](../recipes/sign-and-broadcast.md)
@@ -0,0 +1,104 @@
1
+ # Solana — `SolanaWalletProvider`
2
+
3
+ Backed by `@solana/web3.js` and `@solana/wallet-adapter-base` interfaces.
4
+
5
+ | | |
6
+ |---|---|
7
+ | Class | `SolanaWalletProvider` |
8
+ | Interface | `ISolanaWalletProvider` (from `@sodax/types`) |
9
+ | Discriminant style | **Field presence** (no `type` field) |
10
+ | Underlying SDK | `@solana/web3.js` |
11
+
12
+ ---
13
+
14
+ ## Config
15
+
16
+ ```ts
17
+ type SolanaWalletConfig = PrivateKeySolanaWalletConfig | BrowserExtensionSolanaWalletConfig;
18
+
19
+ type PrivateKeySolanaWalletConfig = {
20
+ privateKey: Uint8Array; // secret key bytes — usually length 64
21
+ endpoint: string; // RPC URL
22
+ defaults?: SolanaWalletDefaults;
23
+ };
24
+
25
+ type BrowserExtensionSolanaWalletConfig = {
26
+ wallet: WalletContextState; // { publicKey, signTransaction }
27
+ endpoint: string;
28
+ defaults?: SolanaWalletDefaults;
29
+ };
30
+
31
+ interface WalletContextState {
32
+ publicKey: PublicKey | null;
33
+ signTransaction: SignerWalletAdapterProps['signTransaction'] | undefined;
34
+ }
35
+ ```
36
+
37
+ | Mode discriminant | How to detect |
38
+ |---|---|
39
+ | Private-key | `'privateKey' in config` |
40
+ | Browser-extension | `'wallet' in config` |
41
+
42
+ ---
43
+
44
+ ## `SolanaWalletDefaults`
45
+
46
+ ```ts
47
+ type SolanaWalletDefaults = {
48
+ connectionCommitment?: Commitment; // for Connection ctor — default 'confirmed'
49
+ connectionConfig?: ConnectionConfig; // overrides connectionCommitment if present
50
+ sendOptions?: SendOptions; // default for sendRawTransaction
51
+ confirmCommitment?: Commitment; // for confirmation polling — default 'finalized'
52
+ };
53
+ ```
54
+
55
+ `connectionConfig` is the full ConnectionConfig — if you set it, `connectionCommitment` is ignored.
56
+
57
+ ---
58
+
59
+ ## Methods
60
+
61
+ | Method | Signature | Returns |
62
+ |---|---|---|
63
+ | `getWalletAddress` | `() => Promise<string>` | base58 public key |
64
+ | `getWalletBase58PublicKey` | `() => SolanaBase58PublicKey` | synchronous public key |
65
+ | `sendTransaction` | `(rawTx: SolanaSerializedTransaction, options?: SendOptions) => Promise<string>` | signature |
66
+ | `sendTransactionWithConfirmation` | `(rawTx, sendOptions?, confirmCommitment?) => Promise<string>` | signature, after confirmation |
67
+ | `waitForConfirmation` | `(signature, commitment?) => Promise<…>` | confirmation status |
68
+ | `buildV0Txn` | `(rawInstructions: SolanaRawTransactionInstruction[]) => Promise<SolanaSerializedTransaction>` | serialised v0 transaction |
69
+ | `getAssociatedTokenAddress` | `(mint) => Promise<SolanaBase58PublicKey>` | derived ATA |
70
+ | `getBalance` | `(publicKey) => Promise<number>` | lamports |
71
+ | `getTokenAccountBalance` | `(publicKey) => Promise<RpcResponseAndContext<TokenAmount>>` | SPL balance |
72
+
73
+ Default slice merging:
74
+ - `defaults.sendOptions` → merged into `sendTransaction(_, options)`.
75
+ - `defaults.confirmCommitment` → falls back when `sendTransactionWithConfirmation(_, _, commit)` is undefined.
76
+ - `defaults.connectionCommitment` / `defaults.connectionConfig` → used at construction time only.
77
+
78
+ ---
79
+
80
+ ## Public fields
81
+
82
+ | Field | Type | Notes |
83
+ |---|---|---|
84
+ | `chainType` | `'SOLANA'` (literal) | Discriminant. |
85
+ | `connection` | `Connection` | The web3.js Connection, derived from `endpoint` + defaults. |
86
+
87
+ `wallet` (Keypair or `WalletContextState`) is private — call provider methods instead.
88
+
89
+ ---
90
+
91
+ ## Gotchas
92
+
93
+ - **`buildV0Txn` is the canonical path for building transactions.** It picks the keypair-vs-adapter signing path internally based on construction mode. Don't construct transactions yourself.
94
+ - **`WalletContextState.signTransaction` is allowed to be `undefined`.** This mirrors `@solana/wallet-adapter-base` — the adapter may not implement signing for all flows. The provider throws at signing time if `signTransaction` is missing.
95
+ - **`confirmCommitment` defaults to `'finalized'`.** Slow but safe. Lower (`'confirmed'`) for faster UX, with the usual finality caveats.
96
+ - **`endpoint` is a required field.** There is no public-RPC fallback like EVM has.
97
+
98
+ ---
99
+
100
+ ## See also
101
+
102
+ - [`recipes/setup-private-key.md`](../recipes/setup-private-key.md)
103
+ - [`recipes/setup-browser-extension.md`](../recipes/setup-browser-extension.md)
104
+ - [`recipes/sign-and-broadcast.md`](../recipes/sign-and-broadcast.md)
@@ -0,0 +1,91 @@
1
+ # Stacks — `StacksWalletProvider`
2
+
3
+ Backed by `@stacks/transactions` and `@stacks/connect` (browser-extension `StacksProvider`).
4
+
5
+ | | |
6
+ |---|---|
7
+ | Class | `StacksWalletProvider` |
8
+ | Interface | `IStacksWalletProvider` (from `@sodax/types`) |
9
+ | Discriminant style | **Field presence** (no `type` field) |
10
+ | Underlying SDK | `@stacks/transactions`, `@stacks/connect`, `@stacks/network` |
11
+
12
+ ---
13
+
14
+ ## Config
15
+
16
+ ```ts
17
+ type StacksWalletConfig = PrivateKeyStacksWalletConfig | BrowserExtensionStacksWalletConfig;
18
+
19
+ type PrivateKeyStacksWalletConfig = {
20
+ privateKey: string;
21
+ endpoint?: string; // Stacks API endpoint
22
+ defaults?: StacksWalletDefaults;
23
+ };
24
+
25
+ type BrowserExtensionStacksWalletConfig = {
26
+ address: string; // 'SP…' (mainnet) or 'ST…' (testnet)
27
+ endpoint?: string;
28
+ provider?: StacksProvider; // from @stacks/connect — optional
29
+ defaults?: StacksWalletDefaults;
30
+ };
31
+ ```
32
+
33
+ | Mode discriminant | How to detect |
34
+ |---|---|
35
+ | Private-key | `'privateKey' in config` |
36
+ | Browser-extension | `'address' in config` (no `privateKey`) |
37
+
38
+ ---
39
+
40
+ ## `StacksWalletDefaults`
41
+
42
+ ```ts
43
+ type StacksWalletDefaults = {
44
+ network?: 'mainnet' | 'testnet'; // default 'mainnet'
45
+ postConditionMode?: PostConditionMode;
46
+ };
47
+ ```
48
+
49
+ `PostConditionMode` is re-exported as a runtime value from this package — see [`recipes/library-exports.md`](../recipes/library-exports.md).
50
+
51
+ ---
52
+
53
+ ## Methods
54
+
55
+ | Method | Signature | Returns |
56
+ |---|---|---|
57
+ | `getWalletAddress` | `() => Promise<string>` | Stacks address (`SP…` / `ST…`) |
58
+ | `getPublicKey` | `() => Promise<string>` | hex pubkey |
59
+ | `sendTransaction` | `(params: StacksTransactionParams) => Promise<…>` | tx response |
60
+ | `readContract` | `(txParams: StacksTransactionParams) => Promise<ClarityValue>` | read-only call result |
61
+ | `getBalance` | `(address: string) => Promise<bigint>` | STX micro-balance |
62
+
63
+ Internally `sendTransaction` dispatches to `sendTransactionWithPrivateKey` or `sendTransactionWithAdapter` based on construction mode.
64
+
65
+ ---
66
+
67
+ ## Public fields
68
+
69
+ | Field | Type | Notes |
70
+ |---|---|---|
71
+ | `chainType` | `'STACKS'` (literal) | Discriminant. |
72
+
73
+ `network` (`StacksNetwork`) and `wallet` are private.
74
+
75
+ ---
76
+
77
+ ## Gotchas
78
+
79
+ - **`endpoint` is optional.** Defaults to the Hiro mainnet/testnet API URL depending on `network`. Override for private RPCs.
80
+ - **`provider` (StacksProvider) is optional in browser-extension mode.** When omitted, the provider falls back to the globally-injected `window`-level provider (Leather, Xverse, Asigna). Pass it explicitly for tests or non-injected environments.
81
+ - **`postConditionMode` is a runtime enum.** Import from `@sodax/wallet-sdk-core` (re-exported via `library-exports`) — no need to add `@stacks/transactions` as a direct dep.
82
+ - **Mainnet vs testnet split.** `network: 'mainnet'` resolves to `STACKS_MAINNET`; `'testnet'` to `STACKS_TESTNET`. Cross-environment addresses will reject.
83
+
84
+ ---
85
+
86
+ ## See also
87
+
88
+ - [`recipes/setup-private-key.md`](../recipes/setup-private-key.md)
89
+ - [`recipes/setup-browser-extension.md`](../recipes/setup-browser-extension.md)
90
+ - [`recipes/sign-and-broadcast.md`](../recipes/sign-and-broadcast.md)
91
+ - [`recipes/library-exports.md`](../recipes/library-exports.md) — `PostConditionMode` enum