@orbinum/sdk 0.1.0 → 0.3.0

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 ADDED
@@ -0,0 +1,209 @@
1
+ # @orbinum/sdk
2
+
3
+ Official TypeScript SDK for Orbinum — a privacy-focused blockchain built on Substrate with an EVM compatibility layer.
4
+
5
+ The SDK provides typed modules for interacting with the Orbinum protocol: shielded pool operations, account identity and mapping, chain queries, EVM JSON-RPC, and the indexer REST API.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @orbinum/sdk
11
+ # or
12
+ pnpm add @orbinum/sdk
13
+ ```
14
+
15
+ ## Requirements
16
+
17
+ - Node.js 18 or later
18
+ - A running Orbinum node (Substrate WebSocket endpoint)
19
+ - An EVM JSON-RPC endpoint (optional, required for EVM and precompile operations)
20
+
21
+ ## Quick Start
22
+
23
+ ```ts
24
+ import { OrbinumClient } from '@orbinum/sdk';
25
+
26
+ const client = await OrbinumClient.connect({
27
+ substrateWs: 'ws://localhost:9944',
28
+ evmRpc: 'http://localhost:9933',
29
+ });
30
+ ```
31
+
32
+ `OrbinumClient` wires together all modules and exposes them under a single interface. Each module can also be instantiated independently.
33
+
34
+ ## Modules
35
+
36
+ ### SubstrateClient
37
+
38
+ Thin wrapper over [polkadot-api](https://github.com/polkadot-api/polkadot-api) (PAPI) for Substrate WebSocket communication.
39
+
40
+ ```ts
41
+ import { SubstrateClient } from '@orbinum/sdk';
42
+
43
+ const substrate = await SubstrateClient.connect('ws://localhost:9944');
44
+
45
+ // Raw JSON-RPC call
46
+ const result = await substrate.request('system_name', []);
47
+
48
+ // Build a transaction from pre-encoded SCALE call bytes
49
+ const tx = await substrate.txFromCallData(callBytes);
50
+ const finalized = await tx.signAndSubmit(signer);
51
+
52
+ // Submit a pre-signed extrinsic
53
+ const finalized = await substrate.submit(signedHex);
54
+
55
+ // Submit and observe lifecycle events
56
+ substrate.submitAndWatch(signedHex).subscribe(event => console.log(event));
57
+ ```
58
+
59
+ ### EvmClient
60
+
61
+ Stateless HTTP client following the Ethereum JSON-RPC specification.
62
+
63
+ ```ts
64
+ import { EvmClient } from '@orbinum/sdk';
65
+
66
+ const evm = new EvmClient('http://localhost:9933');
67
+
68
+ const balance = await evm.getBalance('0xYourAddress');
69
+ const chainId = await evm.getChainId();
70
+ const txHash = await evm.sendRawTransaction(signedHex);
71
+
72
+ // Batch multiple calls in a single HTTP request
73
+ const [balance, nonce] = await evm.batchRequest([
74
+ { method: 'eth_getBalance', params: ['0xAddr', 'latest'] },
75
+ { method: 'eth_getTransactionCount', params: ['0xAddr', 'latest'] },
76
+ ]);
77
+ ```
78
+
79
+ ### ShieldedPoolModule
80
+
81
+ High-level interface for shielded pool operations. Requires a loaded `PrivacyKeyManager` and ZK proofs for unshield and private transfer.
82
+
83
+ ```ts
84
+ // Shield (deposit) tokens into the shielded pool
85
+ const { txResult, note } = await client.shieldedPool.buildAndShield({
86
+ amount: 1_000_000n,
87
+ tokenAddress: '0xTokenAddress',
88
+ }, signer);
89
+
90
+ // Private transfer between notes
91
+ await client.shieldedPool.privateTransfer({ ...params }, signer);
92
+
93
+ // Unshield (withdraw) tokens to a public address
94
+ await client.shieldedPool.unshield({ ...params }, signer);
95
+
96
+ // Check if a nullifier has been spent
97
+ const spent = await client.shieldedPool.isNullifierSpent('0xNullifier');
98
+ ```
99
+
100
+ ### Privacy Keys
101
+
102
+ Key derivation follows a deterministic chain from the user's wallet signature. No key material is ever stored by the SDK.
103
+
104
+ ```ts
105
+ import { PrivacyKeys, PrivacyKeyManager } from '@orbinum/sdk';
106
+
107
+ // 1. Get the message the user must sign
108
+ const message = PrivacyKeys.deriveSpendingKeyMessage(chainId, evmAddress);
109
+
110
+ // 2. Derive the spending key from the wallet signature
111
+ const spendingKey = PrivacyKeys.deriveSpendingKeyFromSignature(sigHex, chainId, evmAddress);
112
+
113
+ // 3. Load into the key manager
114
+ const keyManager = new PrivacyKeyManager();
115
+ keyManager.load(spendingKey);
116
+
117
+ // The manager derives the viewing key (ChaCha20 memo decryption)
118
+ // and owner public key (BabyJubJub, used in note commitments)
119
+ const viewingKey = keyManager.getViewingKey();
120
+ const ownerPk = keyManager.getOwnerPk();
121
+ ```
122
+
123
+ ### AccountMappingModule
124
+
125
+ Manage on-chain identity by linking Substrate and EVM accounts, registering aliases, and interacting with the alias marketplace.
126
+
127
+ ```ts
128
+ // Register an alias
129
+ await client.accountMapping.registerAlias({ alias: 'myalias' }, signer);
130
+
131
+ // Link an EVM address to a Substrate account
132
+ await client.accountMapping.addChainLink({ chainId: 1, address: '0xEvmAddr' }, signer);
133
+
134
+ // Query
135
+ const alias = await client.accountMapping.getAliasOf(substrateHex);
136
+ const linked = await client.accountMapping.getChainLinks(substrateHex);
137
+ ```
138
+
139
+ ### ChainModule
140
+
141
+ Query chain information bridging Substrate and EVM endpoints.
142
+
143
+ ```ts
144
+ const info = await client.chain.getChainInfo(); // name, spec, SS58 prefix
145
+ const identity = await client.chain.getFullIdentity(address);
146
+ const health = await client.chain.getHealth();
147
+ const evmBlock = await client.chain.getEvmBlockNumber();
148
+ ```
149
+
150
+ ### IndexerClient
151
+
152
+ HTTP client for the Orbinum indexer REST API. The indexer runs as a separate service indexed from node events.
153
+
154
+ ```ts
155
+ import { IndexerClient } from '@orbinum/sdk';
156
+
157
+ const indexer = new IndexerClient('https://indexer.orbinum.io');
158
+
159
+ const commitments = await indexer.getCommitments({ page: 1, limit: 20 });
160
+ const status = await indexer.getNullifierStatus('0xNullifier');
161
+ const roots = await indexer.getMerkleRoots({ limit: 10 });
162
+ ```
163
+
164
+ ### Precompiles
165
+
166
+ Typed wrappers for Orbinum's EVM precompile contracts, callable from any EVM wallet or signer.
167
+
168
+ | Precompile | Address | Description |
169
+ |---|---|---|
170
+ | `ShieldedPoolPrecompile` | `0x0801` | Shield, unshield, and private transfer from EVM |
171
+ | `AccountMappingPrecompile` | `0x0800` | Identity and alias operations from EVM |
172
+ | `CryptoPrecompiles` | `0x0400–0x0403` | Frontier crypto utilities (SHA3, EC recover, Curve25519) |
173
+
174
+ ```ts
175
+ import { ShieldedPoolPrecompile } from '@orbinum/sdk';
176
+
177
+ const precompile = new ShieldedPoolPrecompile(evmClient);
178
+ await precompile.shield(amount, tokenAddress, commitment, walletSigner);
179
+ ```
180
+
181
+ ## Key Derivation Chain
182
+
183
+ ```
184
+ wallet.sign(message)
185
+ |
186
+ v
187
+ deriveSpendingKeyFromSignature() -- HKDF-SHA256 over signature bytes, mod BN254_R
188
+ |
189
+ +-- deriveViewingKey() -- HKDF-SHA256 -> 32-byte ChaCha20 symmetric key
190
+ | (used to encrypt/decrypt note memos)
191
+ |
192
+ +-- deriveOwnerPk() -- BabyJubJub scalar multiplication -> Ax
193
+ (embedded in shielded note commitments)
194
+ ```
195
+
196
+ ## Development
197
+
198
+ ```bash
199
+ pnpm install
200
+ pnpm build # compile to dist/ (ESM + CJS + types)
201
+ pnpm test # run test suite
202
+ pnpm typecheck:all # typecheck src and tests
203
+ pnpm lint # eslint
204
+ pnpm format # prettier
205
+ ```
206
+
207
+ ## License
208
+
209
+ ISC