@novasamatech/host-api 0.5.0-9 → 0.5.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.
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
@@ -1,101 +0,0 @@
1
- import type { SignerPayloadJSON, SignerPayloadRaw, SignerResult } from '@polkadot/types/types';
2
- import type { CodecType } from 'scale-ts';
3
- import type { HexString } from '../types.js';
4
- /**
5
- * @see {import('@polkadot/types/types').SignerPayloadRaw}
6
- */
7
- export type SignRawRequestSchema = CodecType<typeof signRawRequestV1Encoder>;
8
- export declare const signRawRequestV1Encoder: import("scale-ts").Codec<SignerPayloadRaw>;
9
- /**
10
- * @see {import('@polkadot/types/types').SignerPayloadJSON}
11
- */
12
- export type SignPayloadRequestSchema = CodecType<typeof signPayloadRequestV1Encoder>;
13
- export declare const signPayloadCodec: import("scale-ts").Codec<{
14
- address: string;
15
- assetId: `0x${string}` | undefined;
16
- blockHash: `0x${string}`;
17
- blockNumber: `0x${string}`;
18
- era: `0x${string}`;
19
- genesisHash: `0x${string}`;
20
- metadataHash: `0x${string}` | undefined;
21
- method: string;
22
- mode: number | undefined;
23
- nonce: `0x${string}`;
24
- specVersion: `0x${string}`;
25
- tip: `0x${string}`;
26
- transactionVersion: `0x${string}`;
27
- signedExtensions: string[];
28
- version: number;
29
- withSignedTransaction: boolean | undefined;
30
- }>;
31
- export declare const signPayloadRequestV1Encoder: import("scale-ts").Codec<SignerPayloadJSON>;
32
- export declare const signResponseV1Encoder: import("scale-ts").Codec<SignerResult>;
33
- /**
34
- * createTransaction implementation
35
- * @see https://github.com/polkadot-js/api/issues/6213
36
- */
37
- export interface TxPayloadV1 {
38
- /** Payload version. MUST be 1. */
39
- version: 1;
40
- /**
41
- * Signer selection hint. Allows the implementer to identify which private-key / scheme to use.
42
- * - Use a wallet-defined handle (e.g., address/SS58, account-name, etc). This identifier
43
- * was previously made available to the consumer.
44
- * - Set `null` to let the implementer pick the signer (or if the signer is implied).
45
- */
46
- signer: string | null;
47
- /**
48
- * SCALE-encoded Call (module indicator + function indicator + params).
49
- */
50
- callData: HexString;
51
- /**
52
- * Transaction extensions supplied by the caller (order irrelevant).
53
- * The consumer SHOULD provide every extension that is relevant to them.
54
- * The implementer MAY infer missing ones.
55
- */
56
- extensions: Array<{
57
- /** Identifier as defined in metadata (e.g., "CheckSpecVersion", "ChargeAssetTxPayment"). */
58
- id: string;
59
- /**
60
- * Explicit "extra" to sign (goes into the extrinsic body).
61
- * SCALE-encoded per the extension's "extra" type as defined in the metadata.
62
- */
63
- extra: HexString;
64
- /**
65
- * "Implicit" data to sign (known by the chain, not included into the extrinsic body).
66
- * SCALE-encoded per the extension's "additionalSigned" type as defined in the metadata.
67
- */
68
- additionalSigned: HexString;
69
- }>;
70
- /**
71
- * Transaction Extension Version.
72
- * - For Extrinsic V4 MUST be 0.
73
- * - For Extrinsic V5, set to any version supported by the runtime.
74
- * The implementer:
75
- * - MUST use this field to determine the required extensions for creating the extrinsic.
76
- * - MAY use this field to infer missing extensions that the implementer could know how to handle.
77
- */
78
- txExtVersion: number;
79
- /**
80
- * Context needed for decoding, display, and (optionally) inferring certain extensions.
81
- */
82
- context: {
83
- /**
84
- * RuntimeMetadataPrefixed blob (SCALE), starting with ASCII "meta" magic (`0x6d657461`),
85
- * then a metadata version (V14+). For V5+ versioned extensions, MUST provide V16+.
86
- */
87
- metadata: HexString;
88
- /**
89
- * Native token display info (used by some implementers), also needed to compute
90
- * the `CheckMetadataHash` value.
91
- */
92
- tokenSymbol: string;
93
- tokenDecimals: number;
94
- /**
95
- * Highest known block number to aid mortality UX.
96
- */
97
- bestBlockHeight: number;
98
- };
99
- }
100
- export declare const createTransactionRequestV1Encoder: import("scale-ts").Codec<TxPayloadV1>;
101
- export declare const createTransactionResponseV1Encoder: import("scale-ts").Codec<`0x${string}`>;
@@ -1,169 +0,0 @@
1
- import { Bytes, Enum, Option, Struct, Vector, _void, bool, str, u16, u32 } from 'scale-ts';
2
- import { hexEncoder } from '../commonEncoders.js';
3
- import { createTransportEncoder } from '../createTransportEncoder.js';
4
- const signRawRequestCodec = Struct({
5
- address: str,
6
- data: str,
7
- type: Enum({
8
- bytes: _void,
9
- payload: _void,
10
- }),
11
- });
12
- export const signRawRequestV1Encoder = createTransportEncoder({
13
- codec: signRawRequestCodec,
14
- from(decoded) {
15
- return {
16
- address: decoded.address,
17
- data: decoded.data,
18
- type: decoded.type.tag,
19
- };
20
- },
21
- to(value) {
22
- return {
23
- address: value.address,
24
- data: value.data,
25
- type: {
26
- tag: value.type,
27
- value: undefined,
28
- },
29
- };
30
- },
31
- });
32
- export const signPayloadCodec = Struct({
33
- address: str,
34
- assetId: Option(hexEncoder),
35
- blockHash: hexEncoder,
36
- blockNumber: hexEncoder,
37
- era: hexEncoder,
38
- genesisHash: hexEncoder,
39
- metadataHash: Option(hexEncoder),
40
- method: str,
41
- mode: Option(u32),
42
- nonce: hexEncoder,
43
- specVersion: hexEncoder,
44
- tip: hexEncoder,
45
- transactionVersion: hexEncoder,
46
- signedExtensions: Vector(str),
47
- version: u32,
48
- withSignedTransaction: Option(bool),
49
- });
50
- export const signPayloadRequestV1Encoder = createTransportEncoder({
51
- codec: signPayloadCodec,
52
- from(decoded) {
53
- return {
54
- address: decoded.address,
55
- assetId: decoded.assetId,
56
- blockHash: decoded.blockHash,
57
- blockNumber: decoded.blockNumber,
58
- era: decoded.era,
59
- genesisHash: decoded.genesisHash,
60
- metadataHash: decoded.metadataHash,
61
- method: decoded.method,
62
- mode: decoded.mode,
63
- nonce: decoded.nonce,
64
- specVersion: decoded.specVersion,
65
- tip: decoded.tip,
66
- transactionVersion: decoded.transactionVersion,
67
- signedExtensions: decoded.signedExtensions,
68
- version: decoded.version,
69
- withSignedTransaction: decoded.withSignedTransaction,
70
- };
71
- },
72
- to(value) {
73
- return {
74
- address: value.address,
75
- assetId: value.assetId,
76
- blockHash: value.blockHash,
77
- blockNumber: value.blockNumber,
78
- era: value.era,
79
- genesisHash: value.genesisHash,
80
- metadataHash: value.metadataHash,
81
- method: value.method,
82
- mode: value.mode,
83
- nonce: value.nonce,
84
- specVersion: value.specVersion,
85
- tip: value.tip,
86
- transactionVersion: value.transactionVersion,
87
- signedExtensions: value.signedExtensions,
88
- version: value.version,
89
- withSignedTransaction: value.withSignedTransaction,
90
- };
91
- },
92
- });
93
- const signResult = Struct({
94
- id: u32,
95
- signature: hexEncoder,
96
- signedTransaction: Option(Enum({
97
- hex: hexEncoder,
98
- buffer: Bytes(),
99
- })),
100
- });
101
- export const signResponseV1Encoder = createTransportEncoder({
102
- codec: signResult,
103
- from(decoded) {
104
- return {
105
- id: decoded.id,
106
- signature: decoded.signature,
107
- signedTransaction: decoded.signedTransaction ? decoded.signedTransaction.value : undefined,
108
- };
109
- },
110
- to(value) {
111
- let signedTransaction = undefined;
112
- if (value.signedTransaction) {
113
- if (typeof value.signedTransaction === 'string') {
114
- signedTransaction = {
115
- tag: 'hex',
116
- value: value.signedTransaction,
117
- };
118
- }
119
- else {
120
- signedTransaction = {
121
- tag: 'buffer',
122
- value: value.signedTransaction,
123
- };
124
- }
125
- }
126
- return {
127
- id: value.id,
128
- signature: value.signature,
129
- signedTransaction: signedTransaction,
130
- };
131
- },
132
- });
133
- const createTransactionRequestCodec = Struct({
134
- version: u16,
135
- signer: Option(str),
136
- callData: hexEncoder,
137
- extensions: Vector(Struct({
138
- id: str,
139
- extra: hexEncoder,
140
- additionalSigned: hexEncoder,
141
- })),
142
- txExtVersion: u16,
143
- context: Struct({
144
- metadata: hexEncoder,
145
- tokenSymbol: str,
146
- tokenDecimals: u32,
147
- bestBlockHeight: u32,
148
- }),
149
- });
150
- export const createTransactionRequestV1Encoder = createTransportEncoder({
151
- codec: createTransactionRequestCodec,
152
- from({ version, signer, ...rest }) {
153
- if (version !== 1) {
154
- throw new Error(`TxPayload supported version are: 1. Got ${version}`);
155
- }
156
- return {
157
- version,
158
- signer: signer ?? null,
159
- ...rest,
160
- };
161
- },
162
- to({ signer, ...rest }) {
163
- return {
164
- signer: signer ?? undefined,
165
- ...rest,
166
- };
167
- },
168
- });
169
- export const createTransactionResponseV1Encoder = hexEncoder;
@@ -1,217 +0,0 @@
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;
4
- export type MessagePayloadSchema = CodecType<typeof messagePayloadEncoder>;
5
- export declare const messagePayloadEncoder: import("scale-ts").Codec<{
6
- tag: "handshakeRequestV1";
7
- value: undefined;
8
- } | {
9
- tag: "handshakeResponseV1";
10
- value: {
11
- tag: "success";
12
- value: undefined;
13
- } | {
14
- tag: "error";
15
- value: string;
16
- };
17
- } | {
18
- tag: "getAccountsRequestV1";
19
- value: undefined;
20
- } | {
21
- tag: "getAccountsResponseV1";
22
- value: {
23
- tag: "success";
24
- value: import("@polkadot-api/pjs-signer").InjectedAccount[];
25
- } | {
26
- tag: "error";
27
- value: string;
28
- };
29
- } | {
30
- tag: "accountSubscriptionV1";
31
- value: undefined;
32
- } | {
33
- tag: "accountUnsubscriptionV1";
34
- value: undefined;
35
- } | {
36
- tag: "supportFeatureRequestV1";
37
- value: {
38
- tag: "chain";
39
- value: {
40
- chainId: `0x${string}`;
41
- };
42
- };
43
- } | {
44
- tag: "supportFeatureResponseV1";
45
- value: {
46
- tag: "success";
47
- value: {
48
- tag: "chain";
49
- value: {
50
- chainId: `0x${string}`;
51
- result: boolean;
52
- };
53
- };
54
- } | {
55
- tag: "error";
56
- value: string;
57
- };
58
- } | {
59
- tag: "papiProviderSendMessageV1";
60
- value: {
61
- chainId: string;
62
- message: string;
63
- };
64
- } | {
65
- tag: "papiProviderReceiveMessageV1";
66
- value: {
67
- tag: "success";
68
- value: {
69
- chainId: string;
70
- message: string;
71
- };
72
- } | {
73
- tag: "error";
74
- value: string;
75
- };
76
- } | {
77
- tag: "signRawRequestV1";
78
- value: import("@polkadot/types/types").SignerPayloadRaw;
79
- } | {
80
- tag: "signPayloadRequestV1";
81
- value: import("@polkadot/types/types").SignerPayloadJSON;
82
- } | {
83
- tag: "signResponseV1";
84
- value: {
85
- tag: "success";
86
- value: import("@polkadot/types/types").SignerResult;
87
- } | {
88
- tag: "error";
89
- value: string;
90
- };
91
- } | {
92
- tag: "createTransactionRequestV1";
93
- value: import("./interactions/sign.js").TxPayloadV1;
94
- } | {
95
- tag: "createTransactionResponseV1";
96
- value: {
97
- tag: "success";
98
- value: `0x${string}`;
99
- } | {
100
- tag: "error";
101
- value: string;
102
- };
103
- } | {
104
- tag: "locationChangedV1";
105
- value: string;
106
- }>;
107
- export type MessageSchema = CodecType<typeof messageEncoder>;
108
- export declare const messageEncoder: import("scale-ts").Codec<{
109
- id: string;
110
- payload: {
111
- tag: "handshakeRequestV1";
112
- value: undefined;
113
- } | {
114
- tag: "handshakeResponseV1";
115
- value: {
116
- tag: "success";
117
- value: undefined;
118
- } | {
119
- tag: "error";
120
- value: string;
121
- };
122
- } | {
123
- tag: "getAccountsRequestV1";
124
- value: undefined;
125
- } | {
126
- tag: "getAccountsResponseV1";
127
- value: {
128
- tag: "success";
129
- value: import("@polkadot-api/pjs-signer").InjectedAccount[];
130
- } | {
131
- tag: "error";
132
- value: string;
133
- };
134
- } | {
135
- tag: "accountSubscriptionV1";
136
- value: undefined;
137
- } | {
138
- tag: "accountUnsubscriptionV1";
139
- value: undefined;
140
- } | {
141
- tag: "supportFeatureRequestV1";
142
- value: {
143
- tag: "chain";
144
- value: {
145
- chainId: `0x${string}`;
146
- };
147
- };
148
- } | {
149
- tag: "supportFeatureResponseV1";
150
- value: {
151
- tag: "success";
152
- value: {
153
- tag: "chain";
154
- value: {
155
- chainId: `0x${string}`;
156
- result: boolean;
157
- };
158
- };
159
- } | {
160
- tag: "error";
161
- value: string;
162
- };
163
- } | {
164
- tag: "papiProviderSendMessageV1";
165
- value: {
166
- chainId: string;
167
- message: string;
168
- };
169
- } | {
170
- tag: "papiProviderReceiveMessageV1";
171
- value: {
172
- tag: "success";
173
- value: {
174
- chainId: string;
175
- message: string;
176
- };
177
- } | {
178
- tag: "error";
179
- value: string;
180
- };
181
- } | {
182
- tag: "signRawRequestV1";
183
- value: import("@polkadot/types/types").SignerPayloadRaw;
184
- } | {
185
- tag: "signPayloadRequestV1";
186
- value: import("@polkadot/types/types").SignerPayloadJSON;
187
- } | {
188
- tag: "signResponseV1";
189
- value: {
190
- tag: "success";
191
- value: import("@polkadot/types/types").SignerResult;
192
- } | {
193
- tag: "error";
194
- value: string;
195
- };
196
- } | {
197
- tag: "createTransactionRequestV1";
198
- value: import("./interactions/sign.js").TxPayloadV1;
199
- } | {
200
- tag: "createTransactionResponseV1";
201
- value: {
202
- tag: "success";
203
- value: `0x${string}`;
204
- } | {
205
- tag: "error";
206
- value: string;
207
- };
208
- } | {
209
- tag: "locationChangedV1";
210
- value: string;
211
- };
212
- }>;
213
- export type MessageType = MessagePayloadSchema['tag'];
214
- export type PickMessagePayload<T extends MessageType> = Extract<MessagePayloadSchema, {
215
- tag: T;
216
- }>;
217
- export type PickMessagePayloadValue<T extends MessageType> = PickMessagePayload<T>['value'];
@@ -1,37 +0,0 @@
1
- import { Enum, Struct, str } from 'scale-ts';
2
- import { responseEncoder } from './commonEncoders.js';
3
- import { accountSubscriptionV1Encoder, accountUnsubscriptionV1Encoder, getAccountsRequestV1Encoder, getAccountsResponseV1Encoder, } from './interactions/accounts.js';
4
- import { supportFeatureRequestV1Encoder, supportFeatureResponseV1 } from './interactions/features.js';
5
- import { handshakeRequestV1Encoder, handshakeResponseV1Encoder } from './interactions/handshake.js';
6
- import { papiProviderReceiveMessageV1Encoder, papiProviderSendMessageV1Encoder } from './interactions/papiProvider.js';
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);
14
- }
15
- }
16
- export const messagePayloadEncoder = Enum({
17
- handshakeRequestV1: handshakeRequestV1Encoder,
18
- handshakeResponseV1: responseEncoder(handshakeResponseV1Encoder),
19
- getAccountsRequestV1: getAccountsRequestV1Encoder,
20
- getAccountsResponseV1: responseEncoder(getAccountsResponseV1Encoder),
21
- accountSubscriptionV1: accountSubscriptionV1Encoder,
22
- accountUnsubscriptionV1: accountUnsubscriptionV1Encoder,
23
- supportFeatureRequestV1: supportFeatureRequestV1Encoder,
24
- supportFeatureResponseV1: responseEncoder(supportFeatureResponseV1),
25
- papiProviderSendMessageV1: papiProviderSendMessageV1Encoder,
26
- papiProviderReceiveMessageV1: responseEncoder(papiProviderReceiveMessageV1Encoder),
27
- signRawRequestV1: signRawRequestV1Encoder,
28
- signPayloadRequestV1: signPayloadRequestV1Encoder,
29
- signResponseV1: responseEncoder(signResponseV1Encoder),
30
- createTransactionRequestV1: createTransactionRequestV1Encoder,
31
- createTransactionResponseV1: responseEncoder(createTransactionResponseV1Encoder),
32
- locationChangedV1: str,
33
- });
34
- export const messageEncoder = Struct({
35
- id: str,
36
- payload: messagePayloadEncoder,
37
- });