@novasamatech/host-api 0.5.2 → 0.5.4-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 CHANGED
@@ -29,7 +29,7 @@ Transport is a low-level wrapper around protocol and provider.
29
29
  It encapsulates serialization/deserialization and request/subscription logic.
30
30
 
31
31
  ```typescript
32
- import { createTransport, okResult } from '@novasamatech/host-api';
32
+ import { createTransport, resultOk } from '@novasamatech/host-api';
33
33
  import { provider } from './custom-provider.js';
34
34
 
35
35
  const transport = createTransport(provider);
@@ -43,9 +43,9 @@ const response = await transport.request('storage_read', payload);
43
43
  const stop = transport.handleRequest('storage_read', async (payload) => {
44
44
  try {
45
45
  const result = await readFromStorage(payload);
46
- return okResult(result);
46
+ return resultOk(result);
47
47
  } catch (e) {
48
- return errResult(e);
48
+ return resultErr(e);
49
49
  }
50
50
  });
51
51
 
package/dist/helpers.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import type { ResultPayload } from 'scale-ts';
2
1
  import type { ComposeMessageAction } from './protocol/messageCodec.js';
3
- import type { HexString } from './protocol/types.js';
4
2
  export declare function delay(ttl: number): Promise<void>;
5
3
  type PromiseWithResolvers<T> = {
6
4
  promise: Promise<T>;
@@ -8,34 +6,7 @@ type PromiseWithResolvers<T> = {
8
6
  reject: (reason: unknown) => void;
9
7
  };
10
8
  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
9
  export declare function composeAction<const Method extends string, const Suffix extends string>(method: Method, suffix: Suffix): ComposeMessageAction<Method, Suffix>;
37
10
  export declare function createRequestId(): string;
38
11
  export declare function extractErrorMessage(err: unknown): string;
39
- export declare function toHex(value: Uint8Array): HexString;
40
- export declare function fromHex(value: string): Uint8Array;
41
12
  export {};
package/dist/helpers.js CHANGED
@@ -1,4 +1,3 @@
1
- import { fromHex as papiFromHex, toHex as papiToHex } from '@polkadot-api/utils';
2
1
  import { nanoid } from 'nanoid';
3
2
  export function delay(ttl) {
4
3
  return new Promise(resolve => setTimeout(resolve, ttl));
@@ -13,29 +12,6 @@ export const promiseWithResolvers = () => {
13
12
  // @ts-expect-error before assign
14
13
  return { promise, resolve, reject };
15
14
  };
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
15
  export function composeAction(method, suffix) {
40
16
  return `${method}_${suffix}`;
41
17
  }
@@ -51,9 +27,3 @@ export function extractErrorMessage(err) {
51
27
  }
52
28
  return 'Unknown error occurred.';
53
29
  }
54
- export function toHex(value) {
55
- return papiToHex(value);
56
- }
57
- export function fromHex(value) {
58
- return papiFromHex(value);
59
- }
package/dist/hostApi.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { ResultAsync } from 'neverthrow';
2
2
  import type { Codec, CodecType } from 'scale-ts';
3
3
  import type { HostApiProtocol, VersionedProtocolRequest, VersionedProtocolSubscription } from './protocol/impl.js';
4
4
  import type { Subscription, Transport } from './types.js';
5
+ type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<SnakeToCamelCase<U>>}` : S;
5
6
  type Value<T extends Codec<any> | Codec<never>> = T extends Codec<any> ? CodecType<T> : unknown;
6
7
  type UnwrapVersionedResult<T> = T extends {
7
8
  tag: infer Tag;
@@ -24,8 +25,8 @@ type ErrorResponse<T> = T extends {
24
25
  type InferRequestMethod<Method extends VersionedProtocolRequest> = (args: Value<Method['request']>) => UnwrapVersionedResult<Value<Method['response']>>;
25
26
  type InferSubscribeMethod<Method extends VersionedProtocolSubscription> = (args: Value<Method['start']>, callback: (payload: Value<Method['receive']>) => void) => Subscription;
26
27
  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]>;
28
+ export type HostApi = {
29
+ [K in keyof HostApiProtocol as SnakeToCamelCase<K>]: InferMethod<HostApiProtocol[K]>;
29
30
  };
30
31
  export declare function createHostApi(transport: Transport): HostApi;
31
32
  export {};
package/dist/hostApi.js CHANGED
@@ -2,10 +2,9 @@ import { errAsync, fromPromise, okAsync } from 'neverthrow';
2
2
  import { extractErrorMessage } from './helpers.js';
3
3
  import { GenericError } from './protocol/commonCodecs.js';
4
4
  import { CreateProofErr, RequestCredentialsErr } from './protocol/v1/accounts.js';
5
- import { ChatContactRegistrationErr, ChatMessagePostingErr } from './protocol/v1/chat.js';
5
+ import { ChatMessagePostingErr, ChatRoomRegistrationErr } from './protocol/v1/chat.js';
6
6
  import { CreateTransactionErr } from './protocol/v1/createTransaction.js';
7
7
  import { HandshakeErr } from './protocol/v1/handshake.js';
8
- import { PermissionErr } from './protocol/v1/permission.js';
9
8
  import { SigningErr } from './protocol/v1/sign.js';
10
9
  import { StatementProofErr } from './protocol/v1/statementStore.js';
11
10
  import { StorageErr } from './protocol/v1/storage.js';
@@ -47,26 +46,8 @@ export function createHostApi(transport) {
47
46
  });
48
47
  });
49
48
  },
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 => ({
49
+ localStorageRead(payload) {
50
+ const response = fromPromise(transport.request('local_storage_read', payload), e => ({
70
51
  tag: payload.tag,
71
52
  value: new StorageErr.Unknown({ reason: extractErrorMessage(e) }),
72
53
  }));
@@ -83,8 +64,8 @@ export function createHostApi(transport) {
83
64
  });
84
65
  });
85
66
  },
86
- storage_write(payload) {
87
- const response = fromPromise(transport.request('storage_write', payload), e => ({
67
+ localStorageWrite(payload) {
68
+ const response = fromPromise(transport.request('local_storage_write', payload), e => ({
88
69
  tag: payload.tag,
89
70
  value: new StorageErr.Unknown({ reason: extractErrorMessage(e) }),
90
71
  }));
@@ -101,8 +82,8 @@ export function createHostApi(transport) {
101
82
  });
102
83
  });
103
84
  },
104
- storage_clear(payload) {
105
- const response = fromPromise(transport.request('storage_clear', payload), e => ({
85
+ localStorageClear(payload) {
86
+ const response = fromPromise(transport.request('local_storage_clear', payload), e => ({
106
87
  tag: payload.tag,
107
88
  value: new StorageErr.Unknown({ reason: extractErrorMessage(e) }),
108
89
  }));
@@ -119,7 +100,7 @@ export function createHostApi(transport) {
119
100
  });
120
101
  });
121
102
  },
122
- account_get(payload) {
103
+ accountGet(payload) {
123
104
  const response = fromPromise(transport.request('account_get', payload), e => ({
124
105
  tag: payload.tag,
125
106
  value: new RequestCredentialsErr.Unknown({ reason: extractErrorMessage(e) }),
@@ -137,7 +118,7 @@ export function createHostApi(transport) {
137
118
  });
138
119
  });
139
120
  },
140
- account_get_alias(payload) {
121
+ accountGetAlias(payload) {
141
122
  const response = fromPromise(transport.request('account_get_alias', payload), e => ({
142
123
  tag: payload.tag,
143
124
  value: new RequestCredentialsErr.Unknown({ reason: extractErrorMessage(e) }),
@@ -155,7 +136,7 @@ export function createHostApi(transport) {
155
136
  });
156
137
  });
157
138
  },
158
- account_create_proof(payload) {
139
+ accountCreateProof(payload) {
159
140
  const response = fromPromise(transport.request('account_create_proof', payload), e => ({
160
141
  tag: payload.tag,
161
142
  value: new CreateProofErr.Unknown({ reason: extractErrorMessage(e) }),
@@ -173,7 +154,7 @@ export function createHostApi(transport) {
173
154
  });
174
155
  });
175
156
  },
176
- get_non_product_accounts(payload) {
157
+ getNonProductAccounts(payload) {
177
158
  const response = fromPromise(transport.request('get_non_product_accounts', payload), e => ({
178
159
  tag: payload.tag,
179
160
  value: new RequestCredentialsErr.Unknown({ reason: extractErrorMessage(e) }),
@@ -191,7 +172,7 @@ export function createHostApi(transport) {
191
172
  });
192
173
  });
193
174
  },
194
- create_transaction(payload) {
175
+ createTransaction(payload) {
195
176
  const response = fromPromise(transport.request('create_transaction', payload), e => ({
196
177
  tag: payload.tag,
197
178
  value: new CreateTransactionErr.Unknown({ reason: extractErrorMessage(e) }),
@@ -209,7 +190,7 @@ export function createHostApi(transport) {
209
190
  });
210
191
  });
211
192
  },
212
- create_transaction_with_non_product_account(payload) {
193
+ createTransactionWithNonProductAccount(payload) {
213
194
  const response = fromPromise(transport.request('create_transaction_with_non_product_account', payload), e => ({
214
195
  tag: payload.tag,
215
196
  value: new CreateTransactionErr.Unknown({ reason: extractErrorMessage(e) }),
@@ -227,7 +208,7 @@ export function createHostApi(transport) {
227
208
  });
228
209
  });
229
210
  },
230
- sign_raw(payload) {
211
+ signRaw(payload) {
231
212
  const response = fromPromise(transport.request('sign_raw', payload), e => ({
232
213
  tag: payload.tag,
233
214
  value: new SigningErr.Unknown({ reason: extractErrorMessage(e) }),
@@ -245,7 +226,7 @@ export function createHostApi(transport) {
245
226
  });
246
227
  });
247
228
  },
248
- sign_payload(payload) {
229
+ signPayload(payload) {
249
230
  const response = fromPromise(transport.request('sign_payload', payload), e => ({
250
231
  tag: payload.tag,
251
232
  value: new SigningErr.Unknown({ reason: extractErrorMessage(e) }),
@@ -263,10 +244,13 @@ export function createHostApi(transport) {
263
244
  });
264
245
  });
265
246
  },
266
- chat_create_contact(payload) {
267
- const response = fromPromise(transport.request('chat_create_contact', payload), e => ({
247
+ chatListSubscribe(args, callback) {
248
+ return transport.subscribe('chat_list_subscribe', args, callback);
249
+ },
250
+ chatCreateRoom(payload) {
251
+ const response = fromPromise(transport.request('chat_create_room', payload), e => ({
268
252
  tag: payload.tag,
269
- value: new ChatContactRegistrationErr.Unknown({ reason: extractErrorMessage(e) }),
253
+ value: new ChatRoomRegistrationErr.Unknown({ reason: extractErrorMessage(e) }),
270
254
  }));
271
255
  return response.andThen(response => {
272
256
  if (response.value.success) {
@@ -281,7 +265,7 @@ export function createHostApi(transport) {
281
265
  });
282
266
  });
283
267
  },
284
- chat_post_message(payload) {
268
+ chatPostMessage(payload) {
285
269
  const response = fromPromise(transport.request('chat_post_message', payload), e => ({
286
270
  tag: payload.tag,
287
271
  value: new ChatMessagePostingErr.Unknown({ reason: extractErrorMessage(e) }),
@@ -299,10 +283,31 @@ export function createHostApi(transport) {
299
283
  });
300
284
  });
301
285
  },
302
- chat_action_subscribe(args, callback) {
286
+ chatActionSubscribe(args, callback) {
303
287
  return transport.subscribe('chat_action_subscribe', args, callback);
304
288
  },
305
- statement_store_create_proof(payload) {
289
+ statementStoreQuery(payload) {
290
+ const response = fromPromise(transport.request('statement_store_query', payload), e => ({
291
+ tag: payload.tag,
292
+ value: new GenericError({ reason: extractErrorMessage(e) }),
293
+ }));
294
+ return response.andThen(response => {
295
+ if (response.value.success) {
296
+ return okAsync({
297
+ tag: response.tag,
298
+ value: response.value.value,
299
+ });
300
+ }
301
+ return errAsync({
302
+ tag: response.tag,
303
+ value: response.value.value,
304
+ });
305
+ });
306
+ },
307
+ statementStoreSubscribe(args, callback) {
308
+ return transport.subscribe('statement_store_subscribe', args, callback);
309
+ },
310
+ statementStoreCreateProof(payload) {
306
311
  const response = fromPromise(transport.request('statement_store_create_proof', payload), e => ({
307
312
  tag: payload.tag,
308
313
  value: new StatementProofErr.Unknown({ reason: extractErrorMessage(e) }),
@@ -320,7 +325,25 @@ export function createHostApi(transport) {
320
325
  });
321
326
  });
322
327
  },
323
- jsonrpc_message_send(payload) {
328
+ statementStoreSubmit(payload) {
329
+ const response = fromPromise(transport.request('statement_store_submit', payload), e => ({
330
+ tag: payload.tag,
331
+ value: new GenericError({ reason: extractErrorMessage(e) }),
332
+ }));
333
+ return response.andThen(response => {
334
+ if (response.value.success) {
335
+ return okAsync({
336
+ tag: response.tag,
337
+ value: response.value.value,
338
+ });
339
+ }
340
+ return errAsync({
341
+ tag: response.tag,
342
+ value: response.value.value,
343
+ });
344
+ });
345
+ },
346
+ jsonrpcMessageSend(payload) {
324
347
  const response = fromPromise(transport.request('jsonrpc_message_send', payload), e => ({
325
348
  tag: payload.tag,
326
349
  value: new GenericError({ reason: extractErrorMessage(e) }),
@@ -338,7 +361,7 @@ export function createHostApi(transport) {
338
361
  });
339
362
  });
340
363
  },
341
- jsonrpc_message_subscribe(args, callback) {
364
+ jsonrpcMessageSubscribe(args, callback) {
342
365
  return transport.subscribe('jsonrpc_message_subscribe', args, callback);
343
366
  },
344
367
  };
package/dist/index.d.ts CHANGED
@@ -1,19 +1,20 @@
1
- export type { ConnectionStatus, Logger, Transport } from './types.js';
1
+ export type { ConnectionStatus, Logger, Subscription, Transport } from './types.js';
2
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';
3
+ export { createRequestId } from './helpers.js';
4
+ export type { HostApi } from './hostApi.js';
5
5
  export { createHostApi } from './hostApi.js';
6
6
  export { createTransport } from './transport.js';
7
7
  export { createDefaultLogger } from './logger.js';
8
8
  export type { HostApiProtocol, VersionedProtocolRequest, VersionedProtocolSubscription } from './protocol/impl.js';
9
9
  export { hostApiProtocol } from './protocol/impl.js';
10
10
  export type { Codec, CodecType } from 'scale-ts';
11
+ export type { HexString } from '@novasamatech/scale';
12
+ export { assertEnumVariant, enumValue, fromHex, isEnumVariant, resultErr, resultOk, toHex, unwrapResultOrThrow, } from '@novasamatech/scale';
11
13
  export { GenericError } from './protocol/commonCodecs.js';
12
14
  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 { Account, AccountId, CreateProofErr, ProductAccountId, RequestCredentialsErr, RingLocation, } from './protocol/v1/accounts.js';
16
+ export { ChatActionPayload, ChatMessageContent, ChatMessagePostingErr, ChatRoom, ChatRoomRegistrationErr, ChatRoomRegistrationResult, ReceivedChatAction, } from './protocol/v1/chat.js';
15
17
  export { HandshakeErr } from './protocol/v1/handshake.js';
16
- export { PermissionErr } from './protocol/v1/permission.js';
17
18
  export { SigningErr } from './protocol/v1/sign.js';
18
- export { StatementProofErr } from './protocol/v1/statementStore.js';
19
+ export { SignedStatement, Statement, StatementProofErr, Topic } from './protocol/v1/statementStore.js';
19
20
  export { StorageErr } from './protocol/v1/storage.js';
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
- export { assertEnumVariant, createRequestId, enumValue, errResult, fromHex, isEnumVariant, okResult, toHex, unwrapResultOrThrow, } from './helpers.js';
1
+ export { createRequestId } from './helpers.js';
2
2
  export { createHostApi } from './hostApi.js';
3
3
  export { createTransport } from './transport.js';
4
4
  export { createDefaultLogger } from './logger.js';
5
5
  export { hostApiProtocol } from './protocol/impl.js';
6
+ export { assertEnumVariant, enumValue, fromHex, isEnumVariant, resultErr, resultOk, toHex, unwrapResultOrThrow, } from '@novasamatech/scale';
6
7
  // Codecs
7
8
  export { GenericError } from './protocol/commonCodecs.js';
8
9
  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';
10
+ export { Account, AccountId, CreateProofErr, ProductAccountId, RequestCredentialsErr, RingLocation, } from './protocol/v1/accounts.js';
11
+ export { ChatActionPayload, ChatMessageContent, ChatMessagePostingErr, ChatRoom, ChatRoomRegistrationErr, ChatRoomRegistrationResult, ReceivedChatAction, } from './protocol/v1/chat.js';
11
12
  export { HandshakeErr } from './protocol/v1/handshake.js';
12
- export { PermissionErr } from './protocol/v1/permission.js';
13
13
  export { SigningErr } from './protocol/v1/sign.js';
14
- export { StatementProofErr } from './protocol/v1/statementStore.js';
14
+ export { SignedStatement, Statement, StatementProofErr, Topic } from './protocol/v1/statementStore.js';
15
15
  export { StorageErr } from './protocol/v1/storage.js';
@@ -1,42 +1,7 @@
1
- import type { Codec, CodecType, StringRecord } from 'scale-ts';
2
- type FilterStringRecord<T extends Record<string, Codec<any>>> = T extends StringRecord<Codec<any>> ? T : never;
3
- export type EnumCodec<T extends Record<string, Codec<any>>> = ReturnType<typeof Enum<T>>;
4
- export declare const Enum: <T extends Record<string, Codec<any>>>(inner: T) => Codec<(FilterStringRecord<T> extends infer T_1 extends StringRecord<Codec<any>> ? { [K in keyof T_1]: {
5
- tag: K;
6
- value: CodecType<T_1[K]>;
7
- }; } : never)[keyof FilterStringRecord<T>]>;
8
- /**
9
- * Enum without values
10
- */
11
- export declare function Status<T extends string>(...list: T[]): Codec<T>;
12
- export declare function Nullable<T>(inner: Codec<T>): Codec<T | null>;
13
- type Constructor<A extends Array<any>, T> = new (...args: A) => T;
14
- type CodecError<T, Name extends string> = Error & {
15
- name: Name;
16
- className: string;
17
- payload: T;
18
- };
19
- type CodecErrorConstructor<T, Name extends string> = Constructor<T extends undefined ? [void] : [T], CodecError<T, Name>>;
20
- export type ErrCodec<T, Name extends string> = Codec<CodecError<T, Name>> & CodecErrorConstructor<T, Name>;
21
- export declare function Err<const T, const Name extends string>(name: Name, value: Codec<T>, message: string | ((value: NoInfer<T>) => string), className?: string): ErrCodec<T, Name>;
22
- type MapErrEnum<Name extends string, T extends Record<string, ErrEnumArguments<any>>> = {
23
- [K in keyof T]: ErrCodec<CodecType<T[K][0]>, K extends string ? `${Name}::${K}` : Name>;
24
- };
25
- type ErrEnumInput<Name extends string, T extends Record<string, ErrEnumArguments<any>>> = {
26
- [K in keyof T]: CodecError<CodecType<T[K][0]>, K extends string ? `${Name}::${K}` : Name>;
27
- }[keyof T];
28
- type ErrEnumArguments<T> = [value: Codec<T>, message: string | ((value: T) => string)];
29
- export declare function ErrEnum<const Name extends string, const T extends Record<string, ErrEnumArguments<any>>>(name: Name, inner: T): Codec<ErrEnumInput<Name, T>> & MapErrEnum<Name, T>;
30
- /**
31
- * Wrapper around Bytes codec. Every usage of Hex codec should be threaded as raw Bytes with mapping to hex string.
32
- * @param [length] Optional, corresponds to byte array size, not the length of hex string.
33
- */
34
- export declare const Hex: (length?: number) => Codec<`0x${string}`>;
35
- export declare const GenesisHash: Codec<`0x${string}`>;
36
- export declare const GenericErr: Codec<{
1
+ export declare const GenesisHash: import("scale-ts").Codec<`0x${string}`>;
2
+ export declare const GenericErr: import("scale-ts").Codec<{
37
3
  reason: string;
38
4
  }>;
39
- export declare const GenericError: ErrCodec<{
5
+ export declare const GenericError: import("@novasamatech/scale").ErrCodec<{
40
6
  reason: string;
41
7
  }, "GenericError">;
42
- export {};
@@ -1,62 +1,5 @@
1
- import { Bytes, Enum as ScaleEnum, Option, Struct, _void, enhanceCodec, str, u8 } from 'scale-ts';
2
- import { fromHex, toHex } from '../helpers.js';
3
- export const Enum = (inner) => ScaleEnum(inner);
4
- /**
5
- * Enum without values
6
- */
7
- export function Status(...list) {
8
- return enhanceCodec(u8, v => {
9
- const i = list.indexOf(v);
10
- if (i === -1) {
11
- throw new Error(`Unknown status value: ${v}`);
12
- }
13
- return i;
14
- }, i => {
15
- const v = list.at(i);
16
- if (v === undefined) {
17
- throw new Error(`Unknown status index: ${i}`);
18
- }
19
- return v;
20
- });
21
- }
22
- export function Nullable(inner) {
23
- return enhanceCodec(Option(inner), v => (v === null ? undefined : v), v => (v === undefined ? null : v));
24
- }
25
- export function Err(name, value, message, className = name) {
26
- // Defining class with dynamic name
27
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
28
- const C = {
29
- [className]: class extends Error {
30
- className = className;
31
- name = name;
32
- payload;
33
- constructor(data) {
34
- super(typeof message === 'function' ? message(data) : message);
35
- this.payload = data;
36
- }
37
- // workaround for codec array destructuring
38
- static [Symbol.iterator]() {
39
- return errorCodec[Symbol.iterator]();
40
- }
41
- },
42
- }[className];
43
- const errorCodec = enhanceCodec(value, v => v.payload,
44
- // @ts-expect-error don't want to fix it really
45
- v => new C(v));
46
- return Object.assign(C, errorCodec);
47
- }
48
- export function ErrEnum(name, inner) {
49
- const values = Object.fromEntries(Object.entries(inner).map(([k, [value, message]]) => {
50
- return [k, Err(`${name}::${k}`, value, message, k)];
51
- }));
52
- const codec = enhanceCodec(Enum(values), v => ({ tag: v.className, value: v }), v => v.value);
53
- return Object.assign(codec, values);
54
- }
55
- /**
56
- * Wrapper around Bytes codec. Every usage of Hex codec should be threaded as raw Bytes with mapping to hex string.
57
- * @param [length] Optional, corresponds to byte array size, not the length of hex string.
58
- */
59
- export const Hex = (length) => enhanceCodec(Bytes(length), fromHex, toHex);
1
+ import { Err, Hex } from '@novasamatech/scale';
2
+ import { Struct, str } from 'scale-ts';
60
3
  export const GenesisHash = Hex();
61
4
  export const GenericErr = Struct({
62
5
  reason: str,
@@ -1,26 +1,25 @@
1
+ import type { EnumCodec } from '@novasamatech/scale';
1
2
  import type { Codec } from 'scale-ts';
2
- import type { EnumCodec } from './commonCodecs.js';
3
3
  import { AccountCreateProofV1_request, AccountCreateProofV1_response, AccountGetAliasV1_request, AccountGetAliasV1_response, AccountGetV1_request, AccountGetV1_response, GetNonProductAccountsV1_request, GetNonProductAccountsV1_response } from './v1/accounts.js';
4
- import { ChatActionSubscribeV1_receive, ChatActionSubscribeV1_start, ChatCreateContactV1_request, ChatCreateContactV1_response, ChatPostMessageV1_request, ChatPostMessageV1_response } from './v1/chat.js';
4
+ import { ChatActionSubscribeV1_receive, ChatActionSubscribeV1_start, ChatCreateRoomV1_request, ChatCreateRoomV1_response, ChatListSubscribeV1_receive, ChatListSubscribeV1_start, ChatPostMessageV1_request, ChatPostMessageV1_response } from './v1/chat.js';
5
5
  import { CreateTransactionV1_request, CreateTransactionV1_response, CreateTransactionWithNonProductAccountV1_request, CreateTransactionWithNonProductAccountV1_response } from './v1/createTransaction.js';
6
6
  import { FeatureV1_request, FeatureV1_response } from './v1/feature.js';
7
7
  import { HandshakeV1_request, HandshakeV1_response } from './v1/handshake.js';
8
8
  import { JsonRpcMessageSendV1_request, JsonRpcMessageSendV1_response, JsonRpcMessageSubscribeV1_receive, JsonRpcMessageSubscribeV1_start } from './v1/jsonRpc.js';
9
- import { PermissionRequestV1_request, PermissionRequestV1_response } from './v1/permission.js';
10
9
  import { SignPayloadV1_request, SignPayloadV1_response, SignRawV1_request, SignRawV1_response } from './v1/sign.js';
11
- import { StatementStoreCreateProofV1_request, StatementStoreCreateProofV1_response } from './v1/statementStore.js';
10
+ import { StatementStoreCreateProofV1_request, StatementStoreCreateProofV1_response, StatementStoreQueryV1_request, StatementStoreQueryV1_response, StatementStoreSubmitV1_request, StatementStoreSubmitV1_response, StatementStoreSubscribeV1_receive, StatementStoreSubscribeV1_start } from './v1/statementStore.js';
12
11
  import { StorageClearV1_request, StorageClearV1_response, StorageReadV1_request, StorageReadV1_response, StorageWriteV1_request, StorageWriteV1_response } from './v1/storage.js';
13
12
  export type VersionedArguments = Record<string, [Codec<any>, Codec<any>]>;
14
13
  type InferVersionedArgument<EnumValues extends VersionedArguments, N extends number> = {
15
14
  [V in keyof EnumValues]: EnumValues[V][N];
16
15
  };
17
16
  export type VersionedProtocolRequest<T extends VersionedArguments = VersionedArguments> = {
18
- type: 'request';
17
+ method: 'request';
19
18
  request: EnumCodec<InferVersionedArgument<T, 0>>;
20
19
  response: EnumCodec<InferVersionedArgument<T, 1>>;
21
20
  };
22
21
  export type VersionedProtocolSubscription<T extends VersionedArguments = VersionedArguments> = {
23
- type: 'subscription';
22
+ method: 'subscribe';
24
23
  start: EnumCodec<InferVersionedArgument<T, 0>>;
25
24
  receive: EnumCodec<InferVersionedArgument<T, 1>>;
26
25
  };
@@ -31,16 +30,13 @@ export type HostApiProtocol = {
31
30
  feature: VersionedProtocolRequest<{
32
31
  v1: [typeof FeatureV1_request, typeof FeatureV1_response];
33
32
  }>;
34
- permission_request: VersionedProtocolRequest<{
35
- v1: [typeof PermissionRequestV1_request, typeof PermissionRequestV1_response];
36
- }>;
37
- storage_read: VersionedProtocolRequest<{
33
+ local_storage_read: VersionedProtocolRequest<{
38
34
  v1: [typeof StorageReadV1_request, typeof StorageReadV1_response];
39
35
  }>;
40
- storage_write: VersionedProtocolRequest<{
36
+ local_storage_write: VersionedProtocolRequest<{
41
37
  v1: [typeof StorageWriteV1_request, typeof StorageWriteV1_response];
42
38
  }>;
43
- storage_clear: VersionedProtocolRequest<{
39
+ local_storage_clear: VersionedProtocolRequest<{
44
40
  v1: [typeof StorageClearV1_request, typeof StorageClearV1_response];
45
41
  }>;
46
42
  account_get: VersionedProtocolRequest<{
@@ -70,8 +66,11 @@ export type HostApiProtocol = {
70
66
  sign_payload: VersionedProtocolRequest<{
71
67
  v1: [typeof SignPayloadV1_request, typeof SignPayloadV1_response];
72
68
  }>;
73
- chat_create_contact: VersionedProtocolRequest<{
74
- v1: [typeof ChatCreateContactV1_request, typeof ChatCreateContactV1_response];
69
+ chat_create_room: VersionedProtocolRequest<{
70
+ v1: [typeof ChatCreateRoomV1_request, typeof ChatCreateRoomV1_response];
71
+ }>;
72
+ chat_list_subscribe: VersionedProtocolSubscription<{
73
+ v1: [typeof ChatListSubscribeV1_start, typeof ChatListSubscribeV1_receive];
75
74
  }>;
76
75
  chat_post_message: VersionedProtocolRequest<{
77
76
  v1: [typeof ChatPostMessageV1_request, typeof ChatPostMessageV1_response];
@@ -79,9 +78,18 @@ export type HostApiProtocol = {
79
78
  chat_action_subscribe: VersionedProtocolSubscription<{
80
79
  v1: [typeof ChatActionSubscribeV1_start, typeof ChatActionSubscribeV1_receive];
81
80
  }>;
81
+ statement_store_query: VersionedProtocolRequest<{
82
+ v1: [typeof StatementStoreQueryV1_request, typeof StatementStoreQueryV1_response];
83
+ }>;
84
+ statement_store_subscribe: VersionedProtocolSubscription<{
85
+ v1: [typeof StatementStoreSubscribeV1_start, typeof StatementStoreSubscribeV1_receive];
86
+ }>;
82
87
  statement_store_create_proof: VersionedProtocolRequest<{
83
88
  v1: [typeof StatementStoreCreateProofV1_request, typeof StatementStoreCreateProofV1_response];
84
89
  }>;
90
+ statement_store_submit: VersionedProtocolRequest<{
91
+ v1: [typeof StatementStoreSubmitV1_request, typeof StatementStoreSubmitV1_response];
92
+ }>;
85
93
  jsonrpc_message_send: VersionedProtocolRequest<{
86
94
  v1: [typeof JsonRpcMessageSendV1_request, typeof JsonRpcMessageSendV1_response];
87
95
  }>;