@parity/product-sdk-host 0.10.3 → 0.12.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/src/types.ts CHANGED
@@ -3,22 +3,26 @@
3
3
  /**
4
4
  * Public types for the host wrappers.
5
5
  *
6
- * These are re-exported from `@novasamatech/host-api-wrapper` (the runtime
7
- * objects the host getters cast to) rather than hand-mirrored, so the
8
- * Parity surface stays in lockstep with the upstream codec types.
6
+ * The statement-store types are re-exported from `@parity/truapi` so the Parity
7
+ * surface stays in lockstep with the in-house protocol codec types. Their fields
8
+ * are `0x`-prefixed hex strings (`HexString`) and their enums are `{ tag }` unions.
9
9
  */
10
10
 
11
11
  import type {
12
- hostLocalStorage,
13
- createStatementStore,
14
- ProductAccountId as NovasamaProductAccountId,
15
- SignedStatement as NovasamaSignedStatement,
16
- Statement as NovasamaStatement,
17
- StatementTopicFilter as NovasamaStatementTopicFilter,
18
- StatementsPage as NovasamaStatementsPage,
19
- Topic as NovasamaTopic,
20
- } from "@novasamatech/host-api-wrapper";
21
- import type { Subscription } from "@novasamatech/host-api";
12
+ ProductAccountId,
13
+ RemoteStatementStoreSubscribeItem,
14
+ SignedStatement,
15
+ Statement,
16
+ StatementProof,
17
+ Topic,
18
+ } from "@parity/truapi";
19
+
20
+ // Statement-store types, re-exported verbatim from `@parity/truapi` (imported
21
+ // above for the local signatures): `Statement` / `SignedStatement` /
22
+ // `StatementProof` / `Topic` / `ProductAccountId`. Their fields are
23
+ // `0x`-prefixed `HexString`s and their enums are `{ tag }` unions; the proof
24
+ // variants cover `Sr25519` / `Ed25519` / `Ecdsa` / `OnChain`.
25
+ export type { ProductAccountId, SignedStatement, Statement, StatementProof, Topic };
22
26
 
23
27
  /**
24
28
  * Persistent storage exposed by the host container, including string, JSON
@@ -27,67 +31,71 @@ import type { Subscription } from "@novasamatech/host-api";
27
31
  * via {@link getHostLocalStorage} when you need raw host storage without the
28
32
  * KV abstraction.
29
33
  *
30
- * Type identical to `hostLocalStorage` from `@novasamatech/host-api-wrapper`.
34
+ * Backed by `truApi.localStorage.*` (raw `read`/`write`/`clear` over hex bytes);
35
+ * {@link getHostLocalStorage} adapts that into this richer surface. `readString`
36
+ * resolves to `""` for a missing key and `readJSON`/`readBytes` to
37
+ * `null`/`undefined`.
31
38
  */
32
- export type HostLocalStorage = typeof hostLocalStorage;
39
+ export interface HostLocalStorage {
40
+ /** Read a UTF-8 string value; `""` when the key is absent. */
41
+ readString(key: string): Promise<string>;
42
+ /** Write a UTF-8 string value. */
43
+ writeString(key: string, value: string): Promise<void>;
44
+ /** Read and JSON-parse a value; `null` when the key is absent. */
45
+ readJSON(key: string): Promise<unknown>;
46
+ /** JSON-stringify and write a value. */
47
+ writeJSON(key: string, value: unknown): Promise<void>;
48
+ /** Read raw bytes; `undefined` when the key is absent. */
49
+ readBytes(key: string): Promise<Uint8Array | undefined>;
50
+ /** Write raw bytes. */
51
+ writeBytes(key: string, value: Uint8Array): Promise<void>;
52
+ /** Remove a key. */
53
+ clear(key: string): Promise<void>;
54
+ }
33
55
 
34
56
  /**
35
- * Cryptographic proof attached to a statement before submission, returned by
36
- * {@link HostStatementStore.createProof}. Variants cover the supported
37
- * signature schemes - `Sr25519`, `Ed25519`, `Ecdsa`, and `OnChain` (chain-
38
- * attestation-based proofs).
57
+ * Topic-based subscription filter. The host delivers statements that match
58
+ * either *all* of the listed topics (`matchAll`) or *any* of them (`matchAny`).
39
59
  *
40
- * Inferred from `createStatementStore().createProof`'s return type so codec
41
- * changes surface here as compile errors, not runtime decode failures.
60
+ * This is a field-discriminated form of truapi's `RemoteStatementStoreSubscribeRequest`,
61
+ * which is a tagged union (`{ tag: "MatchAll"; value: Topic[] } | { tag: "MatchAny"; value: Topic[] }`).
62
+ * The transport maps between the two.
42
63
  */
43
- export type StatementProof = Awaited<
44
- ReturnType<ReturnType<typeof createStatementStore>["createProof"]>
45
- >;
46
-
47
- /**
48
- * Topic-based subscription filter. The host delivers statements that match
49
- * either *all* of the listed topics (`matchAll`) or *any* of them
50
- * (`matchAny`). Re-exported from `@novasamatech/host-api-wrapper`.
51
- */
52
- export type StatementTopicFilter = NovasamaStatementTopicFilter;
53
-
54
- /** A single topic value used inside a {@link StatementTopicFilter}. Re-exported from `@novasamatech/host-api-wrapper`. */
55
- export type Topic = NovasamaTopic;
56
-
57
- /** `[ss58Address, chainPrefix]` tuple identifying a product account at the codec layer. Re-exported from `@novasamatech/host-api-wrapper`. */
58
- export type ProductAccountId = NovasamaProductAccountId;
59
-
60
- /** Unsigned statement payload. Re-exported from `@novasamatech/host-api-wrapper`. */
61
- export type Statement = NovasamaStatement;
62
-
63
- /** Statement bundled with its {@link StatementProof}. Re-exported from `@novasamatech/host-api-wrapper`. */
64
- export type SignedStatement = NovasamaSignedStatement;
64
+ export type StatementTopicFilter = { matchAll: Topic[] } | { matchAny: Topic[] };
65
65
 
66
66
  /**
67
67
  * A page of signed statements delivered by {@link HostStatementStore.subscribe}.
68
68
  *
69
- * Pages arrive sequentially. `isComplete` is `true` on the final page of a
70
- * subscription's initial backfill; subsequent pages contain new statements
71
- * as they appear on chain. `statements` is `SignedStatement[]` (typed,
72
- * not `unknown[]`).
69
+ * truapi's `RemoteStatementStoreSubscribeItem`, re-exported under a friendlier
70
+ * name. Pages arrive sequentially; `isComplete` is `false` while the host
71
+ * streams the historical backfill and `true` once it's done (and on every
72
+ * subsequent live-update page).
73
73
  */
74
- export type StatementsPage = NovasamaStatementsPage;
74
+ export type StatementsPage = RemoteStatementStoreSubscribeItem;
75
75
 
76
76
  /**
77
- * Subscription handle returned by the host - equivalent to
78
- * `Subscription<void>` from `@novasamatech/host-api`. Exposes
79
- * `unsubscribe()` plus an `onInterrupt` hook that fires if the host
80
- * interrupts the subscription server-side.
77
+ * Subscription handle returned by the host. Exposes `unsubscribe()` plus an
78
+ * `onInterrupt` hook that fires if the host interrupts the subscription
79
+ * server-side; `onInterrupt` returns a function that cancels the hook.
81
80
  */
82
- export type HostSubscription = Subscription<void>;
81
+ export interface HostSubscription {
82
+ unsubscribe(): void;
83
+ onInterrupt(callback: (reason?: unknown) => void): () => void;
84
+ }
83
85
 
84
86
  /**
85
- * Statement Store handle exposed by the host container. Provides
86
- * `subscribe`, `createProof`, and `submit` operations that go through the
87
- * host's native binary protocol; the `statement-store` package layers a
88
- * higher-level client on top.
89
- *
90
- * Type identical to `createStatementStore()` from
91
- * `@novasamatech/host-api-wrapper`.
87
+ * Statement Store handle exposed by the host container, backed by
88
+ * `truApi.statementStore.*`. `subscribe` streams matching statements;
89
+ * `createProofAuthorized` signs a statement with the product's RFC-10 allowance
90
+ * account (the sponsored path — no per-call account id); `submit` publishes a
91
+ * signed statement. The `statement-store` package layers a higher-level client
92
+ * on top.
92
93
  */
93
- export type HostStatementStore = ReturnType<typeof createStatementStore>;
94
+ export interface HostStatementStore {
95
+ subscribe(
96
+ filter: StatementTopicFilter,
97
+ callback: (page: StatementsPage) => void,
98
+ ): HostSubscription;
99
+ createProofAuthorized(statement: Statement): Promise<StatementProof>;
100
+ submit(signedStatement: SignedStatement): Promise<void>;
101
+ }