@parity/product-sdk-terminal 0.0.0-dev.312.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/LICENSE +201 -0
- package/README.md +337 -0
- package/dist/chunk-GHOFKVUG.js +210 -0
- package/dist/chunk-GHOFKVUG.js.map +1 -0
- package/dist/chunk-YS3GW2XW.js +1508 -0
- package/dist/chunk-YS3GW2XW.js.map +1 -0
- package/dist/host-C3KVvc1j.d.ts +218 -0
- package/dist/host.d.ts +4 -0
- package/dist/host.js +15 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +262 -0
- package/dist/index.js +1162 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.d.ts +92 -0
- package/dist/testing.js +313 -0
- package/dist/testing.js.map +1 -0
- package/package.json +65 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { T as TerminalAdapter } from './host-C3KVvc1j.js';
|
|
2
|
+
export { A as AllocatableResource, a as ApAllocationOutcome, O as OnExistingAllowancePolicy, R as RequestResourceAllocationOptions, b as TerminalAdapterOptions, c as createTerminalAdapter, r as requestResourceAllocation, s as sendResourceAllocation } from './host-C3KVvc1j.js';
|
|
3
|
+
import { UserSession } from '@novasamatech/host-papp';
|
|
4
|
+
export { AllowanceError, AllowanceErrorReason, AllowanceService, HostMetadata, PairingStatus, PappAdapter, SS_PASEO_STABLE_STAGE_ENDPOINTS, SS_STABLE_STAGE_ENDPOINTS, SigningPayloadRequest, SigningPayloadResponse, SigningRawRequest, StoredUserSession, UserSession } from '@novasamatech/host-papp';
|
|
5
|
+
import { PolkadotSigner } from 'polkadot-api';
|
|
6
|
+
export { AllowanceExpiredError, SignerError } from '@parity/product-sdk-signer/errors';
|
|
7
|
+
import { StatementProver } from '@novasamatech/statement-store';
|
|
8
|
+
import { StorageAdapter } from '@novasamatech/storage-adapter';
|
|
9
|
+
import 'neverthrow';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create a PolkadotSigner from a QR-paired session.
|
|
13
|
+
*
|
|
14
|
+
* Routes **transaction signing** through `session.createTransaction` — the
|
|
15
|
+
* host-papp `CreateTransactionRequest`/`CreateTransactionResponse` SSO
|
|
16
|
+
* message pair. We hand the mobile app the structured
|
|
17
|
+
* `ProductAccountTransaction` (`signer`, `genesisHash`, `callData`, the
|
|
18
|
+
* per-extension `{ extra, additionalSigned }`, and `txExtVersion`) and it
|
|
19
|
+
* **builds and signs** the full extrinsic, returning the signed bytes.
|
|
20
|
+
*
|
|
21
|
+
* Two properties fall out of this:
|
|
22
|
+
* - The wallet can **decode and display** the transaction instead of
|
|
23
|
+
* blind-signing an opaque hash (which is what the older
|
|
24
|
+
* `session.signRaw({ tag: "Payload" })` route did).
|
|
25
|
+
* - Every signed extension the chain declares — including ones PAPI's PJS
|
|
26
|
+
* adapter doesn't know (e.g. `AsPgas` on Paseo Next v2) — is forwarded
|
|
27
|
+
* verbatim as `{ id, extra, additionalSigned }`, so nothing is lost in
|
|
28
|
+
* translation.
|
|
29
|
+
*
|
|
30
|
+
* **Raw-message signing** (`signBytes`) keeps the `session.signRaw` `Bytes`
|
|
31
|
+
* tag so the wallet applies the `<Bytes>...</Bytes>` anti-phishing wrap once
|
|
32
|
+
* on its side. Correct for arbitrary user data; wrong for extrinsic payloads
|
|
33
|
+
* (which is why the two paths split).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const [session] = adapter.sessions.sessions.read();
|
|
38
|
+
*
|
|
39
|
+
* // Default account — uses [adapter.appId, 0]:
|
|
40
|
+
* const signer = createSessionSigner(session, adapter);
|
|
41
|
+
*
|
|
42
|
+
* // Non-default derivation index, or a different productId:
|
|
43
|
+
* const subSigner = createSessionSignerForAccount(session, {
|
|
44
|
+
* productId: "my-product",
|
|
45
|
+
* derivationIndex: 3,
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* await contract.publish.tx(domain, cid, { signer, origin });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Identifies which sub-account of a paired session should sign.
|
|
54
|
+
*
|
|
55
|
+
* Mirrors the `host-papp` wire format `productAccountId: [productId, derivationIndex]`:
|
|
56
|
+
* `productId` is the dotNS-style identifier for the requesting product (matches
|
|
57
|
+
* the adapter's `appId` in normal usage); `derivationIndex` is the BIP32-style
|
|
58
|
+
* child-key index, where `0` is the session's default account.
|
|
59
|
+
*/
|
|
60
|
+
interface ProductAccountRef {
|
|
61
|
+
/** The product identifier. Usually equal to the adapter's `appId`. */
|
|
62
|
+
productId: string;
|
|
63
|
+
/** Child-key derivation index. `0` is the default account. */
|
|
64
|
+
derivationIndex: number;
|
|
65
|
+
/**
|
|
66
|
+
* The **product account's** sr25519 public key (32 bytes), as derived by the
|
|
67
|
+
* host for `[productId, derivationIndex]`.
|
|
68
|
+
*
|
|
69
|
+
* PAPI stamps this into the extrinsic's signer address and verifies the
|
|
70
|
+
* signature against it, so it must be the *product* account's key — not the
|
|
71
|
+
* wallet's selected/root account (`session.remoteAccount.accountId`). A
|
|
72
|
+
* mismatch produces an invalid signature.
|
|
73
|
+
*
|
|
74
|
+
* When omitted, the signer soft-derives it from the session's root account
|
|
75
|
+
* (`mnemonic + "/product/{productId}/{derivationIndex}"`), which is correct
|
|
76
|
+
* for every product account. Supply it explicitly only to avoid the
|
|
77
|
+
* re-derivation or when you've already derived it elsewhere.
|
|
78
|
+
*/
|
|
79
|
+
publicKey?: Uint8Array;
|
|
80
|
+
}
|
|
81
|
+
declare const INCOMPLETE_SESSION_MESSAGE = "Stored login session is missing the root account public key. Run \"logout\" and then \"login\" to pair again.";
|
|
82
|
+
/**
|
|
83
|
+
* The session's handshake-time root account public key (`rootUserAccountId` =
|
|
84
|
+
* the user's bare-mnemonic keypair on current mobile builds). This is the
|
|
85
|
+
* parent key product accounts soft-derive from. host-papp's live `UserSession`
|
|
86
|
+
* doesn't surface it on the public type, so we read it structurally.
|
|
87
|
+
*
|
|
88
|
+
* @throws {@link INCOMPLETE_SESSION_MESSAGE} if the session predates the
|
|
89
|
+
* `rootAccountId` field (a stale login that must re-pair).
|
|
90
|
+
*/
|
|
91
|
+
declare function sessionRootPublicKey(session: UserSession): Uint8Array;
|
|
92
|
+
/**
|
|
93
|
+
* Soft-derive a product account's sr25519 public key from a paired session's
|
|
94
|
+
* root account.
|
|
95
|
+
*
|
|
96
|
+
* This is the single source of truth for product-account math. The session
|
|
97
|
+
* signer uses it to stamp the correct signer address; consumers that need the
|
|
98
|
+
* product address *without* building a signer (e.g. a login-status display
|
|
99
|
+
* triple) call it directly so the displayed address can't desync from what the
|
|
100
|
+
* signer actually signs with.
|
|
101
|
+
*
|
|
102
|
+
* sr25519 soft derivation is composable on public keys alone, so deriving from
|
|
103
|
+
* `session.rootAccountId` locally produces the SAME key the host derives
|
|
104
|
+
* privately via `mnemonic + "/product/{productId}/{derivationIndex}"`.
|
|
105
|
+
*
|
|
106
|
+
* @throws {@link INCOMPLETE_SESSION_MESSAGE} on a stale session with no root key.
|
|
107
|
+
*/
|
|
108
|
+
declare function deriveProductPublicKey(session: UserSession, ref: ProductAccountRef): Uint8Array;
|
|
109
|
+
/**
|
|
110
|
+
* Create a `PolkadotSigner` backed by a QR-paired mobile wallet session,
|
|
111
|
+
* using the session's **default account** (`derivationIndex: 0`).
|
|
112
|
+
*
|
|
113
|
+
* For non-default sub-accounts, use {@link createSessionSignerForAccount}.
|
|
114
|
+
*
|
|
115
|
+
* @param session The paired user session.
|
|
116
|
+
* @param adapter The {@link TerminalAdapter} that loaded the session. Its `appId`
|
|
117
|
+
* is used as the `productId` in the wire request.
|
|
118
|
+
* @param publicKey The product account's sr25519 public key for
|
|
119
|
+
* `[adapter.appId, 0]`. Optional — when omitted it's soft-derived from the
|
|
120
|
+
* session root. See {@link ProductAccountRef.publicKey}.
|
|
121
|
+
*/
|
|
122
|
+
declare function createSessionSigner(session: UserSession, adapter: TerminalAdapter, publicKey?: Uint8Array): PolkadotSigner;
|
|
123
|
+
/**
|
|
124
|
+
* Create a `PolkadotSigner` for a specific sub-account of a paired session.
|
|
125
|
+
*
|
|
126
|
+
* Use this when you need a derivation index other than `0`, or a `productId`
|
|
127
|
+
* different from the adapter's `appId`. For the common default-account case,
|
|
128
|
+
* prefer {@link createSessionSigner}.
|
|
129
|
+
*
|
|
130
|
+
* @param session The paired user session.
|
|
131
|
+
* @param ref The product account to sign as: `{ productId, derivationIndex }`.
|
|
132
|
+
*/
|
|
133
|
+
declare function createSessionSignerForAccount(session: UserSession, ref: ProductAccountRef): PolkadotSigner;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Get a `PolkadotSigner` for a Bulletin allowance slot.
|
|
137
|
+
*
|
|
138
|
+
* Allocates an allowance slot via the paired wallet (or returns the cached
|
|
139
|
+
* one), derives the slot-account keypair, and returns a `PolkadotSigner`
|
|
140
|
+
* that signs Bulletin extrinsics with it. Replaces the manual
|
|
141
|
+
* `requestResourceAllocation` + `createSlotAccountSigner` two-step for the
|
|
142
|
+
* common case.
|
|
143
|
+
*
|
|
144
|
+
* @param adapter Terminal adapter.
|
|
145
|
+
* @param productId The product id the slot is allocated under. Passed to the
|
|
146
|
+
* host as the calling product id in the allowance request.
|
|
147
|
+
* @param sessionId Paired session to allocate against. Defaults to the only
|
|
148
|
+
* paired session; throws `AllowanceError('NoSession')` when zero or more
|
|
149
|
+
* than one sessions are paired and no explicit id is supplied.
|
|
150
|
+
* @throws {AllowanceError} On rejection, missing session, host-side failure,
|
|
151
|
+
* or unexpected response shape.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { createTerminalAdapter, getBulletinSigner } from "@parity/product-sdk-terminal";
|
|
156
|
+
*
|
|
157
|
+
* const adapter = createTerminalAdapter({ appId: "my-cli" });
|
|
158
|
+
* // ... QR pair, wait for session ...
|
|
159
|
+
* const signer = await getBulletinSigner(adapter, "my-cli.dot");
|
|
160
|
+
* await client.bulletin.tx.TransactionStorage.store({ data }).signAndSubmit(signer);
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
declare function getBulletinSigner(adapter: TerminalAdapter, productId: string, sessionId?: string): Promise<PolkadotSigner>;
|
|
164
|
+
/**
|
|
165
|
+
* Get a `StatementProver` for a statement-store allowance slot.
|
|
166
|
+
*
|
|
167
|
+
* Allocates an allowance slot via the paired wallet (or returns the cached
|
|
168
|
+
* one) and returns the upstream `StatementProver` for the slot. Use when
|
|
169
|
+
* publishing statements through `@novasamatech/statement-store` without
|
|
170
|
+
* holding a long-lived key yourself.
|
|
171
|
+
*
|
|
172
|
+
* @param adapter Terminal adapter.
|
|
173
|
+
* @param productId The product id the slot is allocated under.
|
|
174
|
+
* @param sessionId Paired session to allocate against. Defaults to the only
|
|
175
|
+
* paired session; throws `AllowanceError('NoSession')` when zero or more
|
|
176
|
+
* than one sessions are paired and no explicit id is supplied.
|
|
177
|
+
* @throws {AllowanceError} On rejection, missing session, host-side failure,
|
|
178
|
+
* or unexpected response shape.
|
|
179
|
+
*/
|
|
180
|
+
declare function getStatementStoreProver(adapter: TerminalAdapter, productId: string, sessionId?: string): Promise<StatementProver>;
|
|
181
|
+
/**
|
|
182
|
+
* Cache-only probe for a Bulletin allowance slot. Resolves `true` when a
|
|
183
|
+
* slot key for `(sessionId, productId, bulletin)` is already cached on
|
|
184
|
+
* disk; `false` when it is not. Never prompts the paired wallet.
|
|
185
|
+
*
|
|
186
|
+
* Pair with {@link getBulletinSigner} for the "check first, fetch only
|
|
187
|
+
* if needed" flow:
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* if (await hasBulletinAllowance(adapter, "my-cli.dot")) {
|
|
192
|
+
* // happy path — fetch the signer without risking a wallet prompt
|
|
193
|
+
* const signer = await getBulletinSigner(adapter, "my-cli.dot");
|
|
194
|
+
* } else {
|
|
195
|
+
* // tell the user a wallet prompt will fire, then call getBulletinSigner
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function hasBulletinAllowance(adapter: TerminalAdapter, productId: string, sessionId?: string): Promise<boolean>;
|
|
200
|
+
/**
|
|
201
|
+
* Cache-only probe for a Statement Store allowance slot. Resolves `true`
|
|
202
|
+
* when a slot key for `(sessionId, productId, statementStore)` is already
|
|
203
|
+
* cached on disk; `false` when it is not. Never prompts the paired wallet.
|
|
204
|
+
*
|
|
205
|
+
* Pair with {@link getStatementStoreProver} for the "check first, fetch
|
|
206
|
+
* only if needed" flow.
|
|
207
|
+
*/
|
|
208
|
+
declare function hasStatementStoreAllowance(adapter: TerminalAdapter, productId: string, sessionId?: string): Promise<boolean>;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Helpers for working with persisted sessions on a `TerminalAdapter`.
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Wait for the adapter to load at least one persisted session, or resolve
|
|
216
|
+
* with an empty array after `timeoutMs`.
|
|
217
|
+
*
|
|
218
|
+
* The session manager loads sessions from storage asynchronously, so a
|
|
219
|
+
* synchronous `adapter.sessions.sessions.read()` immediately after
|
|
220
|
+
* `createTerminalAdapter()` may return `[]` even when sessions exist on
|
|
221
|
+
* disk. Use this helper to give the loader a chance to populate before
|
|
222
|
+
* deciding whether the user is logged in.
|
|
223
|
+
*/
|
|
224
|
+
declare function waitForSessions(adapter: TerminalAdapter, timeoutMs?: number): Promise<UserSession[]>;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Terminal QR code rendering using Unicode half-block characters.
|
|
228
|
+
*
|
|
229
|
+
* Wraps the `qrcode` npm package's UTF-8 renderer, which packs two
|
|
230
|
+
* module rows per terminal line using half-block characters.
|
|
231
|
+
*/
|
|
232
|
+
/** Options for QR code rendering. */
|
|
233
|
+
interface QrRenderOptions {
|
|
234
|
+
/** Error correction level. Default: "M". */
|
|
235
|
+
errorCorrectionLevel?: "L" | "M" | "Q" | "H";
|
|
236
|
+
/** Quiet zone size in modules. Default: 2. */
|
|
237
|
+
margin?: number;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Encode a string as a QR code rendered in Unicode half-block characters.
|
|
241
|
+
*
|
|
242
|
+
* Returns a multi-line string suitable for `console.log`.
|
|
243
|
+
*/
|
|
244
|
+
declare function renderQrCode(data: string, options?: QrRenderOptions): Promise<string>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* File-based StorageAdapter for Node.js environments.
|
|
248
|
+
*
|
|
249
|
+
* Implements the @novasamatech/storage-adapter interface using JSON files
|
|
250
|
+
* in ~/.polkadot-apps/. Node.js doesn't have localStorage, so this
|
|
251
|
+
* provides persistent storage for the SDK's session and secret data.
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Create a file-based StorageAdapter for use with the host-papp SDK in Node.js.
|
|
256
|
+
*
|
|
257
|
+
* Data is stored as individual JSON files in the given directory
|
|
258
|
+
* (defaults to `~/.polkadot-apps/`).
|
|
259
|
+
*/
|
|
260
|
+
declare function createNodeStorageAdapter(appId: string, storageDir?: string): StorageAdapter;
|
|
261
|
+
|
|
262
|
+
export { INCOMPLETE_SESSION_MESSAGE, type ProductAccountRef, type QrRenderOptions, TerminalAdapter, createNodeStorageAdapter, createSessionSigner, createSessionSignerForAccount, deriveProductPublicKey, getBulletinSigner, getStatementStoreProver, hasBulletinAllowance, hasStatementStoreAllowance, renderQrCode, sessionRootPublicKey, waitForSessions };
|