@novasamatech/host-api 0.5.0-1 → 0.5.0-11

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,9 +1,9 @@
1
1
  import type { Codec } from 'scale-ts';
2
- export declare const hexEncoder: Codec<`0x${string}`>;
3
- export declare function responseEncoder<T>(codec: Codec<T>): Codec<{
4
- tag: "success";
2
+ export declare const hexCodec: Codec<`0x${string}`>;
3
+ export declare function Result<T>(codec: Codec<T>): Codec<{
4
+ tag: "Ok";
5
5
  value: T;
6
6
  } | {
7
- tag: "error";
7
+ tag: "Err";
8
8
  value: string;
9
9
  }>;
@@ -1,14 +1,14 @@
1
1
  import { fromHex, toHex } from '@polkadot-api/utils';
2
2
  import { Bytes, Enum, str } from 'scale-ts';
3
3
  import { createTransportEncoder } from './createTransportEncoder.js';
4
- export const hexEncoder = createTransportEncoder({
4
+ export const hexCodec = createTransportEncoder({
5
5
  codec: Bytes(),
6
6
  from: v => toHex(v),
7
7
  to: fromHex,
8
8
  });
9
- export function responseEncoder(codec) {
9
+ export function Result(codec) {
10
10
  return Enum({
11
- success: codec,
12
- error: str,
11
+ Ok: codec,
12
+ Err: str,
13
13
  });
14
14
  }
@@ -174,7 +174,7 @@ export function createTransport(provider, params) {
174
174
  transportInstance.handleMessage('handshakeRequestV1', async () => ({
175
175
  tag: 'handshakeResponseV1',
176
176
  value: {
177
- tag: 'success',
177
+ tag: 'Ok',
178
178
  value: undefined,
179
179
  },
180
180
  }));
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- export { messageEncoder, unwrapResponseOrThrow } from './messageEncoder.js';
1
+ export { messageEncoder, unwrapResultOrThrow } from './messageEncoder.js';
2
2
  export { type MessagePayloadSchema, type MessageType, type PickMessagePayload, type PickMessagePayloadValue, } from './messageEncoder.js';
3
3
  export { createTransport } from './createTransport.js';
4
4
  export type { ConnectionStatus, HexString, Logger, Transport, TransportProvider } from './types.js';
5
5
  export { createDefaultLogger } from './logger.js';
6
6
  export { type InjectedAccountSchema } from './interactions/accounts.js';
7
7
  export { type TxPayloadV1 } from './interactions/sign.js';
8
+ export { signPayloadCodec } from './interactions/sign.js';
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
- export { messageEncoder, unwrapResponseOrThrow } from './messageEncoder.js';
1
+ export { messageEncoder, unwrapResultOrThrow } from './messageEncoder.js';
2
2
  export {} from './messageEncoder.js';
3
3
  export { createTransport } from './createTransport.js';
4
4
  export { createDefaultLogger } from './logger.js';
5
5
  export {} from './interactions/accounts.js';
6
6
  export {} from './interactions/sign.js';
7
+ export { signPayloadCodec } from './interactions/sign.js';
@@ -1,13 +1,13 @@
1
1
  import { Enum, Struct, bool } from 'scale-ts';
2
- import { hexEncoder } from '../commonEncoders.js';
2
+ import { hexCodec } from '../commonEncoders.js';
3
3
  export const supportFeatureRequestV1Encoder = Enum({
4
4
  chain: Struct({
5
- chainId: hexEncoder,
5
+ chainId: hexCodec,
6
6
  }),
7
7
  });
8
8
  export const supportFeatureResponseV1 = Enum({
9
9
  chain: Struct({
10
- chainId: hexEncoder,
10
+ chainId: hexCodec,
11
11
  result: bool,
12
12
  }),
13
13
  });
@@ -12,20 +12,19 @@ export declare const signRawRequestV1Encoder: import("scale-ts").Codec<SignerPay
12
12
  export type SignPayloadRequestSchema = CodecType<typeof signPayloadRequestV1Encoder>;
13
13
  export declare const signPayloadCodec: import("scale-ts").Codec<{
14
14
  address: string;
15
- assetId: `0x${string}` | undefined;
16
15
  blockHash: `0x${string}`;
17
16
  blockNumber: `0x${string}`;
18
17
  era: `0x${string}`;
19
18
  genesisHash: `0x${string}`;
20
- metadataHash: `0x${string}` | undefined;
21
19
  method: string;
22
- mode: number | undefined;
23
20
  nonce: `0x${string}`;
24
21
  specVersion: `0x${string}`;
25
22
  tip: `0x${string}`;
26
23
  transactionVersion: `0x${string}`;
27
24
  signedExtensions: string[];
28
25
  version: number;
26
+ assetId: `0x${string}` | undefined;
27
+ mode: number | undefined;
29
28
  withSignedTransaction: boolean | undefined;
30
29
  }>;
31
30
  export declare const signPayloadRequestV1Encoder: import("scale-ts").Codec<SignerPayloadJSON>;
@@ -1,5 +1,5 @@
1
1
  import { Bytes, Enum, Option, Struct, Vector, _void, bool, str, u16, u32 } from 'scale-ts';
2
- import { hexEncoder } from '../commonEncoders.js';
2
+ import { hexCodec } from '../commonEncoders.js';
3
3
  import { createTransportEncoder } from '../createTransportEncoder.js';
4
4
  const signRawRequestCodec = Struct({
5
5
  address: str,
@@ -31,20 +31,19 @@ export const signRawRequestV1Encoder = createTransportEncoder({
31
31
  });
32
32
  export const signPayloadCodec = Struct({
33
33
  address: str,
34
- assetId: Option(hexEncoder),
35
- blockHash: hexEncoder,
36
- blockNumber: hexEncoder,
37
- era: hexEncoder,
38
- genesisHash: hexEncoder,
39
- metadataHash: Option(hexEncoder),
34
+ blockHash: hexCodec,
35
+ blockNumber: hexCodec,
36
+ era: hexCodec,
37
+ genesisHash: hexCodec,
40
38
  method: str,
41
- mode: Option(u32),
42
- nonce: hexEncoder,
43
- specVersion: hexEncoder,
44
- tip: hexEncoder,
45
- transactionVersion: hexEncoder,
39
+ nonce: hexCodec,
40
+ specVersion: hexCodec,
41
+ tip: hexCodec,
42
+ transactionVersion: hexCodec,
46
43
  signedExtensions: Vector(str),
47
44
  version: u32,
45
+ assetId: Option(hexCodec),
46
+ mode: Option(u32),
48
47
  withSignedTransaction: Option(bool),
49
48
  });
50
49
  export const signPayloadRequestV1Encoder = createTransportEncoder({
@@ -57,7 +56,6 @@ export const signPayloadRequestV1Encoder = createTransportEncoder({
57
56
  blockNumber: decoded.blockNumber,
58
57
  era: decoded.era,
59
58
  genesisHash: decoded.genesisHash,
60
- metadataHash: decoded.metadataHash,
61
59
  method: decoded.method,
62
60
  mode: decoded.mode,
63
61
  nonce: decoded.nonce,
@@ -92,9 +90,9 @@ export const signPayloadRequestV1Encoder = createTransportEncoder({
92
90
  });
93
91
  const signResult = Struct({
94
92
  id: u32,
95
- signature: hexEncoder,
93
+ signature: hexCodec,
96
94
  signedTransaction: Option(Enum({
97
- hex: hexEncoder,
95
+ hex: hexCodec,
98
96
  buffer: Bytes(),
99
97
  })),
100
98
  });
@@ -133,15 +131,15 @@ export const signResponseV1Encoder = createTransportEncoder({
133
131
  const createTransactionRequestCodec = Struct({
134
132
  version: u16,
135
133
  signer: Option(str),
136
- callData: hexEncoder,
134
+ callData: hexCodec,
137
135
  extensions: Vector(Struct({
138
136
  id: str,
139
- extra: hexEncoder,
140
- additionalSigned: hexEncoder,
137
+ extra: hexCodec,
138
+ additionalSigned: hexCodec,
141
139
  })),
142
140
  txExtVersion: u16,
143
141
  context: Struct({
144
- metadata: hexEncoder,
142
+ metadata: hexCodec,
145
143
  tokenSymbol: str,
146
144
  tokenDecimals: u32,
147
145
  bestBlockHeight: u32,
@@ -166,4 +164,4 @@ export const createTransactionRequestV1Encoder = createTransportEncoder({
166
164
  };
167
165
  },
168
166
  });
169
- export const createTransactionResponseV1Encoder = hexEncoder;
167
+ export const createTransactionResponseV1Encoder = hexCodec;
@@ -1,6 +1,6 @@
1
1
  import type { CodecType } from 'scale-ts';
2
- import { responseEncoder } from './commonEncoders.js';
3
- export declare function unwrapResponseOrThrow<T>(response: CodecType<ReturnType<typeof responseEncoder<T>>>): T;
2
+ import { Result } from './commonEncoders.js';
3
+ export declare function unwrapResultOrThrow<T>(response: CodecType<ReturnType<typeof Result<T>>>): T;
4
4
  export type MessagePayloadSchema = CodecType<typeof messagePayloadEncoder>;
5
5
  export declare const messagePayloadEncoder: import("scale-ts").Codec<{
6
6
  tag: "handshakeRequestV1";
@@ -8,10 +8,10 @@ export declare const messagePayloadEncoder: import("scale-ts").Codec<{
8
8
  } | {
9
9
  tag: "handshakeResponseV1";
10
10
  value: {
11
- tag: "success";
11
+ tag: "Ok";
12
12
  value: undefined;
13
13
  } | {
14
- tag: "error";
14
+ tag: "Err";
15
15
  value: string;
16
16
  };
17
17
  } | {
@@ -20,10 +20,10 @@ export declare const messagePayloadEncoder: import("scale-ts").Codec<{
20
20
  } | {
21
21
  tag: "getAccountsResponseV1";
22
22
  value: {
23
- tag: "success";
23
+ tag: "Ok";
24
24
  value: import("@polkadot-api/pjs-signer").InjectedAccount[];
25
25
  } | {
26
- tag: "error";
26
+ tag: "Err";
27
27
  value: string;
28
28
  };
29
29
  } | {
@@ -43,7 +43,7 @@ export declare const messagePayloadEncoder: import("scale-ts").Codec<{
43
43
  } | {
44
44
  tag: "supportFeatureResponseV1";
45
45
  value: {
46
- tag: "success";
46
+ tag: "Ok";
47
47
  value: {
48
48
  tag: "chain";
49
49
  value: {
@@ -52,7 +52,7 @@ export declare const messagePayloadEncoder: import("scale-ts").Codec<{
52
52
  };
53
53
  };
54
54
  } | {
55
- tag: "error";
55
+ tag: "Err";
56
56
  value: string;
57
57
  };
58
58
  } | {
@@ -64,13 +64,13 @@ export declare const messagePayloadEncoder: import("scale-ts").Codec<{
64
64
  } | {
65
65
  tag: "papiProviderReceiveMessageV1";
66
66
  value: {
67
- tag: "success";
67
+ tag: "Ok";
68
68
  value: {
69
69
  chainId: string;
70
70
  message: string;
71
71
  };
72
72
  } | {
73
- tag: "error";
73
+ tag: "Err";
74
74
  value: string;
75
75
  };
76
76
  } | {
@@ -82,10 +82,10 @@ export declare const messagePayloadEncoder: import("scale-ts").Codec<{
82
82
  } | {
83
83
  tag: "signResponseV1";
84
84
  value: {
85
- tag: "success";
85
+ tag: "Ok";
86
86
  value: import("@polkadot/types/types").SignerResult;
87
87
  } | {
88
- tag: "error";
88
+ tag: "Err";
89
89
  value: string;
90
90
  };
91
91
  } | {
@@ -94,10 +94,10 @@ export declare const messagePayloadEncoder: import("scale-ts").Codec<{
94
94
  } | {
95
95
  tag: "createTransactionResponseV1";
96
96
  value: {
97
- tag: "success";
97
+ tag: "Ok";
98
98
  value: `0x${string}`;
99
99
  } | {
100
- tag: "error";
100
+ tag: "Err";
101
101
  value: string;
102
102
  };
103
103
  } | {
@@ -113,10 +113,10 @@ export declare const messageEncoder: import("scale-ts").Codec<{
113
113
  } | {
114
114
  tag: "handshakeResponseV1";
115
115
  value: {
116
- tag: "success";
116
+ tag: "Ok";
117
117
  value: undefined;
118
118
  } | {
119
- tag: "error";
119
+ tag: "Err";
120
120
  value: string;
121
121
  };
122
122
  } | {
@@ -125,10 +125,10 @@ export declare const messageEncoder: import("scale-ts").Codec<{
125
125
  } | {
126
126
  tag: "getAccountsResponseV1";
127
127
  value: {
128
- tag: "success";
128
+ tag: "Ok";
129
129
  value: import("@polkadot-api/pjs-signer").InjectedAccount[];
130
130
  } | {
131
- tag: "error";
131
+ tag: "Err";
132
132
  value: string;
133
133
  };
134
134
  } | {
@@ -148,7 +148,7 @@ export declare const messageEncoder: import("scale-ts").Codec<{
148
148
  } | {
149
149
  tag: "supportFeatureResponseV1";
150
150
  value: {
151
- tag: "success";
151
+ tag: "Ok";
152
152
  value: {
153
153
  tag: "chain";
154
154
  value: {
@@ -157,7 +157,7 @@ export declare const messageEncoder: import("scale-ts").Codec<{
157
157
  };
158
158
  };
159
159
  } | {
160
- tag: "error";
160
+ tag: "Err";
161
161
  value: string;
162
162
  };
163
163
  } | {
@@ -169,13 +169,13 @@ export declare const messageEncoder: import("scale-ts").Codec<{
169
169
  } | {
170
170
  tag: "papiProviderReceiveMessageV1";
171
171
  value: {
172
- tag: "success";
172
+ tag: "Ok";
173
173
  value: {
174
174
  chainId: string;
175
175
  message: string;
176
176
  };
177
177
  } | {
178
- tag: "error";
178
+ tag: "Err";
179
179
  value: string;
180
180
  };
181
181
  } | {
@@ -187,10 +187,10 @@ export declare const messageEncoder: import("scale-ts").Codec<{
187
187
  } | {
188
188
  tag: "signResponseV1";
189
189
  value: {
190
- tag: "success";
190
+ tag: "Ok";
191
191
  value: import("@polkadot/types/types").SignerResult;
192
192
  } | {
193
- tag: "error";
193
+ tag: "Err";
194
194
  value: string;
195
195
  };
196
196
  } | {
@@ -199,10 +199,10 @@ export declare const messageEncoder: import("scale-ts").Codec<{
199
199
  } | {
200
200
  tag: "createTransactionResponseV1";
201
201
  value: {
202
- tag: "success";
202
+ tag: "Ok";
203
203
  value: `0x${string}`;
204
204
  } | {
205
- tag: "error";
205
+ tag: "Err";
206
206
  value: string;
207
207
  };
208
208
  } | {
@@ -1,34 +1,34 @@
1
1
  import { Enum, Struct, str } from 'scale-ts';
2
- import { responseEncoder } from './commonEncoders.js';
2
+ import { Result } from './commonEncoders.js';
3
3
  import { accountSubscriptionV1Encoder, accountUnsubscriptionV1Encoder, getAccountsRequestV1Encoder, getAccountsResponseV1Encoder, } from './interactions/accounts.js';
4
4
  import { supportFeatureRequestV1Encoder, supportFeatureResponseV1 } from './interactions/features.js';
5
5
  import { handshakeRequestV1Encoder, handshakeResponseV1Encoder } from './interactions/handshake.js';
6
6
  import { papiProviderReceiveMessageV1Encoder, papiProviderSendMessageV1Encoder } from './interactions/papiProvider.js';
7
7
  import { createTransactionRequestV1Encoder, createTransactionResponseV1Encoder, signPayloadRequestV1Encoder, signRawRequestV1Encoder, signResponseV1Encoder, } from './interactions/sign.js';
8
- export function unwrapResponseOrThrow(response) {
9
- if (response.tag === 'success') {
10
- return response.value;
11
- }
12
- else {
13
- throw new Error(response.value);
8
+ export function unwrapResultOrThrow(response) {
9
+ switch (response.tag) {
10
+ case 'Ok':
11
+ return response.value;
12
+ case 'Err':
13
+ throw new Error(response.value);
14
14
  }
15
15
  }
16
16
  export const messagePayloadEncoder = Enum({
17
17
  handshakeRequestV1: handshakeRequestV1Encoder,
18
- handshakeResponseV1: responseEncoder(handshakeResponseV1Encoder),
18
+ handshakeResponseV1: Result(handshakeResponseV1Encoder),
19
19
  getAccountsRequestV1: getAccountsRequestV1Encoder,
20
- getAccountsResponseV1: responseEncoder(getAccountsResponseV1Encoder),
20
+ getAccountsResponseV1: Result(getAccountsResponseV1Encoder),
21
21
  accountSubscriptionV1: accountSubscriptionV1Encoder,
22
22
  accountUnsubscriptionV1: accountUnsubscriptionV1Encoder,
23
23
  supportFeatureRequestV1: supportFeatureRequestV1Encoder,
24
- supportFeatureResponseV1: responseEncoder(supportFeatureResponseV1),
24
+ supportFeatureResponseV1: Result(supportFeatureResponseV1),
25
25
  papiProviderSendMessageV1: papiProviderSendMessageV1Encoder,
26
- papiProviderReceiveMessageV1: responseEncoder(papiProviderReceiveMessageV1Encoder),
26
+ papiProviderReceiveMessageV1: Result(papiProviderReceiveMessageV1Encoder),
27
27
  signRawRequestV1: signRawRequestV1Encoder,
28
28
  signPayloadRequestV1: signPayloadRequestV1Encoder,
29
- signResponseV1: responseEncoder(signResponseV1Encoder),
29
+ signResponseV1: Result(signResponseV1Encoder),
30
30
  createTransactionRequestV1: createTransactionRequestV1Encoder,
31
- createTransactionResponseV1: responseEncoder(createTransactionResponseV1Encoder),
31
+ createTransactionResponseV1: Result(createTransactionResponseV1Encoder),
32
32
  locationChangedV1: str,
33
33
  });
34
34
  export const messageEncoder = Struct({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-api",
3
3
  "type": "module",
4
- "version": "0.5.0-1",
4
+ "version": "0.5.0-11",
5
5
  "description": "Host API: transport implementation for host - product integration.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -21,7 +21,7 @@
21
21
  "README.md"
22
22
  ],
23
23
  "dependencies": {
24
- "@polkadot-api/utils": "0.2.0",
24
+ "@polkadot-api/utils": "^0.2.0",
25
25
  "nanoevents": "9.1.0",
26
26
  "nanoid": "5.1.6",
27
27
  "scale-ts": "1.6.1"