@novasamatech/host-api 0.4.0 → 0.5.0-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/dist/commonEncoders.d.ts +0 -7
- package/dist/commonEncoders.js +2 -8
- package/dist/createTransport.d.ts +1 -1
- package/dist/createTransport.js +7 -10
- package/dist/index.d.ts +7 -7
- package/dist/index.js +6 -6
- package/dist/interactions/accounts.js +1 -1
- package/dist/interactions/features.js +1 -1
- package/dist/interactions/sign.d.ts +1 -1
- package/dist/interactions/sign.js +5 -13
- package/dist/logger.d.ts +1 -1
- package/dist/messageEncoder.d.ts +3 -3
- package/dist/messageEncoder.js +6 -6
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
package/dist/commonEncoders.d.ts
CHANGED
|
@@ -7,10 +7,3 @@ export declare function responseEncoder<T>(codec: Codec<T>): Codec<{
|
|
|
7
7
|
tag: "error";
|
|
8
8
|
value: string;
|
|
9
9
|
}>;
|
|
10
|
-
export declare function createNullableEncoder<T>(codec: Codec<T>): Codec<{
|
|
11
|
-
tag: "value";
|
|
12
|
-
value: T;
|
|
13
|
-
} | {
|
|
14
|
-
tag: "null";
|
|
15
|
-
value: undefined;
|
|
16
|
-
}>;
|
package/dist/commonEncoders.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fromHex, toHex } from '@polkadot-api/utils';
|
|
2
|
-
import { Bytes, Enum,
|
|
3
|
-
import { createTransportEncoder } from './createTransportEncoder';
|
|
2
|
+
import { Bytes, Enum, str } from 'scale-ts';
|
|
3
|
+
import { createTransportEncoder } from './createTransportEncoder.js';
|
|
4
4
|
export const hexEncoder = createTransportEncoder({
|
|
5
5
|
codec: Bytes(),
|
|
6
6
|
from: v => toHex(v),
|
|
@@ -12,9 +12,3 @@ export function responseEncoder(codec) {
|
|
|
12
12
|
error: str,
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
-
export function createNullableEncoder(codec) {
|
|
16
|
-
return Enum({
|
|
17
|
-
value: codec,
|
|
18
|
-
null: _void,
|
|
19
|
-
});
|
|
20
|
-
}
|
package/dist/createTransport.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createNanoEvents } from 'nanoevents';
|
|
2
2
|
import { nanoid } from 'nanoid';
|
|
3
|
-
import { HANDSHAKE_INTERVAL } from './constants';
|
|
4
|
-
import { delay, promiseWithResolvers } from './helpers';
|
|
5
|
-
import { messageEncoder } from './messageEncoder';
|
|
3
|
+
import { HANDSHAKE_INTERVAL } from './constants.js';
|
|
4
|
+
import { delay, promiseWithResolvers } from './helpers.js';
|
|
5
|
+
import { messageEncoder } from './messageEncoder.js';
|
|
6
6
|
export function createTransport(provider, params) {
|
|
7
7
|
const handshakeTimeout = params?.handshakeTimeout ?? Number.POSITIVE_INFINITY;
|
|
8
8
|
const handshakeAbortController = new AbortController();
|
|
@@ -10,7 +10,7 @@ export function createTransport(provider, params) {
|
|
|
10
10
|
let connectionStatusResolved = false;
|
|
11
11
|
let connectionStatus = 'disconnected';
|
|
12
12
|
let disposed = false;
|
|
13
|
-
const events =
|
|
13
|
+
const events = createNanoEvents();
|
|
14
14
|
events.on('connectionStatus', value => {
|
|
15
15
|
connectionStatus = value;
|
|
16
16
|
});
|
|
@@ -159,17 +159,14 @@ export function createTransport(provider, params) {
|
|
|
159
159
|
});
|
|
160
160
|
},
|
|
161
161
|
onConnectionStatusChange(callback) {
|
|
162
|
-
events.on('connectionStatus', callback);
|
|
163
162
|
callback(connectionStatus);
|
|
164
|
-
return ()
|
|
165
|
-
events.off('connectionStatus', callback);
|
|
166
|
-
};
|
|
163
|
+
return events.on('connectionStatus', callback);
|
|
167
164
|
},
|
|
168
165
|
dispose() {
|
|
169
166
|
disposed = true;
|
|
170
167
|
provider.dispose();
|
|
171
168
|
changeConnectionStatus('disconnected');
|
|
172
|
-
events.
|
|
169
|
+
events.events = {};
|
|
173
170
|
handshakeAbortController.abort('Transport disposed');
|
|
174
171
|
},
|
|
175
172
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { messageEncoder, unwrapResponseOrThrow } from './messageEncoder';
|
|
2
|
-
export { type MessagePayloadSchema, type MessageType, type PickMessagePayload, type PickMessagePayloadValue, } from './messageEncoder';
|
|
3
|
-
export { createTransport } from './createTransport';
|
|
4
|
-
export type { ConnectionStatus, HexString, Logger, Transport, TransportProvider } from './types';
|
|
5
|
-
export { createDefaultLogger } from './logger';
|
|
6
|
-
export { type InjectedAccountSchema } from './interactions/accounts';
|
|
7
|
-
export { type TxPayloadV1 } from './interactions/sign';
|
|
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';
|
|
5
|
+
export { createDefaultLogger } from './logger.js';
|
|
6
|
+
export { type InjectedAccountSchema } from './interactions/accounts.js';
|
|
7
|
+
export { type TxPayloadV1 } from './interactions/sign.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { messageEncoder, unwrapResponseOrThrow } from './messageEncoder';
|
|
2
|
-
export {} from './messageEncoder';
|
|
3
|
-
export { createTransport } from './createTransport';
|
|
4
|
-
export { createDefaultLogger } from './logger';
|
|
5
|
-
export {} from './interactions/accounts';
|
|
6
|
-
export {} from './interactions/sign';
|
|
1
|
+
export { messageEncoder, unwrapResponseOrThrow } from './messageEncoder.js';
|
|
2
|
+
export {} from './messageEncoder.js';
|
|
3
|
+
export { createTransport } from './createTransport.js';
|
|
4
|
+
export { createDefaultLogger } from './logger.js';
|
|
5
|
+
export {} from './interactions/accounts.js';
|
|
6
|
+
export {} from './interactions/sign.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Enum, Option, Struct, Vector, _void, str } from 'scale-ts';
|
|
2
|
-
import { createTransportEncoder } from '../createTransportEncoder';
|
|
2
|
+
import { createTransportEncoder } from '../createTransportEncoder.js';
|
|
3
3
|
const keypairCodec = Enum({
|
|
4
4
|
ed25519: _void,
|
|
5
5
|
sr25519: _void,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SignerPayloadJSON, SignerPayloadRaw, SignerResult } from '@polkadot/types/types';
|
|
2
2
|
import type { CodecType } from 'scale-ts';
|
|
3
|
-
import type { HexString } from '../types';
|
|
3
|
+
import type { HexString } from '../types.js';
|
|
4
4
|
/**
|
|
5
5
|
* @see {import('@polkadot/types/types').SignerPayloadRaw}
|
|
6
6
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Bytes, Enum, Option, Struct, Vector, _void, bool, str, u16, u32 } from 'scale-ts';
|
|
2
|
-
import {
|
|
3
|
-
import { createTransportEncoder } from '../createTransportEncoder';
|
|
2
|
+
import { hexEncoder } from '../commonEncoders.js';
|
|
3
|
+
import { createTransportEncoder } from '../createTransportEncoder.js';
|
|
4
4
|
const signRawRequestCodec = Struct({
|
|
5
5
|
address: str,
|
|
6
6
|
data: str,
|
|
@@ -132,7 +132,7 @@ export const signResponseV1Encoder = createTransportEncoder({
|
|
|
132
132
|
});
|
|
133
133
|
const createTransactionRequestCodec = Struct({
|
|
134
134
|
version: u16,
|
|
135
|
-
signer:
|
|
135
|
+
signer: Option(str),
|
|
136
136
|
callData: hexEncoder,
|
|
137
137
|
extensions: Vector(Struct({
|
|
138
138
|
id: str,
|
|
@@ -155,21 +155,13 @@ export const createTransactionRequestV1Encoder = createTransportEncoder({
|
|
|
155
155
|
}
|
|
156
156
|
return {
|
|
157
157
|
version,
|
|
158
|
-
signer: signer
|
|
158
|
+
signer: signer ?? null,
|
|
159
159
|
...rest,
|
|
160
160
|
};
|
|
161
161
|
},
|
|
162
162
|
to({ signer, ...rest }) {
|
|
163
163
|
return {
|
|
164
|
-
signer:
|
|
165
|
-
? {
|
|
166
|
-
tag: 'value',
|
|
167
|
-
value: signer,
|
|
168
|
-
}
|
|
169
|
-
: {
|
|
170
|
-
tag: 'null',
|
|
171
|
-
value: undefined,
|
|
172
|
-
},
|
|
164
|
+
signer: signer ?? undefined,
|
|
173
165
|
...rest,
|
|
174
166
|
};
|
|
175
167
|
},
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Logger } from './types';
|
|
1
|
+
import type { Logger } from './types.js';
|
|
2
2
|
export declare function createDefaultLogger(): Logger;
|
package/dist/messageEncoder.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CodecType } from 'scale-ts';
|
|
2
|
-
import { responseEncoder } from './commonEncoders';
|
|
2
|
+
import { responseEncoder } from './commonEncoders.js';
|
|
3
3
|
export declare function unwrapResponseOrThrow<T>(response: CodecType<ReturnType<typeof responseEncoder<T>>>): T;
|
|
4
4
|
export type MessagePayloadSchema = CodecType<typeof messagePayloadEncoder>;
|
|
5
5
|
export declare const messagePayloadEncoder: import("scale-ts").Codec<{
|
|
@@ -90,7 +90,7 @@ export declare const messagePayloadEncoder: import("scale-ts").Codec<{
|
|
|
90
90
|
};
|
|
91
91
|
} | {
|
|
92
92
|
tag: "createTransactionRequestV1";
|
|
93
|
-
value: import(".").TxPayloadV1;
|
|
93
|
+
value: import("./interactions/sign.js").TxPayloadV1;
|
|
94
94
|
} | {
|
|
95
95
|
tag: "createTransactionResponseV1";
|
|
96
96
|
value: {
|
|
@@ -195,7 +195,7 @@ export declare const messageEncoder: import("scale-ts").Codec<{
|
|
|
195
195
|
};
|
|
196
196
|
} | {
|
|
197
197
|
tag: "createTransactionRequestV1";
|
|
198
|
-
value: import(".").TxPayloadV1;
|
|
198
|
+
value: import("./interactions/sign.js").TxPayloadV1;
|
|
199
199
|
} | {
|
|
200
200
|
tag: "createTransactionResponseV1";
|
|
201
201
|
value: {
|
package/dist/messageEncoder.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Enum, Struct, str } from 'scale-ts';
|
|
2
|
-
import { responseEncoder } from './commonEncoders';
|
|
3
|
-
import { accountSubscriptionV1Encoder, accountUnsubscriptionV1Encoder, getAccountsRequestV1Encoder, getAccountsResponseV1Encoder, } from './interactions/accounts';
|
|
4
|
-
import { supportFeatureRequestV1Encoder, supportFeatureResponseV1 } from './interactions/features';
|
|
5
|
-
import { handshakeRequestV1Encoder, handshakeResponseV1Encoder } from './interactions/handshake';
|
|
6
|
-
import { papiProviderReceiveMessageV1Encoder, papiProviderSendMessageV1Encoder } from './interactions/papiProvider';
|
|
7
|
-
import { createTransactionRequestV1Encoder, createTransactionResponseV1Encoder, signPayloadRequestV1Encoder, signRawRequestV1Encoder, signResponseV1Encoder, } from './interactions/sign';
|
|
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
8
|
export function unwrapResponseOrThrow(response) {
|
|
9
9
|
if (response.tag === 'success') {
|
|
10
10
|
return response.value;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MessagePayloadSchema, MessageType, PickMessagePayload, PickMessagePayloadValue } from './messageEncoder';
|
|
1
|
+
import type { MessagePayloadSchema, MessageType, PickMessagePayload, PickMessagePayloadValue } from './messageEncoder.js';
|
|
2
2
|
export type HexString = `0x${string}`;
|
|
3
3
|
export type Logger = Record<'info' | 'warn' | 'error' | 'log', (...args: unknown[]) => void>;
|
|
4
4
|
export type TransportProvider = {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/host-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0-0",
|
|
5
5
|
"description": "Host API: transport implementation for host - product integration.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
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"
|
|
28
28
|
},
|