@novasamatech/host-api 0.5.0-9 → 0.5.1

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.
Files changed (63) hide show
  1. package/README.md +103 -1
  2. package/dist/constants.d.ts +2 -0
  3. package/dist/constants.js +2 -0
  4. package/dist/helpers.d.ts +33 -0
  5. package/dist/helpers.js +46 -0
  6. package/dist/hostApi.d.ts +31 -0
  7. package/dist/hostApi.js +345 -0
  8. package/dist/index.d.ts +18 -7
  9. package/dist/index.js +14 -6
  10. package/dist/protocol/commonCodecs.d.ts +42 -0
  11. package/dist/protocol/commonCodecs.js +64 -0
  12. package/dist/protocol/commonCodecs.spec.d.ts +1 -0
  13. package/dist/protocol/commonCodecs.spec.js +72 -0
  14. package/dist/protocol/impl.d.ts +93 -0
  15. package/dist/protocol/impl.js +97 -0
  16. package/dist/protocol/messageCodec.d.ts +1245 -0
  17. package/dist/protocol/messageCodec.js +24 -0
  18. package/dist/protocol/types.d.ts +1 -0
  19. package/dist/protocol/types.js +1 -0
  20. package/dist/protocol/v1/accounts.d.ts +265 -0
  21. package/dist/protocol/v1/accounts.js +51 -0
  22. package/dist/protocol/v1/chat.d.ts +341 -0
  23. package/dist/protocol/v1/chat.js +71 -0
  24. package/dist/protocol/v1/createTransaction.d.ts +238 -0
  25. package/dist/protocol/v1/createTransaction.js +58 -0
  26. package/dist/protocol/v1/feature.d.ts +15 -0
  27. package/dist/protocol/v1/feature.js +7 -0
  28. package/dist/protocol/v1/handshake.d.ts +85 -0
  29. package/dist/protocol/v1/handshake.js +12 -0
  30. package/dist/protocol/v1/jsonRpc.d.ts +10 -0
  31. package/dist/protocol/v1/jsonRpc.js +6 -0
  32. package/dist/protocol/v1/permission.d.ts +90 -0
  33. package/dist/protocol/v1/permission.js +18 -0
  34. package/dist/protocol/v1/sign.d.ts +152 -0
  35. package/dist/protocol/v1/sign.js +43 -0
  36. package/dist/protocol/v1/statementStore.d.ts +175 -0
  37. package/dist/protocol/v1/statementStore.js +47 -0
  38. package/dist/protocol/v1/storage.d.ts +87 -0
  39. package/dist/protocol/v1/storage.js +16 -0
  40. package/dist/provider.d.ts +8 -0
  41. package/dist/provider.js +1 -0
  42. package/dist/transport.d.ts +3 -0
  43. package/dist/transport.js +248 -0
  44. package/dist/types.d.ts +15 -15
  45. package/package.json +2 -4
  46. package/dist/commonEncoders.d.ts +0 -9
  47. package/dist/commonEncoders.js +0 -14
  48. package/dist/createTransport.d.ts +0 -6
  49. package/dist/createTransport.js +0 -183
  50. package/dist/createTransportEncoder.d.ts +0 -7
  51. package/dist/createTransportEncoder.js +0 -5
  52. package/dist/interactions/accounts.d.ts +0 -12
  53. package/dist/interactions/accounts.js +0 -39
  54. package/dist/interactions/features.d.ts +0 -13
  55. package/dist/interactions/features.js +0 -13
  56. package/dist/interactions/handshake.d.ts +0 -2
  57. package/dist/interactions/handshake.js +0 -3
  58. package/dist/interactions/papiProvider.d.ts +0 -8
  59. package/dist/interactions/papiProvider.js +0 -9
  60. package/dist/interactions/sign.d.ts +0 -101
  61. package/dist/interactions/sign.js +0 -169
  62. package/dist/messageEncoder.d.ts +0 -217
  63. package/dist/messageEncoder.js +0 -37
package/README.md CHANGED
@@ -1,9 +1,111 @@
1
1
  # @novasamatech/host-api
2
2
 
3
- Protocol and transport implementation for host <=> product interaction inside Polkadot ecosystem.
3
+ A protocol designed to connect Products and Host applications by providing a set of methods for communication.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```shell
8
8
  npm install @novasamatech/host-api --save -E
9
9
  ```
10
+
11
+ ## Usage
12
+
13
+ The Host API package is composed of four main parts:
14
+ * **Protocol** — JAM codecs according to [proposal](https://hackmd.io/@zhuravlev-novasama-1337/B1kW0RWmbg);
15
+ * **Provider** — IPC interface, depends on environment;
16
+ * **Transport** — wrapper around protocol for making actual calls;
17
+ * **Host API** — wrapper around transport for direct usage of business methods.
18
+
19
+ ### Provider
20
+
21
+ Provider is an interface for IPC communication.
22
+ You can find the definition [here](./src/provider.ts).
23
+ The main goal is to abstract actual message send/receive logic from API.
24
+ Products should not implement their own providers, it should be done inside SDKs.
25
+
26
+ ### Transport
27
+
28
+ Transport is a low-level wrapper around protocol and provider.
29
+ It encapsulates serialization/deserialization and request/subscription logic.
30
+
31
+ ```typescript
32
+ import { createTransport, okResult } from '@novasamatech/host-api';
33
+ import { provider } from './custom-provider.js';
34
+
35
+ const transport = createTransport(provider);
36
+
37
+ // requesting by consumer
38
+
39
+ const response = await transport.request('storage_read', payload);
40
+
41
+ // handling request on provider side
42
+
43
+ const stop = transport.handleRequest('storage_read', async (payload) => {
44
+ try {
45
+ const result = await readFromStorage(payload);
46
+ return okResult(result);
47
+ } catch (e) {
48
+ return errResult(e);
49
+ }
50
+ });
51
+
52
+ // subscribing by consumer
53
+
54
+ const subscription = await transport.subscribe('chat_action_subscribe', params, (payload) => {
55
+ console.log('action received:', payload);
56
+ });
57
+
58
+ subscription.onInterrupt(() => {
59
+ console.log('subscription interrupted');
60
+ });
61
+
62
+ subscription.unsubscribe();
63
+
64
+ // handling subscription on provider side
65
+
66
+ transport.handleSubscription('chat_action_subscribe', (params, send, interrupt) => {
67
+ const unsubscribe = subscribeToChatActions(params, (err, action) => {
68
+ if (err) {
69
+ interrupt(err);
70
+ } else {
71
+ send(action);
72
+ }
73
+ });
74
+
75
+ return unsubscribe;
76
+ });
77
+ ```
78
+
79
+ ### Host API
80
+
81
+ Host API is a wrapper around transport that provides convenient methods for calling methods and subscribing to events.
82
+ It can be used by products directly or indirectly via SDK. All requests return a `ResultAsync` struct from the [neverthrow](https://github.com/Microsoft/neverthrow) library.
83
+
84
+ ```typescript
85
+ import { createHostApi, createTransport } from '@novasamatech/host-api';
86
+ import { provider } from './custom-provider.js';
87
+
88
+ const transport = createTransport(provider);
89
+ const hostApi = createHostApi(transport);
90
+
91
+ // requesting data
92
+
93
+ const storageValue = hostApi.storage_read(payload);
94
+
95
+ storageValue.match(
96
+ (data) => console.log('success:', data),
97
+ (err) => console.log('error:', err)
98
+ );
99
+
100
+ // subscribing to events
101
+
102
+ const subscription = hostApi.chat_action_subscribe(params, (action) => {
103
+ console.log('action received:', action);
104
+ });
105
+
106
+ subscription.onInterrupt(() => {
107
+ console.log('subscription interrupted');
108
+ });
109
+
110
+ subscription.unsubscribe();
111
+ ```
@@ -1 +1,3 @@
1
+ export declare const JAM_CODEC_PROTOCOL_ID = 1;
1
2
  export declare const HANDSHAKE_INTERVAL = 50;
3
+ export declare const HANDSHAKE_TIMEOUT = 10000;
package/dist/constants.js CHANGED
@@ -1 +1,3 @@
1
+ export const JAM_CODEC_PROTOCOL_ID = 1;
1
2
  export const HANDSHAKE_INTERVAL = 50;
3
+ export const HANDSHAKE_TIMEOUT = 10_000;
package/dist/helpers.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import type { ResultPayload } from 'scale-ts';
2
+ import type { ComposeMessageAction } from './protocol/messageCodec.js';
3
+ import type { HexString } from './protocol/types.js';
1
4
  export declare function delay(ttl: number): Promise<void>;
2
5
  type PromiseWithResolvers<T> = {
3
6
  promise: Promise<T>;
@@ -5,4 +8,34 @@ type PromiseWithResolvers<T> = {
5
8
  reject: (reason: unknown) => void;
6
9
  };
7
10
  export declare const promiseWithResolvers: <const T>() => PromiseWithResolvers<T>;
11
+ export declare function unwrapResultOrThrow<Ok, Err>(response: ResultPayload<Ok, Err>, toError: (e: Err) => Error): Ok;
12
+ export declare function okResult<const T>(value: T): {
13
+ success: true;
14
+ value: T;
15
+ };
16
+ export declare function errResult<const T>(e: T): {
17
+ success: false;
18
+ value: T;
19
+ };
20
+ export declare function enumValue<const Tag extends string, const Value>(tag: Tag, value: Value): {
21
+ tag: Tag;
22
+ value: Value;
23
+ };
24
+ export declare function isEnumVariant<const Enum extends {
25
+ tag: string;
26
+ value: unknown;
27
+ }, const Tag extends Enum['tag']>(v: Enum, tag: Tag): v is Extract<Enum, {
28
+ tag: Tag;
29
+ }>;
30
+ export declare function assertEnumVariant<const Enum extends {
31
+ tag: string;
32
+ value: unknown;
33
+ }, const Tag extends Enum['tag']>(v: Enum, tag: Tag, message: string): asserts v is Extract<Enum, {
34
+ tag: Tag;
35
+ }>;
36
+ export declare function composeAction<const Method extends string, const Suffix extends string>(method: Method, suffix: Suffix): ComposeMessageAction<Method, Suffix>;
37
+ export declare function createRequestId(): string;
38
+ export declare function extractErrorMessage(err: unknown): string;
39
+ export declare function toHex(value: Uint8Array): HexString;
40
+ export declare function fromHex(value: string): Uint8Array;
8
41
  export {};
package/dist/helpers.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { fromHex as papiFromHex, toHex as papiToHex } from '@polkadot-api/utils';
2
+ import { nanoid } from 'nanoid';
1
3
  export function delay(ttl) {
2
4
  return new Promise(resolve => setTimeout(resolve, ttl));
3
5
  }
@@ -11,3 +13,47 @@ export const promiseWithResolvers = () => {
11
13
  // @ts-expect-error before assign
12
14
  return { promise, resolve, reject };
13
15
  };
16
+ export function unwrapResultOrThrow(response, toError) {
17
+ if (response.success) {
18
+ return response.value;
19
+ }
20
+ throw toError(response.value);
21
+ }
22
+ export function okResult(value) {
23
+ return { success: true, value };
24
+ }
25
+ export function errResult(e) {
26
+ return { success: false, value: e };
27
+ }
28
+ export function enumValue(tag, value) {
29
+ return { tag, value };
30
+ }
31
+ export function isEnumVariant(v, tag) {
32
+ return v.tag === tag;
33
+ }
34
+ export function assertEnumVariant(v, tag, message) {
35
+ if (!isEnumVariant(v, tag)) {
36
+ throw new Error(message);
37
+ }
38
+ }
39
+ export function composeAction(method, suffix) {
40
+ return `${method}_${suffix}`;
41
+ }
42
+ export function createRequestId() {
43
+ return nanoid(8);
44
+ }
45
+ export function extractErrorMessage(err) {
46
+ if (err instanceof Error) {
47
+ return err.toString();
48
+ }
49
+ if (err) {
50
+ return err.toString();
51
+ }
52
+ return 'Unknown error occurred.';
53
+ }
54
+ export function toHex(value) {
55
+ return papiToHex(value);
56
+ }
57
+ export function fromHex(value) {
58
+ return papiFromHex(value);
59
+ }
@@ -0,0 +1,31 @@
1
+ import type { ResultAsync } from 'neverthrow';
2
+ import type { Codec, CodecType } from 'scale-ts';
3
+ import type { HostApiProtocol, VersionedProtocolRequest, VersionedProtocolSubscription } from './protocol/impl.js';
4
+ import type { Subscription, Transport } from './types.js';
5
+ type Value<T extends Codec<any> | Codec<never>> = T extends Codec<any> ? CodecType<T> : unknown;
6
+ type UnwrapVersionedResult<T> = T extends {
7
+ tag: infer Tag;
8
+ value: infer Value;
9
+ } ? ResultAsync<{
10
+ tag: Tag;
11
+ value: SuccessResponse<Value>;
12
+ }, {
13
+ tag: Tag;
14
+ value: ErrorResponse<Value>;
15
+ }> : never;
16
+ type SuccessResponse<T> = T extends {
17
+ success: true;
18
+ value: infer U;
19
+ } ? U : never;
20
+ type ErrorResponse<T> = T extends {
21
+ success: false;
22
+ value: infer U;
23
+ } ? U : never;
24
+ type InferRequestMethod<Method extends VersionedProtocolRequest> = (args: Value<Method['request']>) => UnwrapVersionedResult<Value<Method['response']>>;
25
+ type InferSubscribeMethod<Method extends VersionedProtocolSubscription> = (args: Value<Method['start']>, callback: (payload: Value<Method['receive']>) => void) => Subscription;
26
+ type InferMethod<Method extends VersionedProtocolRequest | VersionedProtocolSubscription> = Method extends VersionedProtocolRequest ? InferRequestMethod<Method> : Method extends VersionedProtocolSubscription ? InferSubscribeMethod<Method> : never;
27
+ type HostApi = {
28
+ [K in keyof HostApiProtocol]: InferMethod<HostApiProtocol[K]>;
29
+ };
30
+ export declare function createHostApi(transport: Transport): HostApi;
31
+ export {};
@@ -0,0 +1,345 @@
1
+ import { errAsync, fromPromise, okAsync } from 'neverthrow';
2
+ import { extractErrorMessage } from './helpers.js';
3
+ import { GenericError } from './protocol/commonCodecs.js';
4
+ import { CreateProofErr, RequestCredentialsErr } from './protocol/v1/accounts.js';
5
+ import { ChatContactRegistrationErr, ChatMessagePostingErr } from './protocol/v1/chat.js';
6
+ import { CreateTransactionErr } from './protocol/v1/createTransaction.js';
7
+ import { HandshakeErr } from './protocol/v1/handshake.js';
8
+ import { PermissionErr } from './protocol/v1/permission.js';
9
+ import { SigningErr } from './protocol/v1/sign.js';
10
+ import { StatementProofErr } from './protocol/v1/statementStore.js';
11
+ import { StorageErr } from './protocol/v1/storage.js';
12
+ export function createHostApi(transport) {
13
+ return {
14
+ handshake(payload) {
15
+ const response = fromPromise(transport.request('handshake', payload), e => ({
16
+ tag: payload.tag,
17
+ value: new HandshakeErr.Unknown({ reason: extractErrorMessage(e) }),
18
+ }));
19
+ return response.andThen(response => {
20
+ if (response.value.success) {
21
+ return okAsync({
22
+ tag: response.tag,
23
+ value: response.value.value,
24
+ });
25
+ }
26
+ return errAsync({
27
+ tag: response.tag,
28
+ value: response.value.value,
29
+ });
30
+ });
31
+ },
32
+ feature(payload) {
33
+ const response = fromPromise(transport.request('feature', payload), e => ({
34
+ tag: payload.tag,
35
+ value: new GenericError({ reason: extractErrorMessage(e) }),
36
+ }));
37
+ return response.andThen(response => {
38
+ if (response.value.success) {
39
+ return okAsync({
40
+ tag: response.tag,
41
+ value: response.value.value,
42
+ });
43
+ }
44
+ return errAsync({
45
+ tag: response.tag,
46
+ value: response.value.value,
47
+ });
48
+ });
49
+ },
50
+ permission_request(payload) {
51
+ const response = fromPromise(transport.request('permission_request', payload), e => ({
52
+ tag: payload.tag,
53
+ value: new PermissionErr.Unknown({ reason: extractErrorMessage(e) }),
54
+ }));
55
+ return response.andThen(response => {
56
+ if (response.value.success) {
57
+ return okAsync({
58
+ tag: response.tag,
59
+ value: response.value.value,
60
+ });
61
+ }
62
+ return errAsync({
63
+ tag: response.tag,
64
+ value: response.value.value,
65
+ });
66
+ });
67
+ },
68
+ storage_read(payload) {
69
+ const response = fromPromise(transport.request('storage_read', payload), e => ({
70
+ tag: payload.tag,
71
+ value: new StorageErr.Unknown({ reason: extractErrorMessage(e) }),
72
+ }));
73
+ return response.andThen(response => {
74
+ if (response.value.success) {
75
+ return okAsync({
76
+ tag: response.tag,
77
+ value: response.value.value,
78
+ });
79
+ }
80
+ return errAsync({
81
+ tag: response.tag,
82
+ value: response.value.value,
83
+ });
84
+ });
85
+ },
86
+ storage_write(payload) {
87
+ const response = fromPromise(transport.request('storage_write', payload), e => ({
88
+ tag: payload.tag,
89
+ value: new StorageErr.Unknown({ reason: extractErrorMessage(e) }),
90
+ }));
91
+ return response.andThen(response => {
92
+ if (response.value.success) {
93
+ return okAsync({
94
+ tag: response.tag,
95
+ value: response.value.value,
96
+ });
97
+ }
98
+ return errAsync({
99
+ tag: response.tag,
100
+ value: response.value.value,
101
+ });
102
+ });
103
+ },
104
+ storage_clear(payload) {
105
+ const response = fromPromise(transport.request('storage_clear', payload), e => ({
106
+ tag: payload.tag,
107
+ value: new StorageErr.Unknown({ reason: extractErrorMessage(e) }),
108
+ }));
109
+ return response.andThen(response => {
110
+ if (response.value.success) {
111
+ return okAsync({
112
+ tag: response.tag,
113
+ value: response.value.value,
114
+ });
115
+ }
116
+ return errAsync({
117
+ tag: response.tag,
118
+ value: response.value.value,
119
+ });
120
+ });
121
+ },
122
+ account_get(payload) {
123
+ const response = fromPromise(transport.request('account_get', payload), e => ({
124
+ tag: payload.tag,
125
+ value: new RequestCredentialsErr.Unknown({ reason: extractErrorMessage(e) }),
126
+ }));
127
+ return response.andThen(response => {
128
+ if (response.value.success) {
129
+ return okAsync({
130
+ tag: response.tag,
131
+ value: response.value.value,
132
+ });
133
+ }
134
+ return errAsync({
135
+ tag: response.tag,
136
+ value: response.value.value,
137
+ });
138
+ });
139
+ },
140
+ account_get_alias(payload) {
141
+ const response = fromPromise(transport.request('account_get_alias', payload), e => ({
142
+ tag: payload.tag,
143
+ value: new RequestCredentialsErr.Unknown({ reason: extractErrorMessage(e) }),
144
+ }));
145
+ return response.andThen(response => {
146
+ if (response.value.success) {
147
+ return okAsync({
148
+ tag: response.tag,
149
+ value: response.value.value,
150
+ });
151
+ }
152
+ return errAsync({
153
+ tag: response.tag,
154
+ value: response.value.value,
155
+ });
156
+ });
157
+ },
158
+ account_create_proof(payload) {
159
+ const response = fromPromise(transport.request('account_create_proof', payload), e => ({
160
+ tag: payload.tag,
161
+ value: new CreateProofErr.Unknown({ reason: extractErrorMessage(e) }),
162
+ }));
163
+ return response.andThen(response => {
164
+ if (response.value.success) {
165
+ return okAsync({
166
+ tag: response.tag,
167
+ value: response.value.value,
168
+ });
169
+ }
170
+ return errAsync({
171
+ tag: response.tag,
172
+ value: response.value.value,
173
+ });
174
+ });
175
+ },
176
+ get_non_product_accounts(payload) {
177
+ const response = fromPromise(transport.request('get_non_product_accounts', payload), e => ({
178
+ tag: payload.tag,
179
+ value: new RequestCredentialsErr.Unknown({ reason: extractErrorMessage(e) }),
180
+ }));
181
+ return response.andThen(response => {
182
+ if (response.value.success) {
183
+ return okAsync({
184
+ tag: response.tag,
185
+ value: response.value.value,
186
+ });
187
+ }
188
+ return errAsync({
189
+ tag: response.tag,
190
+ value: response.value.value,
191
+ });
192
+ });
193
+ },
194
+ create_transaction(payload) {
195
+ const response = fromPromise(transport.request('create_transaction', payload), e => ({
196
+ tag: payload.tag,
197
+ value: new CreateTransactionErr.Unknown({ reason: extractErrorMessage(e) }),
198
+ }));
199
+ return response.andThen(response => {
200
+ if (response.value.success) {
201
+ return okAsync({
202
+ tag: response.tag,
203
+ value: response.value.value,
204
+ });
205
+ }
206
+ return errAsync({
207
+ tag: response.tag,
208
+ value: response.value.value,
209
+ });
210
+ });
211
+ },
212
+ create_transaction_with_non_product_account(payload) {
213
+ const response = fromPromise(transport.request('create_transaction_with_non_product_account', payload), e => ({
214
+ tag: payload.tag,
215
+ value: new CreateTransactionErr.Unknown({ reason: extractErrorMessage(e) }),
216
+ }));
217
+ return response.andThen(response => {
218
+ if (response.value.success) {
219
+ return okAsync({
220
+ tag: response.tag,
221
+ value: response.value.value,
222
+ });
223
+ }
224
+ return errAsync({
225
+ tag: response.tag,
226
+ value: response.value.value,
227
+ });
228
+ });
229
+ },
230
+ sign_raw(payload) {
231
+ const response = fromPromise(transport.request('sign_raw', payload), e => ({
232
+ tag: payload.tag,
233
+ value: new SigningErr.Unknown({ reason: extractErrorMessage(e) }),
234
+ }));
235
+ return response.andThen(response => {
236
+ if (response.value.success) {
237
+ return okAsync({
238
+ tag: response.tag,
239
+ value: response.value.value,
240
+ });
241
+ }
242
+ return errAsync({
243
+ tag: response.tag,
244
+ value: response.value.value,
245
+ });
246
+ });
247
+ },
248
+ sign_payload(payload) {
249
+ const response = fromPromise(transport.request('sign_payload', payload), e => ({
250
+ tag: payload.tag,
251
+ value: new SigningErr.Unknown({ reason: extractErrorMessage(e) }),
252
+ }));
253
+ return response.andThen(response => {
254
+ if (response.value.success) {
255
+ return okAsync({
256
+ tag: response.tag,
257
+ value: response.value.value,
258
+ });
259
+ }
260
+ return errAsync({
261
+ tag: response.tag,
262
+ value: response.value.value,
263
+ });
264
+ });
265
+ },
266
+ chat_create_contact(payload) {
267
+ const response = fromPromise(transport.request('chat_create_contact', payload), e => ({
268
+ tag: payload.tag,
269
+ value: new ChatContactRegistrationErr.Unknown({ reason: extractErrorMessage(e) }),
270
+ }));
271
+ return response.andThen(response => {
272
+ if (response.value.success) {
273
+ return okAsync({
274
+ tag: response.tag,
275
+ value: response.value.value,
276
+ });
277
+ }
278
+ return errAsync({
279
+ tag: response.tag,
280
+ value: response.value.value,
281
+ });
282
+ });
283
+ },
284
+ chat_post_message(payload) {
285
+ const response = fromPromise(transport.request('chat_post_message', payload), e => ({
286
+ tag: payload.tag,
287
+ value: new ChatMessagePostingErr.Unknown({ reason: extractErrorMessage(e) }),
288
+ }));
289
+ return response.andThen(response => {
290
+ if (response.value.success) {
291
+ return okAsync({
292
+ tag: response.tag,
293
+ value: response.value.value,
294
+ });
295
+ }
296
+ return errAsync({
297
+ tag: response.tag,
298
+ value: response.value.value,
299
+ });
300
+ });
301
+ },
302
+ chat_action_subscribe(args, callback) {
303
+ return transport.subscribe('chat_action_subscribe', args, callback);
304
+ },
305
+ statement_store_create_proof(payload) {
306
+ const response = fromPromise(transport.request('statement_store_create_proof', payload), e => ({
307
+ tag: payload.tag,
308
+ value: new StatementProofErr.Unknown({ reason: extractErrorMessage(e) }),
309
+ }));
310
+ return response.andThen(response => {
311
+ if (response.value.success) {
312
+ return okAsync({
313
+ tag: response.tag,
314
+ value: response.value.value,
315
+ });
316
+ }
317
+ return errAsync({
318
+ tag: response.tag,
319
+ value: response.value.value,
320
+ });
321
+ });
322
+ },
323
+ jsonrpc_message_send(payload) {
324
+ const response = fromPromise(transport.request('jsonrpc_message_send', payload), e => ({
325
+ tag: payload.tag,
326
+ value: new GenericError({ reason: extractErrorMessage(e) }),
327
+ }));
328
+ return response.andThen(response => {
329
+ if (response.value.success) {
330
+ return okAsync({
331
+ tag: response.tag,
332
+ value: response.value.value,
333
+ });
334
+ }
335
+ return errAsync({
336
+ tag: response.tag,
337
+ value: response.value.value,
338
+ });
339
+ });
340
+ },
341
+ jsonrpc_message_subscribe(args, callback) {
342
+ return transport.subscribe('jsonrpc_message_subscribe', args, callback);
343
+ },
344
+ };
345
+ }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,19 @@
1
- export { messageEncoder, unwrapResponseOrThrow } from './messageEncoder.js';
2
- export { type MessagePayloadSchema, type MessageType, type PickMessagePayload, type PickMessagePayloadValue, } from './messageEncoder.js';
3
- export { createTransport } from './createTransport.js';
4
- export type { ConnectionStatus, HexString, Logger, Transport, TransportProvider } from './types.js';
1
+ export type { ConnectionStatus, Logger, Transport } from './types.js';
2
+ export type { Provider } from './provider.js';
3
+ export { assertEnumVariant, createRequestId, enumValue, errResult, fromHex, isEnumVariant, okResult, toHex, unwrapResultOrThrow, } from './helpers.js';
4
+ export type { HexString } from './protocol/types.js';
5
+ export { createHostApi } from './hostApi.js';
6
+ export { createTransport } from './transport.js';
5
7
  export { createDefaultLogger } from './logger.js';
6
- export { type InjectedAccountSchema } from './interactions/accounts.js';
7
- export { type TxPayloadV1 } from './interactions/sign.js';
8
- export { signPayloadCodec } from './interactions/sign.js';
8
+ export type { HostApiProtocol, VersionedProtocolRequest, VersionedProtocolSubscription } from './protocol/impl.js';
9
+ export { hostApiProtocol } from './protocol/impl.js';
10
+ export type { Codec, CodecType } from 'scale-ts';
11
+ export { GenericError } from './protocol/commonCodecs.js';
12
+ export { CreateTransactionErr, VersionedPublicTxPayload } from './protocol/v1/createTransaction.js';
13
+ export { Account, AccountId, CreateProofErr, ProductAccountId, RequestCredentialsErr } from './protocol/v1/accounts.js';
14
+ export { ChatContactRegistrationErr, ChatContactRegistrationStatus, ChatMessage, ChatMessagePostingErr, ReceivedChatAction, } from './protocol/v1/chat.js';
15
+ export { HandshakeErr } from './protocol/v1/handshake.js';
16
+ export { PermissionErr } from './protocol/v1/permission.js';
17
+ export { SigningErr } from './protocol/v1/sign.js';
18
+ export { StatementProofErr } from './protocol/v1/statementStore.js';
19
+ export { StorageErr } from './protocol/v1/storage.js';
package/dist/index.js CHANGED
@@ -1,7 +1,15 @@
1
- export { messageEncoder, unwrapResponseOrThrow } from './messageEncoder.js';
2
- export {} from './messageEncoder.js';
3
- export { createTransport } from './createTransport.js';
1
+ export { assertEnumVariant, createRequestId, enumValue, errResult, fromHex, isEnumVariant, okResult, toHex, unwrapResultOrThrow, } from './helpers.js';
2
+ export { createHostApi } from './hostApi.js';
3
+ export { createTransport } from './transport.js';
4
4
  export { createDefaultLogger } from './logger.js';
5
- export {} from './interactions/accounts.js';
6
- export {} from './interactions/sign.js';
7
- export { signPayloadCodec } from './interactions/sign.js';
5
+ export { hostApiProtocol } from './protocol/impl.js';
6
+ // Codecs
7
+ export { GenericError } from './protocol/commonCodecs.js';
8
+ export { CreateTransactionErr, VersionedPublicTxPayload } from './protocol/v1/createTransaction.js';
9
+ export { Account, AccountId, CreateProofErr, ProductAccountId, RequestCredentialsErr } from './protocol/v1/accounts.js';
10
+ export { ChatContactRegistrationErr, ChatContactRegistrationStatus, ChatMessage, ChatMessagePostingErr, ReceivedChatAction, } from './protocol/v1/chat.js';
11
+ export { HandshakeErr } from './protocol/v1/handshake.js';
12
+ export { PermissionErr } from './protocol/v1/permission.js';
13
+ export { SigningErr } from './protocol/v1/sign.js';
14
+ export { StatementProofErr } from './protocol/v1/statementStore.js';
15
+ export { StorageErr } from './protocol/v1/storage.js';