@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.
@@ -1,5 +1,6 @@
1
+ import { Enum, ErrEnum } from '@novasamatech/scale';
1
2
  import { Bytes, Option, Result, Struct, Tuple, Vector, _void, u32, u64 } from 'scale-ts';
2
- import { Enum, ErrEnum, GenericErr } from '../commonCodecs.js';
3
+ import { GenericErr, GenericError } from '../commonCodecs.js';
3
4
  import { ProductAccountId } from './accounts.js';
4
5
  // structs definition
5
6
  export const Topic = Bytes(32);
@@ -37,6 +38,19 @@ export const Statement = Struct({
37
38
  topics: Vector(Topic),
38
39
  data: Option(Bytes()),
39
40
  });
41
+ export const SignedStatement = Struct({
42
+ proof: StatementProof,
43
+ decryptionKey: Option(DecryptionKey),
44
+ priority: Option(u32),
45
+ channel: Option(Channel),
46
+ topics: Vector(Topic),
47
+ data: Option(Bytes()),
48
+ });
49
+ // query
50
+ export const StatementStoreQueryV1_request = Vector(Topic);
51
+ export const StatementStoreQueryV1_response = Result(Vector(SignedStatement), GenericError);
52
+ export const StatementStoreSubscribeV1_start = Vector(Topic);
53
+ export const StatementStoreSubscribeV1_receive = Vector(SignedStatement);
40
54
  // creating proof
41
55
  export const StatementProofErr = ErrEnum('StatementProofErr', {
42
56
  UnableToSign: [_void, 'StatementProof: unable to sign'],
@@ -45,3 +59,6 @@ export const StatementProofErr = ErrEnum('StatementProofErr', {
45
59
  });
46
60
  export const StatementStoreCreateProofV1_request = Tuple(ProductAccountId, Statement);
47
61
  export const StatementStoreCreateProofV1_response = Result(StatementProof, StatementProofErr);
62
+ // submit
63
+ export const StatementStoreSubmitV1_request = SignedStatement;
64
+ export const StatementStoreSubmitV1_response = Result(_void, GenericError);
@@ -1,87 +1,31 @@
1
- export declare const StorageErr: [import("scale-ts").Encoder<(Error & {
2
- name: "StorageErr::Unknown";
3
- className: string;
4
- payload: {
1
+ export declare const StorageErr: [import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<{
2
+ reason: string;
3
+ }, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>, import("scale-ts").Decoder<import("@novasamatech/scale").CodecError<{
4
+ reason: string;
5
+ }, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>] & {
6
+ enc: import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<{
5
7
  reason: string;
6
- };
7
- }) | (Error & {
8
- name: "StorageErr::Full";
9
- className: string;
10
- payload: undefined;
11
- })>, import("scale-ts").Decoder<(Error & {
12
- name: "StorageErr::Unknown";
13
- className: string;
14
- payload: {
8
+ }, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>;
9
+ dec: import("scale-ts").Decoder<import("@novasamatech/scale").CodecError<{
15
10
  reason: string;
16
- };
17
- }) | (Error & {
18
- name: "StorageErr::Full";
19
- className: string;
20
- payload: undefined;
21
- })>] & {
22
- enc: import("scale-ts").Encoder<(Error & {
23
- name: "StorageErr::Unknown";
24
- className: string;
25
- payload: {
26
- reason: string;
27
- };
28
- }) | (Error & {
29
- name: "StorageErr::Full";
30
- className: string;
31
- payload: undefined;
32
- })>;
33
- dec: import("scale-ts").Decoder<(Error & {
34
- name: "StorageErr::Unknown";
35
- className: string;
36
- payload: {
37
- reason: string;
38
- };
39
- }) | (Error & {
40
- name: "StorageErr::Full";
41
- className: string;
42
- payload: undefined;
43
- })>;
11
+ }, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>;
44
12
  } & {
45
- readonly Full: import("../commonCodecs.js").ErrCodec<undefined, "StorageErr::Full">;
46
- readonly Unknown: import("../commonCodecs.js").ErrCodec<{
13
+ readonly Full: import("@novasamatech/scale").ErrCodec<undefined, "StorageErr::Full">;
14
+ readonly Unknown: import("@novasamatech/scale").ErrCodec<{
47
15
  reason: string;
48
16
  }, "StorageErr::Unknown">;
49
17
  };
50
- export declare const StorageKey: import("scale-ts").Codec<`0x${string}`>;
18
+ export declare const StorageKey: import("scale-ts").Codec<string>;
51
19
  export declare const StorageValue: import("scale-ts").Codec<Uint8Array<ArrayBufferLike>>;
52
- export declare const StorageReadV1_request: import("scale-ts").Codec<`0x${string}`>;
53
- export declare const StorageReadV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<Uint8Array<ArrayBufferLike> | undefined, (Error & {
54
- name: "StorageErr::Unknown";
55
- className: string;
56
- payload: {
57
- reason: string;
58
- };
59
- }) | (Error & {
60
- name: "StorageErr::Full";
61
- className: string;
62
- payload: undefined;
63
- })>>;
64
- export declare const StorageWriteV1_request: import("scale-ts").Codec<[`0x${string}`, Uint8Array<ArrayBufferLike>]>;
65
- export declare const StorageWriteV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, (Error & {
66
- name: "StorageErr::Unknown";
67
- className: string;
68
- payload: {
69
- reason: string;
70
- };
71
- }) | (Error & {
72
- name: "StorageErr::Full";
73
- className: string;
74
- payload: undefined;
75
- })>>;
76
- export declare const StorageClearV1_request: import("scale-ts").Codec<`0x${string}`>;
77
- export declare const StorageClearV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, (Error & {
78
- name: "StorageErr::Unknown";
79
- className: string;
80
- payload: {
81
- reason: string;
82
- };
83
- }) | (Error & {
84
- name: "StorageErr::Full";
85
- className: string;
86
- payload: undefined;
87
- })>>;
20
+ export declare const StorageReadV1_request: import("scale-ts").Codec<string>;
21
+ export declare const StorageReadV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<Uint8Array<ArrayBufferLike> | undefined, import("@novasamatech/scale").CodecError<{
22
+ reason: string;
23
+ }, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>>;
24
+ export declare const StorageWriteV1_request: import("scale-ts").Codec<[string, Uint8Array<ArrayBufferLike>]>;
25
+ export declare const StorageWriteV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
26
+ reason: string;
27
+ }, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>>;
28
+ export declare const StorageClearV1_request: import("scale-ts").Codec<string>;
29
+ export declare const StorageClearV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
30
+ reason: string;
31
+ }, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>>;
@@ -1,11 +1,12 @@
1
- import { Bytes, Option, Result, Tuple, _void } from 'scale-ts';
2
- import { ErrEnum, GenericErr, Hex } from '../commonCodecs.js';
1
+ import { ErrEnum } from '@novasamatech/scale';
2
+ import { Bytes, Option, Result, Tuple, _void, str } from 'scale-ts';
3
+ import { GenericErr } from '../commonCodecs.js';
3
4
  // common structures
4
5
  export const StorageErr = ErrEnum('StorageErr', {
5
6
  Full: [_void, 'Storage is full'],
6
- Unknown: [GenericErr, 'Storage: unknown error'],
7
+ Unknown: [GenericErr, 'Unknown storage error'],
7
8
  });
8
- export const StorageKey = Hex();
9
+ export const StorageKey = str;
9
10
  export const StorageValue = Bytes();
10
11
  // actions
11
12
  export const StorageReadV1_request = StorageKey;
package/dist/transport.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { enumValue, isEnumVariant, resultErr, resultOk } from '@novasamatech/scale';
1
2
  import { createNanoEvents } from 'nanoevents';
2
3
  import { HANDSHAKE_INTERVAL, HANDSHAKE_TIMEOUT, JAM_CODEC_PROTOCOL_ID } from './constants.js';
3
- import { composeAction, createRequestId, delay, enumValue, errResult, isEnumVariant, okResult, promiseWithResolvers, } from './helpers.js';
4
+ import { composeAction, createRequestId, delay, promiseWithResolvers } from './helpers.js';
4
5
  import { Message } from './protocol/messageCodec.js';
5
6
  import { HandshakeErr } from './protocol/v1/handshake.js';
6
7
  const isConnected = (status) => status === 'connected';
@@ -234,13 +235,13 @@ export function createTransport(provider) {
234
235
  codecVersion = version.value;
235
236
  switch (version.value) {
236
237
  case JAM_CODEC_PROTOCOL_ID:
237
- return enumValue(version.tag, okResult(undefined));
238
+ return enumValue(version.tag, resultOk(undefined));
238
239
  default:
239
- return enumValue(version.tag, errResult(new HandshakeErr.UnsupportedProtocolVersion(undefined)));
240
+ return enumValue(version.tag, resultErr(new HandshakeErr.UnsupportedProtocolVersion(undefined)));
240
241
  }
241
242
  }
242
243
  default:
243
- return enumValue(version.tag, errResult(new HandshakeErr.UnsupportedProtocolVersion(undefined)));
244
+ return enumValue(version.tag, resultErr(new HandshakeErr.UnsupportedProtocolVersion(undefined)));
244
245
  }
245
246
  });
246
247
  }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import type { HostApiProtocol } from './protocol/impl.js';
1
2
  import type { ComposeMessageAction, MessageAction, MessagePayloadSchema, PickMessagePayload, PickMessagePayloadValue } from './protocol/messageCodec.js';
2
3
  import type { Provider } from './provider.js';
4
+ export type HostApiMethod = keyof HostApiProtocol;
3
5
  export type Logger = Record<'info' | 'warn' | 'error' | 'log', (...args: unknown[]) => void>;
4
6
  export type ConnectionStatus = 'connecting' | 'connected' | 'disconnected';
5
7
  export type RequestHandler<Method extends string> = (message: PickMessagePayloadValue<ComposeMessageAction<Method, 'request'>>) => PromiseLike<PickMessagePayloadValue<ComposeMessageAction<Method, 'response'>>>;
@@ -14,10 +16,10 @@ export type Transport = {
14
16
  isReady(): Promise<boolean>;
15
17
  onConnectionStatusChange(callback: (status: ConnectionStatus) => void): VoidFunction;
16
18
  dispose(): void;
17
- request<const Method extends string>(method: Method, payload: PickMessagePayloadValue<ComposeMessageAction<Method, 'request'>>, signal?: AbortSignal): Promise<PickMessagePayloadValue<ComposeMessageAction<Method, 'response'>>>;
18
- handleRequest<const Method extends string>(method: Method, handler: RequestHandler<Method>): VoidFunction;
19
- subscribe<const Method extends string>(method: Method, payload: PickMessagePayloadValue<ComposeMessageAction<Method, 'start'>>, callback: (payload: PickMessagePayloadValue<ComposeMessageAction<Method, 'receive'>>) => void): Subscription;
20
- handleSubscription<const Method extends string>(method: Method, handler: SubscriptionHandler<Method>): VoidFunction;
19
+ request<const Method extends HostApiMethod>(method: Method, payload: PickMessagePayloadValue<ComposeMessageAction<Method, 'request'>>, signal?: AbortSignal): Promise<PickMessagePayloadValue<ComposeMessageAction<Method, 'response'>>>;
20
+ handleRequest<const Method extends HostApiMethod>(method: Method, handler: RequestHandler<Method>): VoidFunction;
21
+ subscribe<const Method extends HostApiMethod>(method: Method, payload: PickMessagePayloadValue<ComposeMessageAction<Method, 'start'>>, callback: (payload: PickMessagePayloadValue<ComposeMessageAction<Method, 'receive'>>) => void): Subscription;
22
+ handleSubscription<const Method extends HostApiMethod>(method: Method, handler: SubscriptionHandler<Method>): VoidFunction;
21
23
  postMessage(requestId: string, payload: MessagePayloadSchema): void;
22
24
  listenMessages<const Action extends MessageAction>(action: Action, callback: (requestId: string, data: PickMessagePayload<Action>) => void, onError?: (error: unknown) => void): VoidFunction;
23
25
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-api",
3
3
  "type": "module",
4
- "version": "0.5.2",
4
+ "version": "0.5.4-0",
5
5
  "description": "Host API: transport implementation for host - product integration.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -21,6 +21,7 @@
21
21
  "README.md"
22
22
  ],
23
23
  "dependencies": {
24
+ "@novasamatech/scale": "0.5.4-0",
24
25
  "@polkadot-api/utils": "^0.2.0",
25
26
  "nanoevents": "9.1.0",
26
27
  "nanoid": "5.1.6",