@palliora.org/chainsdk 0.1.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 +254 -0
- package/dist/index.cjs +1687 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +811 -0
- package/dist/index.d.ts +811 -0
- package/dist/index.js +1687 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
## What this SDK provides
|
|
2
|
+
|
|
3
|
+
- API initialization helpers for Palliora.
|
|
4
|
+
- Keyring helpers for regular signing keys and encryption-oriented keys.
|
|
5
|
+
- Wrapper functions for Palliora-specific RPC calls and extrinsics, especially in `guardian/`, `da/`, `compute/`, and `stake/`.
|
|
6
|
+
- Utility helpers for token formatting.
|
|
7
|
+
- Crypto helpers for threshold-encryption-adjacent and hybrid encryption workflows.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @palliora/chainsdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Node.js 18+ is expected.
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
The SDK reads these environment variables:
|
|
20
|
+
|
|
21
|
+
- `PALLIORA_WS`: WebSocket endpoint for the chain. Defaults to `wss://manas-rpc.palliora.org`.
|
|
22
|
+
- `DEBUG=true`: Enables debug logging in wrapper helpers.
|
|
23
|
+
- `TX_WAIT_FINALIZATION=true`: Wait for finalization instead of returning once the tx is in-block.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
export PALLIORA_WS=wss://manas-rpc.palliora.org
|
|
29
|
+
export DEBUG=true
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
|
|
34
|
+
The most common flow is:
|
|
35
|
+
|
|
36
|
+
1. Initialize the API.
|
|
37
|
+
2. Load or create a signing account from the keyring.
|
|
38
|
+
3. Fetch token metadata once.
|
|
39
|
+
4. Call the wrapper functions you need.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import {
|
|
43
|
+
getKeyring,
|
|
44
|
+
fetchTokenProperties,
|
|
45
|
+
formatBalanceWithTokenProperties,
|
|
46
|
+
getGuardianList,
|
|
47
|
+
submitData,
|
|
48
|
+
newStake,
|
|
49
|
+
transfer,
|
|
50
|
+
} from "@palliora/chainsdk";
|
|
51
|
+
|
|
52
|
+
async function main() {
|
|
53
|
+
const keyring = await getKeyring();
|
|
54
|
+
const amount = BigInt("1000000000000000000000"); // 1000 PALI
|
|
55
|
+
|
|
56
|
+
// The SDK adds a default //Bob dev account. For real use, add your own signer.
|
|
57
|
+
const account = keyring.addFromUri("//Alice");
|
|
58
|
+
|
|
59
|
+
const token = await fetchTokenProperties();
|
|
60
|
+
console.log("Token:", token.symbol, token.decimals);
|
|
61
|
+
console.log(
|
|
62
|
+
"Formatted sample balance:",
|
|
63
|
+
await formatBalanceWithTokenProperties(amount.toString()),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const guardians = await getGuardianList();
|
|
67
|
+
console.log("Active guardians:", guardians);
|
|
68
|
+
|
|
69
|
+
await submitData(account, "hello from chainsdk");
|
|
70
|
+
await newStake(account, amount);
|
|
71
|
+
await transfer(account, amount, "5F3sa2TJAWMqDhXG6jhV4N8ko9qQ7x7T9nM8uA8V2sR8hF4M");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
main().catch(console.error);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## API and keystore initialization
|
|
78
|
+
|
|
79
|
+
Use these when you want a broader integration and may combine SDK wrappers with direct RPC calls.
|
|
80
|
+
|
|
81
|
+
### Default initialization
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { getApi, getKeyring } from "@palliora/chainsdk";
|
|
85
|
+
|
|
86
|
+
const api = await getApi();
|
|
87
|
+
const keyring = await getKeyring();
|
|
88
|
+
|
|
89
|
+
const signer = keyring.addFromUri("//Alice");
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- `getApi()` returns the shared `ApiPromise` instance.
|
|
93
|
+
- `getKeyring()` returns the shared `sr25519` keyring for signing.
|
|
94
|
+
|
|
95
|
+
## Wrapper calls
|
|
96
|
+
|
|
97
|
+
The wrappers can be called directly once the API is initialized. Transaction wrappers expect a signer account. Read-only RPC wrappers only need the API connection.
|
|
98
|
+
|
|
99
|
+
### Guardian
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import {
|
|
103
|
+
getGuardianList,
|
|
104
|
+
createGuardianGroup,
|
|
105
|
+
joinGuardian,
|
|
106
|
+
} from "@palliora/chainsdk";
|
|
107
|
+
|
|
108
|
+
const guardians = await getGuardianList();
|
|
109
|
+
|
|
110
|
+
await createGuardianGroup(account, guardians.slice(0, 3));
|
|
111
|
+
|
|
112
|
+
await joinGuardian(account, {
|
|
113
|
+
standard: true,
|
|
114
|
+
verifier: true,
|
|
115
|
+
compute: "trusted,tee",
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Main guardian exports:
|
|
120
|
+
|
|
121
|
+
- `getGuardianList()`
|
|
122
|
+
- `createGuardianGroup(account, selectedGuardians)`
|
|
123
|
+
- `joinGuardian(account, prefs)`
|
|
124
|
+
|
|
125
|
+
### Data availability
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { submitData } from "@palliora/chainsdk";
|
|
129
|
+
|
|
130
|
+
await submitData(account, "payload to store on Palliora DA");
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Main DA export:
|
|
134
|
+
|
|
135
|
+
- `submitData(account, data)`
|
|
136
|
+
|
|
137
|
+
### Compute
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { createAgreement, getGuardianParticipants } from "@palliora/chainsdk";
|
|
141
|
+
|
|
142
|
+
await createAgreement();
|
|
143
|
+
|
|
144
|
+
const participants = await getGuardianParticipants();
|
|
145
|
+
console.log(participants);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Main compute exports:
|
|
149
|
+
|
|
150
|
+
- `createAgreement()`
|
|
151
|
+
|
|
152
|
+
### Stake
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import {
|
|
156
|
+
newStake,
|
|
157
|
+
addStake,
|
|
158
|
+
reduceStake,
|
|
159
|
+
payoutStake,
|
|
160
|
+
removeStake,
|
|
161
|
+
withdrawStake,
|
|
162
|
+
tokenToBigint,
|
|
163
|
+
} from "@palliora/chainsdk";
|
|
164
|
+
|
|
165
|
+
const amount = tokenToBigint(100);
|
|
166
|
+
|
|
167
|
+
await newStake(account, amount, "Staked");
|
|
168
|
+
await addStake(account, amount);
|
|
169
|
+
await reduceStake(account, tokenToBigint(25));
|
|
170
|
+
await payoutStake(account, [123, 124]);
|
|
171
|
+
await removeStake(account);
|
|
172
|
+
await withdrawStake(account);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Main stake exports:
|
|
176
|
+
|
|
177
|
+
- `newStake(account, amount, rewardDestination?)`
|
|
178
|
+
- `addStake(account, amount)`
|
|
179
|
+
- `reduceStake(account, amount)`
|
|
180
|
+
- `removeStake(account)`
|
|
181
|
+
- `withdrawStake(account)`
|
|
182
|
+
- `payoutStake(account, eras)`
|
|
183
|
+
- `joinIdleStaker(account, prefs)`
|
|
184
|
+
|
|
185
|
+
### Token
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { fundAccount, transfer, tokenToBigint } from "@palliora/chainsdk";
|
|
189
|
+
|
|
190
|
+
await fundAccount(account, tokenToBigint(50));
|
|
191
|
+
await transfer(account, tokenToBigint(10), "5F3sa2TJAWMqDhXG6jhV4N8ko9qQ7x7T9nM8uA8V2sR8hF4M");
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Main token exports:
|
|
195
|
+
|
|
196
|
+
- `fundAccount(account, amount, address?)`
|
|
197
|
+
- `transfer(account, amount, address)`
|
|
198
|
+
|
|
199
|
+
## Useful helpers
|
|
200
|
+
|
|
201
|
+
### Chain helpers
|
|
202
|
+
|
|
203
|
+
- `signAndSend(tx, account)`
|
|
204
|
+
- `getGuardianAddress()`
|
|
205
|
+
- `setIdentity(account, { display })`
|
|
206
|
+
- `joinValidator(account, commission)`
|
|
207
|
+
|
|
208
|
+
### Utility helpers
|
|
209
|
+
|
|
210
|
+
- `tokenToBigint(value)`
|
|
211
|
+
- `hexToUint8Array(hex)`
|
|
212
|
+
- `decodeField(base64, expectedLength?)`
|
|
213
|
+
- `generateRandomBytes(length?)`
|
|
214
|
+
|
|
215
|
+
### Crypto helpers
|
|
216
|
+
|
|
217
|
+
The crypto module contains small helper functions for hybrid encryption flows and lower-level threshold-encryption-related work.
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
import {
|
|
221
|
+
gen_shared_key,
|
|
222
|
+
gen_stretched_key,
|
|
223
|
+
encrypt,
|
|
224
|
+
decrypt,
|
|
225
|
+
} from "@palliora/chainsdk";
|
|
226
|
+
|
|
227
|
+
const shared = gen_shared_key(mySecretKeyBytes, peerPublicKeyBytes);
|
|
228
|
+
const key = gen_stretched_key(shared);
|
|
229
|
+
|
|
230
|
+
const message = new TextEncoder().encode("hello");
|
|
231
|
+
const sealed = encrypt(message, key);
|
|
232
|
+
const opened = decrypt(sealed.ciphertext, key, sealed.nonce);
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Main crypto exports:
|
|
236
|
+
|
|
237
|
+
- `gen_shared_key(key, pk)`
|
|
238
|
+
- `gen_stretched_key(input)`
|
|
239
|
+
- `encrypt(plaintext, key)`
|
|
240
|
+
- `decrypt(ciphertext, key, nonce)`
|
|
241
|
+
- `generateRandomBytes(length?)`
|
|
242
|
+
|
|
243
|
+
## Choosing between raw API and wrappers
|
|
244
|
+
|
|
245
|
+
Use the wrappers when:
|
|
246
|
+
|
|
247
|
+
- You want the simplest way to call Palliora-specific RPCs or extrinsics.
|
|
248
|
+
- The SDK already exposes some of the operations.
|
|
249
|
+
|
|
250
|
+
Use `getApi()` and the keyring helpers when:
|
|
251
|
+
|
|
252
|
+
- You need custom query logic beyond the shipped wrappers.
|
|
253
|
+
- You want to mix Palliora wrappers with direct RPC calls.
|
|
254
|
+
- Most transaction helpers expect an `account` compatible with RPC `signAndSend`.
|