@sodax/wallet-sdk-core 1.5.7-beta → 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.
- package/README.md +231 -1
- package/ai-exported/AGENTS.md +139 -0
- package/ai-exported/integration/README.md +108 -0
- package/ai-exported/integration/ai-rules.md +141 -0
- package/ai-exported/integration/architecture.md +212 -0
- package/ai-exported/integration/features/README.md +22 -0
- package/ai-exported/integration/features/bitcoin.md +103 -0
- package/ai-exported/integration/features/evm.md +102 -0
- package/ai-exported/integration/features/icon.md +88 -0
- package/ai-exported/integration/features/injective.md +92 -0
- package/ai-exported/integration/features/near.md +92 -0
- package/ai-exported/integration/features/solana.md +104 -0
- package/ai-exported/integration/features/stacks.md +91 -0
- package/ai-exported/integration/features/stellar.md +95 -0
- package/ai-exported/integration/features/sui.md +96 -0
- package/ai-exported/integration/quickstart.md +259 -0
- package/ai-exported/integration/recipes/README.md +15 -0
- package/ai-exported/integration/recipes/bridge-to-sdk.md +145 -0
- package/ai-exported/integration/recipes/defaults-and-overrides.md +159 -0
- package/ai-exported/integration/recipes/library-exports.md +129 -0
- package/ai-exported/integration/recipes/setup-browser-extension.md +137 -0
- package/ai-exported/integration/recipes/setup-private-key.md +115 -0
- package/ai-exported/integration/recipes/sign-and-broadcast.md +201 -0
- package/ai-exported/integration/recipes/testing.md +163 -0
- package/ai-exported/integration/reference/README.md +13 -0
- package/ai-exported/integration/reference/chain-support.md +65 -0
- package/ai-exported/integration/reference/glossary.md +28 -0
- package/ai-exported/integration/reference/interfaces.md +131 -0
- package/ai-exported/integration/reference/provider-classes.md +54 -0
- package/ai-exported/integration/reference/public-api.md +128 -0
- package/ai-exported/migration/README.md +84 -0
- package/ai-exported/migration/ai-rules.md +139 -0
- package/ai-exported/migration/breaking-changes/README.md +14 -0
- package/ai-exported/migration/breaking-changes/base-wallet-provider.md +52 -0
- package/ai-exported/migration/breaking-changes/defaults-config.md +57 -0
- package/ai-exported/migration/breaking-changes/folder-layout.md +99 -0
- package/ai-exported/migration/breaking-changes/library-exports.md +58 -0
- package/ai-exported/migration/checklist.md +62 -0
- package/ai-exported/migration/recipes/README.md +12 -0
- package/ai-exported/migration/recipes/adopt-defaults.md +84 -0
- package/ai-exported/migration/recipes/adopt-library-exports.md +99 -0
- package/ai-exported/migration/reference/README.md +12 -0
- package/ai-exported/migration/reference/added-fields.md +71 -0
- package/ai-exported/migration/reference/deleted-exports.md +35 -0
- package/ai-exported/migration/reference/renamed-symbols.md +31 -0
- package/ai-exported/migration/reference/return-shapes.md +23 -0
- package/dist/index.cjs +3200 -2392
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +415 -128
- package/dist/index.d.ts +415 -128
- package/dist/index.mjs +3197 -2395
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -8
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Recipe: Testing — mocking providers
|
|
2
|
+
|
|
3
|
+
Patterns for unit-testing code that consumes `IXxxWalletProvider` interfaces. The same approach scales to integration tests against testnets.
|
|
4
|
+
|
|
5
|
+
**Depends on:** [`bridge-to-sdk.md`](./bridge-to-sdk.md) — your code should already type its functions against the interface, not the class.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Pattern 1 — Type the function signature on the interface
|
|
10
|
+
|
|
11
|
+
Make the function under test accept the interface, not the concrete class:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// ✅ Testable — accept the interface
|
|
15
|
+
import type { IEvmWalletProvider } from '@sodax/types';
|
|
16
|
+
|
|
17
|
+
export async function depositFlow(wallet: IEvmWalletProvider, amount: bigint) {
|
|
18
|
+
const addr = await wallet.getWalletAddress();
|
|
19
|
+
// …
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Mock the interface in the test:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
27
|
+
import type { IEvmWalletProvider } from '@sodax/types';
|
|
28
|
+
import { depositFlow } from '../depositFlow';
|
|
29
|
+
|
|
30
|
+
describe('depositFlow', () => {
|
|
31
|
+
it('uses the address from the provider', async () => {
|
|
32
|
+
const mockProvider: IEvmWalletProvider = {
|
|
33
|
+
chainType: 'EVM',
|
|
34
|
+
getWalletAddress: vi.fn(async () => '0xabc' as const),
|
|
35
|
+
sendTransaction: vi.fn(async () => '0xdeadbeef'),
|
|
36
|
+
waitForTransactionReceipt: vi.fn(async () => ({ /* … */ } as any)),
|
|
37
|
+
publicClient: undefined as never, // not used in this test
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
await depositFlow(mockProvider, 100n);
|
|
41
|
+
expect(mockProvider.getWalletAddress).toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> Test files are the **only** place where `as any` / `as unknown as` casts should be tolerated — production code paths should rely on the discriminated unions instead.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Pattern 2 — Use the real provider against a local key
|
|
51
|
+
|
|
52
|
+
For end-to-end logic tests, construct a real provider with a deterministic key — no mocking, no network calls:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { describe, it } from 'vitest';
|
|
56
|
+
import { EvmWalletProvider } from '@sodax/wallet-sdk-core';
|
|
57
|
+
import { ChainKeys } from '@sodax/types';
|
|
58
|
+
|
|
59
|
+
const TEST_PK = '0x' + 'ab'.repeat(32) as `0x${string}`; // dev-only key
|
|
60
|
+
|
|
61
|
+
describe('EvmWalletProvider', () => {
|
|
62
|
+
it('derives the address from the private key', async () => {
|
|
63
|
+
const provider = new EvmWalletProvider({
|
|
64
|
+
privateKey: TEST_PK,
|
|
65
|
+
chainId: ChainKeys.SONIC_MAINNET,
|
|
66
|
+
});
|
|
67
|
+
const addr = await provider.getWalletAddress();
|
|
68
|
+
expect(addr).toMatch(/^0x[a-fA-F0-9]{40}$/);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`getWalletAddress` doesn't hit the network — viem derives the EOA from the key in-process.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Pattern 3 — Stub the upstream chain SDK with `vi.mock`
|
|
78
|
+
|
|
79
|
+
When you can't avoid testing the bits that **do** hit the network (sending, polling), stub the upstream chain SDK:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { vi } from 'vitest';
|
|
83
|
+
|
|
84
|
+
vi.mock('viem', async (importActual) => {
|
|
85
|
+
const actual = await importActual<typeof import('viem')>();
|
|
86
|
+
return {
|
|
87
|
+
...actual,
|
|
88
|
+
createWalletClient: vi.fn(() => ({
|
|
89
|
+
sendTransaction: vi.fn(async () => '0xfakehash'),
|
|
90
|
+
account: { address: '0xabc' as const },
|
|
91
|
+
// …
|
|
92
|
+
})),
|
|
93
|
+
createPublicClient: vi.fn(() => ({
|
|
94
|
+
waitForTransactionReceipt: vi.fn(async () => mockReceipt),
|
|
95
|
+
})),
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This isolates the test from the network without rewriting the provider. The downside is that you're now testing your mock; reserve this pattern for cases where pattern 1 isn't enough.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Pattern 4 — Run against a testnet (true integration)
|
|
105
|
+
|
|
106
|
+
For real end-to-end coverage, use a testnet (Sonic Testnet, Solana Devnet, BTC Testnet, etc.) and a CI-managed key:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
// vitest.config.ts — gate behind an env flag so devs don't accidentally run it
|
|
110
|
+
test: {
|
|
111
|
+
exclude: process.env.RUN_E2E ? [] : ['**/*.e2e.test.ts'],
|
|
112
|
+
},
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
// foo.e2e.test.ts
|
|
117
|
+
import { EvmWalletProvider } from '@sodax/wallet-sdk-core';
|
|
118
|
+
import { ChainKeys } from '@sodax/types';
|
|
119
|
+
|
|
120
|
+
const PK = process.env.E2E_EVM_PK as `0x${string}`;
|
|
121
|
+
const RPC = process.env.E2E_EVM_RPC;
|
|
122
|
+
|
|
123
|
+
describe.skipIf(!PK)('e2e — EVM testnet', () => {
|
|
124
|
+
it('sends a 0-value tx', async () => {
|
|
125
|
+
const provider = new EvmWalletProvider({ privateKey: PK, chainId: ChainKeys.SONIC_MAINNET, rpcUrl: RPC });
|
|
126
|
+
const hash = await provider.sendTransaction({ to: '0x…', value: 0n, data: '0x' });
|
|
127
|
+
expect(hash).toMatch(/^0x[a-fA-F0-9]{64}$/);
|
|
128
|
+
}, 60_000);
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`apps/node/src/tests/` in this repo follows this pattern — see those test files for live examples.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## What NOT to test
|
|
137
|
+
|
|
138
|
+
| Test idea | Why skip | Alternative |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| The merge semantics of `defaults` | Already covered by `src/utils/merge.test.ts` in this package | Trust the merge; test your **policy** values are right |
|
|
141
|
+
| viem's `sendTransaction` semantics | Not your code | Mock at pattern 3 if you need to assert your provider passes args through |
|
|
142
|
+
| Wallet-extension UI flows in unit tests | Browser-only | Use Playwright / Cypress against a real extension build |
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Verification
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
pnpm test
|
|
150
|
+
pnpm checkTs
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Confirm test files use the interface, not the class, for type annotations
|
|
155
|
+
grep -rn "IEvmWalletProvider\|ISolanaWalletProvider\|IBitcoinWalletProvider" <user-src>/**/*.test.ts
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## See also
|
|
161
|
+
|
|
162
|
+
- `src/utils/merge.test.ts` — reference test style for utility-level tests in this package.
|
|
163
|
+
- Every `src/wallet-providers/*/`*`WalletProvider.test.ts` file — provider-level test patterns.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Reference
|
|
2
|
+
|
|
3
|
+
Lookup tables. Use these to answer "what does X look like" without reading source.
|
|
4
|
+
|
|
5
|
+
| File | Use for |
|
|
6
|
+
|---|---|
|
|
7
|
+
| [`public-api.md`](./public-api.md) | Every named export from `@sodax/wallet-sdk-core`. |
|
|
8
|
+
| [`provider-classes.md`](./provider-classes.md) | Class × config × interface × default-merge-helper matrix. |
|
|
9
|
+
| [`interfaces.md`](./interfaces.md) | `IXxxWalletProvider` method signatures (sourced from `@sodax/types`). |
|
|
10
|
+
| [`chain-support.md`](./chain-support.md) | Chain family → spoke chain keys + provider. |
|
|
11
|
+
| [`glossary.md`](./glossary.md) | Terms used across the docs. |
|
|
12
|
+
|
|
13
|
+
All files in this directory are intentionally **terse and table-heavy** — for narrative explanations see [`../architecture.md`](../architecture.md) and the per-chain [`../features/`](../features/) files.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Chain support
|
|
2
|
+
|
|
3
|
+
Chain families and spoke chain keys this package can sign for. Keys live in `@sodax/types`.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## EVM (one provider, 12 chains)
|
|
8
|
+
|
|
9
|
+
`EvmWalletProvider` covers every EVM spoke chain via `getEvmViemChain()`. The provider is exhaustive — adding a new `EvmChainKey` to `@sodax/types` requires updating `getEvmViemChain` (caught at compile time via a `never` assertion in the default branch).
|
|
10
|
+
|
|
11
|
+
| Spoke chain key | viem chain |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `ChainKeys.SONIC_MAINNET` (hub) | `sonic` |
|
|
14
|
+
| `ChainKeys.ETHEREUM_MAINNET` | `mainnet` |
|
|
15
|
+
| `ChainKeys.ARBITRUM_MAINNET` | `arbitrum` |
|
|
16
|
+
| `ChainKeys.BASE_MAINNET` | `base` |
|
|
17
|
+
| `ChainKeys.BSC_MAINNET` | `bsc` |
|
|
18
|
+
| `ChainKeys.OPTIMISM_MAINNET` | `optimism` |
|
|
19
|
+
| `ChainKeys.POLYGON_MAINNET` | `polygon` |
|
|
20
|
+
| `ChainKeys.AVALANCHE_MAINNET` | `avalanche` |
|
|
21
|
+
| `ChainKeys.HYPEREVM_MAINNET` | `hyper` (defined inside this package) |
|
|
22
|
+
| `ChainKeys.LIGHTLINK_MAINNET` | `lightlinkPhoenix` |
|
|
23
|
+
| `ChainKeys.REDBELLY_MAINNET` | `redbellyMainnet` |
|
|
24
|
+
| `ChainKeys.KAIA_MAINNET` | `kaia` |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Non-EVM (one provider per chain family)
|
|
29
|
+
|
|
30
|
+
| Chain family | Provider | Spoke chain key(s) |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| Solana | `SolanaWalletProvider` | `ChainKeys.SOLANA_MAINNET` |
|
|
33
|
+
| Sui | `SuiWalletProvider` | `ChainKeys.SUI_MAINNET` |
|
|
34
|
+
| Bitcoin | `BitcoinWalletProvider` | `ChainKeys.BITCOIN_MAINNET` |
|
|
35
|
+
| Stellar | `StellarWalletProvider` | `ChainKeys.STELLAR_MAINNET` |
|
|
36
|
+
| ICON | `IconWalletProvider` | `ChainKeys.ICON_MAINNET` |
|
|
37
|
+
| Injective | `InjectiveWalletProvider` | `ChainKeys.INJECTIVE_MAINNET` |
|
|
38
|
+
| NEAR | `NearWalletProvider` | `ChainKeys.NEAR_MAINNET` |
|
|
39
|
+
| Stacks | `StacksWalletProvider` | `ChainKeys.STACKS_MAINNET` |
|
|
40
|
+
|
|
41
|
+
> 20 spoke chains total = 12 EVM + 8 non-EVM. The hub chain (Sonic) is counted with EVM.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Upstream chain-SDK matrix
|
|
46
|
+
|
|
47
|
+
Run-time deps each provider pulls in. See [`../recipes/library-exports.md`](../recipes/library-exports.md) for how to re-import their **types** without a direct dep.
|
|
48
|
+
|
|
49
|
+
| Provider | Upstream SDKs |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `EvmWalletProvider` | `viem` |
|
|
52
|
+
| `SolanaWalletProvider` | `@solana/web3.js`, `@solana/spl-token`, `@solana/wallet-adapter-base` |
|
|
53
|
+
| `SuiWalletProvider` | `@mysten/sui`, `@mysten/wallet-standard` |
|
|
54
|
+
| `BitcoinWalletProvider` | `bitcoinjs-lib`, `ecpair`, `secp256k1`, `@bitcoinerlab/secp256k1`, `bip322-js` |
|
|
55
|
+
| `StellarWalletProvider` | `@stellar/stellar-sdk` |
|
|
56
|
+
| `IconWalletProvider` | `icon-sdk-js` |
|
|
57
|
+
| `InjectiveWalletProvider` | `@injectivelabs/sdk-ts`, `@injectivelabs/wallet-core`, `@injectivelabs/networks`, `@injectivelabs/ts-types` |
|
|
58
|
+
| `NearWalletProvider` | `near-api-js`, `@hot-labs/near-connect` |
|
|
59
|
+
| `StacksWalletProvider` | `@stacks/transactions`, `@stacks/connect`, `@stacks/network` |
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## When to NOT use this package
|
|
64
|
+
|
|
65
|
+
If your chain is not in the table above, this package does not yet support it. Adding a new chain is a **maintainer task** — open an issue if your chain is missing.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Glossary
|
|
2
|
+
|
|
3
|
+
Terms used across the `wallet-sdk-core` docs.
|
|
4
|
+
|
|
5
|
+
| Term | Meaning |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **`BaseWalletProvider`** | Abstract base class every provider extends. Holds `defaults` and exposes `mergePolicy` / `mergeDefaults`. |
|
|
8
|
+
| **Browser-extension mode** | Construction mode where the caller supplies pre-built chain clients / wallet kits from a wallet extension (MetaMask, Phantom, Xverse, Hana, Freighter, Leather, …). |
|
|
9
|
+
| **`chainType`** | Literal string identifier on each provider class (`'EVM'`, `'SOLANA'`, …). Mirrors `ChainType` in `@sodax/types`. |
|
|
10
|
+
| **Discriminant style** | How the union narrows. Either **field presence** (most chains) or an explicit **`type` field** (Bitcoin, Stellar). |
|
|
11
|
+
| **`defaults`** | Optional config slice merged into every method call. Shape per chain is `*WalletDefaults`. |
|
|
12
|
+
| **EOA** | Externally Owned Account — a wallet derived from a key, as opposed to a contract account. Some chains brand it (`IconEoaAddress`, `InjectiveEoaAddress`). |
|
|
13
|
+
| **Field presence** | A discriminated union narrowed by which fields exist (`'privateKey' in config` vs `'walletClient' in config`). |
|
|
14
|
+
| **Flat merge** (`mergeDefaults`) | Defaults are a flat object; per-call options shallow-merge over the entire object. |
|
|
15
|
+
| **Hub / Spoke** | SODAX architecture term. Sonic is the hub; all other 19 chains are spokes. `wallet-sdk-core` provides spoke-side wallet primitives. |
|
|
16
|
+
| **`IXxxWalletProvider`** | Chain-specific interface from `@sodax/types`. The class implements it; the SDK consumes it. |
|
|
17
|
+
| **`library-exports`** | `src/types/library-exports.ts` — curated re-exports of upstream chain-SDK types (and 2 runtime enums). |
|
|
18
|
+
| **Mnemonics** | BIP-39 phrase. Used as the private-key credential on Sui (no raw-key option) and as one option on Injective via the `secret` wrapper. |
|
|
19
|
+
| **Per-method merge** (`mergePolicy`) | Defaults are grouped per method (`defaults.sendTransaction`, …); per-call options shallow-merge over the matching slice. |
|
|
20
|
+
| **Private-key mode** | Construction mode where the caller supplies a raw secret (or mnemonic / nested `secret` for some chains). Server / script / CI flows only. |
|
|
21
|
+
| **PSBT** | Partially Signed Bitcoin Transaction. Bitcoin `signTransaction` accepts a base64-encoded PSBT. |
|
|
22
|
+
| **`secret`** (Injective only) | Nested credential wrapper accepting `{ privateKey }` or `{ mnemonics }` in `SecretInjectiveWalletConfig`. |
|
|
23
|
+
| **Shallow merge** | Top-level keys are merged; nested objects are replaced wholesale. See `src/utils/merge.ts`. |
|
|
24
|
+
| **Spoke chain key** | Branded string from `@sodax/types` identifying a chain (`ChainKeys.SONIC_MAINNET`, `ChainKeys.BSC_MAINNET`, …). |
|
|
25
|
+
| **`type` discriminant** | Explicit uppercase `type: 'PRIVATE_KEY' \| 'BROWSER_EXTENSION'` field. Used by Bitcoin and Stellar only. |
|
|
26
|
+
| **`WalletAddressProvider`** | Base interface in `@sodax/types` — exposes `getWalletAddress(): Promise<string>`. Every `IXxxWalletProvider` extends it. |
|
|
27
|
+
| **`walletsKit`** | Consumer-supplied adapter in Bitcoin / Stellar browser-extension mode. Conforms to `BitcoinWalletsKit` / `StellarWalletsKit`. |
|
|
28
|
+
| **XDR** | Stellar's binary transaction format, encoded as a string. Type alias `XDR` from `@sodax/types`. |
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# `IXxxWalletProvider` interfaces
|
|
2
|
+
|
|
3
|
+
The signatures `@sodax/sdk` consumes. Sourced from `@sodax/types`; one interface per chain. Pass the **interface**, not the class, in function signatures — see [`../recipes/bridge-to-sdk.md`](../recipes/bridge-to-sdk.md).
|
|
4
|
+
|
|
5
|
+
The tables below summarise the methods each provider exposes. For full type-level signatures (including the chain-specific param/return types) consult `@sodax/types`'s package — these tables intentionally elide deep generics.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## `IEvmWalletProvider`
|
|
10
|
+
|
|
11
|
+
| Method | Signature (abridged) |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `getWalletAddress` | `() => Promise<Address>` |
|
|
14
|
+
| `sendTransaction` | `(tx: EvmRawTransaction, opts?: EvmSendTransactionPolicy) => Promise<Hash>` |
|
|
15
|
+
| `waitForTransactionReceipt` | `(hash: Hash, opts?: EvmWaitForTransactionReceiptPolicy) => Promise<EvmRawTransactionReceipt>` |
|
|
16
|
+
|
|
17
|
+
Plus public field: `publicClient: PublicClient`.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## `ISolanaWalletProvider`
|
|
22
|
+
|
|
23
|
+
| Method | Signature (abridged) |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
26
|
+
| `getWalletBase58PublicKey` | `() => SolanaBase58PublicKey` |
|
|
27
|
+
| `sendTransaction` | `(rawTx, opts?: SendOptions) => Promise<string>` |
|
|
28
|
+
| `sendTransactionWithConfirmation` | `(rawTx, sendOpts?, confirmCommitment?) => Promise<string>` |
|
|
29
|
+
| `waitForConfirmation` | `(signature, commitment?) => Promise<…>` |
|
|
30
|
+
| `buildV0Txn` | `(rawInstructions) => Promise<SolanaSerializedTransaction>` |
|
|
31
|
+
| `getAssociatedTokenAddress` | `(mint) => Promise<SolanaBase58PublicKey>` |
|
|
32
|
+
| `getBalance` | `(publicKey) => Promise<number>` |
|
|
33
|
+
| `getTokenAccountBalance` | `(publicKey) => Promise<RpcResponseAndContext<TokenAmount>>` |
|
|
34
|
+
|
|
35
|
+
Plus public field: `connection: Connection`.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## `ISuiWalletProvider`
|
|
40
|
+
|
|
41
|
+
| Method | Signature (abridged) |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
44
|
+
| `signAndExecuteTxn` | `(txn: SuiTransaction, opts?: SuiSignAndExecutePolicy) => Promise<string>` |
|
|
45
|
+
| `viewContract` | `(txn, …) => Promise<…>` |
|
|
46
|
+
| `getCoins` | `(address, token, opts?: SuiGetCoinsPolicy) => Promise<SuiPaginatedCoins>` |
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## `IBitcoinWalletProvider`
|
|
51
|
+
|
|
52
|
+
| Method | Signature (abridged) |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
55
|
+
| `getPublicKey` | `() => Promise<string>` |
|
|
56
|
+
| `getAddressType` | `(address: string) => Promise<BtcAddressType>` |
|
|
57
|
+
| `signTransaction` | `(psbtBase64: string, finalize?: boolean) => Promise<string>` |
|
|
58
|
+
| `signEcdsaMessage` | `(message: string) => Promise<string>` |
|
|
59
|
+
| `signBip322Message` | `(message: string) => Promise<string>` |
|
|
60
|
+
| `getPayment` | `(keyPair, addressType) => bitcoin.Payment` (PK mode helper) |
|
|
61
|
+
| `sendBitcoin` | `(toAddress: string, satoshis: bigint) => Promise<string>` (only if wallet kit implements it) |
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## `IStellarWalletProvider`
|
|
66
|
+
|
|
67
|
+
| Method | Signature (abridged) |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
70
|
+
| `signTransaction` | `(tx: XDR) => Promise<XDR>` |
|
|
71
|
+
| `waitForTransactionReceipt` | `(hash: string, opts?: Partial<StellarWalletDefaults>) => Promise<…>` |
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## `IIconWalletProvider`
|
|
76
|
+
|
|
77
|
+
| Method | Signature (abridged) |
|
|
78
|
+
|---|---|
|
|
79
|
+
| `getWalletAddress` | `() => Promise<IconEoaAddress>` |
|
|
80
|
+
| `sendTransaction` | `(tx: IcxCallTransaction, opts?: IconWalletDefaults) => Promise<Hash>` |
|
|
81
|
+
| `waitForTransactionReceipt` | `(txHash: Hash) => Promise<IconTransactionResult>` |
|
|
82
|
+
|
|
83
|
+
Plus public field: `iconService: IconService`.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## `IInjectiveWalletProvider`
|
|
88
|
+
|
|
89
|
+
| Method | Signature (abridged) |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `getWalletAddress` | `() => Promise<InjectiveEoaAddress>` |
|
|
92
|
+
| `getWalletPubKey` | `() => Promise<string>` |
|
|
93
|
+
| `getRawTransaction` | `(…) => Promise<…>` |
|
|
94
|
+
| `execute` | `(…) => Promise<…>` |
|
|
95
|
+
|
|
96
|
+
Plus public field: `wallet: InjectiveWallet`.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## `INearWalletProvider`
|
|
101
|
+
|
|
102
|
+
| Method | Signature (abridged) |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
105
|
+
| `getRawTransaction` | `(params: CallContractParams) => Promise<NearRawTransaction>` |
|
|
106
|
+
| `signAndSubmitTxn` | `(tx: NearRawTransaction, opts?: NearWalletDefaults) => Promise<string>` |
|
|
107
|
+
|
|
108
|
+
Plus public fields (PK mode only): `account?: Account`, `rpcProvider?: JsonRpcProvider`.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## `IStacksWalletProvider`
|
|
113
|
+
|
|
114
|
+
| Method | Signature (abridged) |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
117
|
+
| `getPublicKey` | `() => Promise<string>` |
|
|
118
|
+
| `sendTransaction` | `(params: StacksTransactionParams) => Promise<…>` |
|
|
119
|
+
| `readContract` | `(params: StacksTransactionParams) => Promise<ClarityValue>` |
|
|
120
|
+
| `getBalance` | `(address: string) => Promise<bigint>` |
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Authoritative source
|
|
125
|
+
|
|
126
|
+
These tables are summarised. For the full, current type-level signatures (including generics, branded types, and union narrowings) read:
|
|
127
|
+
|
|
128
|
+
- `@sodax/types/src/wallet-providers/*.ts` (each interface lives here)
|
|
129
|
+
- The implementing class in `packages/wallet-sdk-core/src/wallet-providers/<chain>/`.
|
|
130
|
+
|
|
131
|
+
If a method exists on the class but not on the interface, it is an **implementation detail** — do not depend on it from outside the package.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Provider classes — class × config × interface × merge helper
|
|
2
|
+
|
|
3
|
+
One row per chain. Use this when you know the chain and need to look up everything else.
|
|
4
|
+
|
|
5
|
+
| Chain | Class | Config union | Interface (`@sodax/types`) | Default merge helper | Discriminant |
|
|
6
|
+
|---|---|---|---|---|---|
|
|
7
|
+
| EVM | `EvmWalletProvider` | `EvmWalletConfig` | `IEvmWalletProvider` | `mergePolicy` (per-method) | Field presence (no `type`) |
|
|
8
|
+
| Solana | `SolanaWalletProvider` | `SolanaWalletConfig` | `ISolanaWalletProvider` | `mergePolicy` (per-method) | Field presence (no `type`) |
|
|
9
|
+
| Sui | `SuiWalletProvider` | `SuiWalletConfig` | `ISuiWalletProvider` | `mergePolicy` (per-method) | Field presence — uses `mnemonics` |
|
|
10
|
+
| Bitcoin | `BitcoinWalletProvider` | `BitcoinWalletConfig` | `IBitcoinWalletProvider` | `mergeDefaults` (flat) | **`type` field** (`'PRIVATE_KEY' \| 'BROWSER_EXTENSION'`) |
|
|
11
|
+
| Stellar | `StellarWalletProvider` | `StellarWalletConfig` | `IStellarWalletProvider` | `mergeDefaults` (flat) | **`type` field** |
|
|
12
|
+
| ICON | `IconWalletProvider` | `IconWalletConfig` | `IIconWalletProvider` | `mergeDefaults` (flat) | Field presence (no `type`) |
|
|
13
|
+
| Injective | `InjectiveWalletProvider` | `InjectiveWalletConfig` | `IInjectiveWalletProvider` | `mergeDefaults` (flat) | Field presence — PK variant uses `secret` wrapper |
|
|
14
|
+
| NEAR | `NearWalletProvider` | `NearWalletConfig` | `INearWalletProvider` | `mergeDefaults` (flat) | Field presence (no `type`) |
|
|
15
|
+
| Stacks | `StacksWalletProvider` | `StacksWalletConfig` | `IStacksWalletProvider` | `mergeDefaults` (flat) | Field presence (no `type`) |
|
|
16
|
+
|
|
17
|
+
> EVM, Solana, and Sui group their `defaults` per method (e.g. `defaults.sendTransaction`, `defaults.signAndExecuteTxn`). Every other chain has a flat `defaults` object. See [`../architecture.md`](../architecture.md) § `BaseWalletProvider`.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## All exported `chainType` literals
|
|
22
|
+
|
|
23
|
+
| Provider | `chainType` |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `EvmWalletProvider` | `'EVM'` |
|
|
26
|
+
| `SolanaWalletProvider` | `'SOLANA'` |
|
|
27
|
+
| `SuiWalletProvider` | `'SUI'` |
|
|
28
|
+
| `BitcoinWalletProvider` | `'BITCOIN'` |
|
|
29
|
+
| `StellarWalletProvider` | `'STELLAR'` |
|
|
30
|
+
| `IconWalletProvider` | `'ICON'` |
|
|
31
|
+
| `InjectiveWalletProvider` | `'INJECTIVE'` |
|
|
32
|
+
| `NearWalletProvider` | `'NEAR'` |
|
|
33
|
+
| `StacksWalletProvider` | `'STACKS'` |
|
|
34
|
+
|
|
35
|
+
These match `ChainType` values in `@sodax/types`. Useful for runtime discrimination of a generic `IXxxWalletProvider`.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Class hierarchy
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
BaseWalletProvider<TDefaults> ← abstract base from this package
|
|
43
|
+
├── EvmWalletProvider implements IEvmWalletProvider
|
|
44
|
+
├── SolanaWalletProvider implements ISolanaWalletProvider
|
|
45
|
+
├── SuiWalletProvider implements ISuiWalletProvider
|
|
46
|
+
├── BitcoinWalletProvider implements IBitcoinWalletProvider
|
|
47
|
+
├── StellarWalletProvider implements IStellarWalletProvider
|
|
48
|
+
├── IconWalletProvider implements IIconWalletProvider
|
|
49
|
+
├── InjectiveWalletProvider implements IInjectiveWalletProvider
|
|
50
|
+
├── NearWalletProvider implements INearWalletProvider
|
|
51
|
+
└── StacksWalletProvider implements IStacksWalletProvider
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Subclassing `BaseWalletProvider` is **maintainer-only** — it implies adding a new chain to the package.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Public API surface
|
|
2
|
+
|
|
3
|
+
Every named export from `@sodax/wallet-sdk-core`. The package root is the **only** public surface — deep imports from `src/...` are unsupported.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
// Single entry point
|
|
7
|
+
import { /* … */ } from '@sodax/wallet-sdk-core';
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Provider classes (9)
|
|
13
|
+
|
|
14
|
+
| Export | Chain family | File |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| `EvmWalletProvider` | EVM | `wallet-providers/evm/EvmWalletProvider.ts` |
|
|
17
|
+
| `SolanaWalletProvider` | Solana | `wallet-providers/solana/SolanaWalletProvider.ts` |
|
|
18
|
+
| `SuiWalletProvider` | Sui | `wallet-providers/sui/SuiWalletProvider.ts` |
|
|
19
|
+
| `BitcoinWalletProvider` | Bitcoin | `wallet-providers/bitcoin/BTCWalletProvider.ts` |
|
|
20
|
+
| `StellarWalletProvider` | Stellar | `wallet-providers/stellar/StellarWalletProvider.ts` |
|
|
21
|
+
| `IconWalletProvider` | ICON | `wallet-providers/icon/IconWalletProvider.ts` |
|
|
22
|
+
| `InjectiveWalletProvider` | Injective | `wallet-providers/injective/InjectiveWalletProvider.ts` |
|
|
23
|
+
| `NearWalletProvider` | NEAR | `wallet-providers/near/NearWalletProvider.ts` |
|
|
24
|
+
| `StacksWalletProvider` | Stacks | `wallet-providers/stacks/StacksWalletProvider.ts` |
|
|
25
|
+
|
|
26
|
+
Plus the abstract base:
|
|
27
|
+
|
|
28
|
+
| Export | Purpose |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `BaseWalletProvider<TDefaults>` | Abstract base class. Exposes `getWalletAddress`, `mergePolicy`, `mergeDefaults`. **Subclass only for new chains.** |
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Config types (per chain)
|
|
35
|
+
|
|
36
|
+
Each chain ships **three** config-related exports:
|
|
37
|
+
|
|
38
|
+
| Pattern | Example | Purpose |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| `PrivateKey<Chain>WalletConfig` *or* `Secret<Chain>WalletConfig` (Injective) | `PrivateKeyEvmWalletConfig` | Private-key mode config |
|
|
41
|
+
| `BrowserExtension<Chain>WalletConfig` | `BrowserExtensionEvmWalletConfig` | Browser-extension mode config |
|
|
42
|
+
| `<Chain>WalletConfig` | `EvmWalletConfig` | Discriminated union — accept this in function signatures |
|
|
43
|
+
| `<Chain>WalletDefaults` | `EvmWalletDefaults` | Optional `defaults` slice |
|
|
44
|
+
|
|
45
|
+
Full list:
|
|
46
|
+
|
|
47
|
+
| Chain | Discriminated union | PK variant | Browser variant | Defaults |
|
|
48
|
+
|---|---|---|---|---|
|
|
49
|
+
| EVM | `EvmWalletConfig` | `PrivateKeyEvmWalletConfig` | `BrowserExtensionEvmWalletConfig` | `EvmWalletDefaults` |
|
|
50
|
+
| Solana | `SolanaWalletConfig` | `PrivateKeySolanaWalletConfig` | `BrowserExtensionSolanaWalletConfig` | `SolanaWalletDefaults` |
|
|
51
|
+
| Sui | `SuiWalletConfig` | `PrivateKeySuiWalletConfig` | `BrowserExtensionSuiWalletConfig` | `SuiWalletDefaults` |
|
|
52
|
+
| Bitcoin | `BitcoinWalletConfig` | `PrivateKeyBitcoinWalletConfig` | `BrowserExtensionBitcoinWalletConfig` | `BitcoinWalletDefaults` |
|
|
53
|
+
| Stellar | `StellarWalletConfig` | `PrivateKeyStellarWalletConfig` | `BrowserExtensionStellarWalletConfig` | `StellarWalletDefaults` |
|
|
54
|
+
| ICON | `IconWalletConfig` | `PrivateKeyIconWalletConfig` | `BrowserExtensionIconWalletConfig` | `IconWalletDefaults` |
|
|
55
|
+
| Injective | `InjectiveWalletConfig` | `SecretInjectiveWalletConfig` ⚠ | `BrowserExtensionInjectiveWalletConfig` | `InjectiveWalletDefaults` |
|
|
56
|
+
| NEAR | `NearWalletConfig` | `PrivateKeyNearWalletConfig` | `BrowserExtensionNearWalletConfig` | `NearWalletDefaults` |
|
|
57
|
+
| Stacks | `StacksWalletConfig` | `PrivateKeyStacksWalletConfig` | `BrowserExtensionStacksWalletConfig` | `StacksWalletDefaults` |
|
|
58
|
+
|
|
59
|
+
⚠ **Injective uses `Secret*`, not `PrivateKey*`** — see [`../features/injective.md`](../features/injective.md).
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Per-chain helpers and supporting types
|
|
64
|
+
|
|
65
|
+
| Export | Chain | Purpose |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `getEvmViemChain(key: EvmChainKey)` | EVM | Maps a chain key to its viem `Chain` config. Exhaustive — adding a new key fails typecheck until handled. |
|
|
68
|
+
| `hyper` (viem `Chain`) | EVM | Locally-defined HyperEVM chain config (not in `viem/chains`). |
|
|
69
|
+
| `isPrivateKeyEvmWalletConfig` | EVM | Predicate for narrowing `EvmWalletConfig`. |
|
|
70
|
+
| `isBrowserExtensionEvmWalletConfig` | EVM | Predicate for narrowing `EvmWalletConfig`. |
|
|
71
|
+
| `EvmSendTransactionPolicy` | EVM | Per-call options shape for `sendTransaction`. |
|
|
72
|
+
| `EvmWaitForTransactionReceiptPolicy` | EVM | Per-call options shape for `waitForTransactionReceipt`. |
|
|
73
|
+
| `WalletContextState` | Solana | Subset of `@solana/wallet-adapter-react` context — used by browser-extension config. |
|
|
74
|
+
| `SuiSignAndExecutePolicy` | Sui | Per-call options for `signAndExecuteTxn`. |
|
|
75
|
+
| `SuiGetCoinsPolicy` | Sui | Per-call options for `getCoins`. |
|
|
76
|
+
| `BitcoinNetwork` | Bitcoin | `'TESTNET' \| 'MAINNET'` |
|
|
77
|
+
| `BitcoinWalletsKit` (interface) | Bitcoin | Adapter contract for browser-extension mode. |
|
|
78
|
+
| `BitcoinPkWallet` / `BitcoinBrowserWallet` / `BitcoinWallet` | Bitcoin | Internal runtime-wallet union (exported for type assertions in tests). |
|
|
79
|
+
| `StellarNetwork` | Stellar | `'TESTNET' \| 'PUBLIC'` |
|
|
80
|
+
| `StellarAddress` | Stellar | `string` brand. |
|
|
81
|
+
| `StellarWalletsKit` (interface) | Stellar | Adapter contract for browser-extension mode. |
|
|
82
|
+
| `StellarPkWallet` / `StellarBrowserExtensionWallet` / `StellarWallet` | Stellar | Internal runtime-wallet union (exported for tests). |
|
|
83
|
+
| `IconJsonRpcVersion` / `Hex` / `Hash` / `IconAddress` / `IconEoaAddress` | ICON | Address & hex brands. |
|
|
84
|
+
| `IconPkWallet` / `IconBrowserExtensionWallet` / `IconWallet` | ICON | Internal runtime-wallet union. |
|
|
85
|
+
| `HanaWalletRequestEvent` / `HanaWalletResponseEvent` | ICON | Event names for the Hana wallet `postMessage` bridge. |
|
|
86
|
+
| `ResponseAddressType` / `ResponseSigningType` / `RelayRequestDetail` / `RelayRequestSigning` / `JsonRpcPayloadResponse` | ICON | Hana wallet message shapes. |
|
|
87
|
+
| `InjectiveWallet` | Injective | Internal runtime-wallet shape. |
|
|
88
|
+
| `NearTxExecutionStatus` | NEAR | `'NONE' \| 'INCLUDED' \| 'EXECUTED_OPTIMISTIC' \| 'INCLUDED_FINAL' \| 'EXECUTED' \| 'FINAL'` |
|
|
89
|
+
| `StacksPkWallet` / `StacksBrowserExtensionWallet` / `StacksWallet` | Stacks | Internal runtime-wallet union. |
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## `library-exports` (types + a few runtime values)
|
|
94
|
+
|
|
95
|
+
Re-exports from upstream chain SDKs. See [`../recipes/library-exports.md`](../recipes/library-exports.md) for the full table and intended usage.
|
|
96
|
+
|
|
97
|
+
Type-only (selected examples):
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import type {
|
|
101
|
+
WalletClient, PublicClient, TransactionReceipt, // from viem
|
|
102
|
+
SuiTransactionBlockResponseOptions, // from @mysten/sui
|
|
103
|
+
Commitment, ConnectionConfig, SendOptions, // from @solana/web3.js
|
|
104
|
+
Network, ChainId, EvmChainId, MsgBroadcaster, // from @injectivelabs/*
|
|
105
|
+
ClarityValue, PostConditionModeName, // from @stacks/transactions
|
|
106
|
+
StacksNetwork, StacksProvider, // from @stacks/network, @stacks/connect
|
|
107
|
+
KeyPairString, NearConnector, // from near-api-js, @hot-labs/near-connect
|
|
108
|
+
BitcoinJsNetwork, // from bitcoinjs-lib
|
|
109
|
+
} from '@sodax/wallet-sdk-core';
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Runtime values:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { Networks, PostConditionMode } from '@sodax/wallet-sdk-core';
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## NOT exported (intentional)
|
|
121
|
+
|
|
122
|
+
| Symbol | Where it lives | Why hidden |
|
|
123
|
+
|---|---|---|
|
|
124
|
+
| `shallowMerge` | `src/utils/merge.ts` | Internal merge helper — semantics may change. |
|
|
125
|
+
| Anything under `src/utils/` | — | All internal. |
|
|
126
|
+
| `EvmWalletProvider.serializeReceipt` | private static method | Implementation detail of `waitForTransactionReceipt`. |
|
|
127
|
+
|
|
128
|
+
If you need one of these, the corresponding **behavior** is exposed via a method — call that instead.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Migration: v1 → v2 (Human-readable overview)
|
|
2
|
+
|
|
3
|
+
This folder documents how to upgrade an app from **v1** of `@sodax/wallet-sdk-core` (the legacy `sodax-frontend` codebase) to **v2** (this repo). The package name did not change — and **the public surface is intentionally backwards-compatible**. v1 consumer code drops in unchanged.
|
|
4
|
+
|
|
5
|
+
This folder is the **human-facing** entry point for the upgrade. If you are a coding agent, read [`ai-rules.md`](./ai-rules.md) first. If you are integrating for the first time, see `../integration/` instead.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Scope
|
|
10
|
+
|
|
11
|
+
v1 (`sodax-frontend/packages/wallet-sdk-core`) and v2 (current) share:
|
|
12
|
+
|
|
13
|
+
- **Identical class names**: `EvmWalletProvider`, `InjectiveWalletProvider`, `BitcoinWalletProvider`, … (all 9).
|
|
14
|
+
- **Identical config-type names**: `PrivateKeyEvmWalletConfig`, `SecretInjectiveWalletConfig`, `BrowserExtension*WalletConfig`, …
|
|
15
|
+
- **Identical config shapes**: same required fields, same discriminants, same Injective `secret: { privateKey | mnemonics }` nesting.
|
|
16
|
+
- **Identical public method signatures**: `getWalletAddress`, `sendTransaction`, `signAndExecuteTxn`, …
|
|
17
|
+
|
|
18
|
+
What v2 **added** (all optional, all additive):
|
|
19
|
+
|
|
20
|
+
1. **`defaults` config** — every `*WalletConfig` gained an optional `defaults?: *WalletDefaults` field. Used to encode env-level constants (default gas, default commitment, …) once at construction.
|
|
21
|
+
2. **`library-exports`** — types and a few runtime enums re-exported from `@sodax/wallet-sdk-core`. Lets consumers drop direct deps on `viem`, `@mysten/sui`, `@stellar/stellar-sdk`, etc. for type-only usage.
|
|
22
|
+
3. **`BaseWalletProvider<TDefaults>`** — abstract base class shared by every provider. Holds `defaults` and exposes shallow-merge helpers. Internal — consumer code does not extend it.
|
|
23
|
+
4. **`*WalletDefaults` and `*Policy` types** — exported alongside each chain's config types.
|
|
24
|
+
5. **Folder-per-chain source layout** — `wallet-providers/evm/EvmWalletProvider.ts` (v2) replaced `wallet-providers/EvmWalletProvider.ts` (v1). Only matters if you deep-imported from `src/`.
|
|
25
|
+
|
|
26
|
+
What was **removed** or **renamed**: **nothing**. There is no mandatory edit.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Read order
|
|
31
|
+
|
|
32
|
+
If you are upgrading by hand, read in this order:
|
|
33
|
+
|
|
34
|
+
1. [`ai-rules.md`](./ai-rules.md) — workflow + stop conditions. **Drop-in upgrade is the default**; only adopt new features if you want them.
|
|
35
|
+
2. [`breaking-changes/README.md`](./breaking-changes/README.md) — every additive change, with a `Why:` line each.
|
|
36
|
+
3. [`recipes/`](./recipes/) — paired before/after **only** for optional cleanup tasks (adopt `defaults`, adopt `library-exports`).
|
|
37
|
+
4. [`checklist.md`](./checklist.md) — verification pass.
|
|
38
|
+
|
|
39
|
+
If you are letting a coding agent drive the upgrade, point it at [`ai-rules.md`](./ai-rules.md) — that file gives the agent its workflow and verification protocol.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## TL;DR for the impatient
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# 1. Update version in package.json
|
|
47
|
+
pnpm add @sodax/wallet-sdk-core@latest
|
|
48
|
+
|
|
49
|
+
# 2. Type-check — expect zero errors from wallet-sdk-core surface
|
|
50
|
+
pnpm exec tsc --noEmit | grep -iE "wallet-sdk-core|WalletProvider|WalletConfig"
|
|
51
|
+
# (errors here indicate either v1 deep imports or a real bug — file an issue)
|
|
52
|
+
|
|
53
|
+
# 3. Done. Optional cleanups in recipes/ when you have time.
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## What is NOT covered here
|
|
59
|
+
|
|
60
|
+
- **Other SODAX packages** (`@sodax/sdk`, `@sodax/types`, `@sodax/wallet-sdk-react`, `@sodax/dapp-kit`). They each have their own migration docs and **real** v1→v2 breaks.
|
|
61
|
+
- **Upstream chain-SDK upgrades** (viem 2.x → 3.x, etc.) — out of scope.
|
|
62
|
+
- **App framework upgrades** (Node, Vite, Next.js) — out of scope.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Tip: typecheck-driven verification
|
|
67
|
+
|
|
68
|
+
The repo includes `apps/node/` (Node scripts) and `apps/demo_v1/` (React demo). Running `pnpm exec tsc --noEmit` from either reveals breaking changes — but for wallet-sdk-core specifically, **none of those errors come from this package**. If you see `wallet-sdk-core` in the error output, it's most likely:
|
|
69
|
+
|
|
70
|
+
- A deep import from `src/...` (never supported; the v2 source layout differs).
|
|
71
|
+
- Indirect — a broken `@sodax/sdk` / `@sodax/types` signature that includes a wallet-provider type.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Filter to wallet-sdk-core specifically
|
|
75
|
+
pnpm exec tsc --noEmit | grep -iE "from '@sodax/wallet-sdk-core'|@sodax/wallet-sdk-core/"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
That filtered output is your work list. In a typical project the list is empty.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Getting help
|
|
83
|
+
|
|
84
|
+
If you do hit a v1 pattern that doesn't compile against v2, [open an issue](https://github.com/icon-project/sodax-sdks/issues) with the source snippet — that means we missed a backwards-compat case and the migration scope needs to grow.
|