@novasamatech/host-api 0.7.2 → 0.7.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/dist/protocol/impl.d.ts +8 -8
- package/dist/protocol/impl.js +8 -8
- package/dist/protocol/messageCodec.d.ts +24 -24
- package/dist/protocol/v1/notification.d.ts +1 -1
- package/dist/transport.js +37 -6
- package/dist/types.d.ts +6 -0
- package/dist/types.js +1 -1
- package/package.json +2 -2
package/dist/protocol/impl.d.ts
CHANGED
|
@@ -133,9 +133,9 @@ export declare const hostApiProtocol: {
|
|
|
133
133
|
reason: string;
|
|
134
134
|
}, "CreateTransactionErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "CreateTransactionErr::PermissionDenied"> | import("@novasamatech/scale").CodecError<undefined, "CreateTransactionErr::FailedToDecode"> | import("@novasamatech/scale").CodecError<string, "CreateTransactionErr::NotSupported">>>];
|
|
135
135
|
}>;
|
|
136
|
-
readonly
|
|
136
|
+
readonly host_sign_raw_with_legacy_account: VersionedProtocolRequest<{
|
|
137
137
|
readonly v1: [Codec<{
|
|
138
|
-
|
|
138
|
+
signer: string;
|
|
139
139
|
payload: {
|
|
140
140
|
tag: "Bytes";
|
|
141
141
|
value: Uint8Array<ArrayBufferLike>;
|
|
@@ -150,9 +150,9 @@ export declare const hostApiProtocol: {
|
|
|
150
150
|
reason: string;
|
|
151
151
|
}, "SigningErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::PermissionDenied"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::FailedToDecode">>>];
|
|
152
152
|
}>;
|
|
153
|
-
readonly
|
|
153
|
+
readonly host_sign_payload_with_legacy_account: VersionedProtocolRequest<{
|
|
154
154
|
readonly v1: [Codec<{
|
|
155
|
-
|
|
155
|
+
signer: string;
|
|
156
156
|
payload: {
|
|
157
157
|
blockHash: `0x${string}`;
|
|
158
158
|
blockNumber: `0x${string}`;
|
|
@@ -751,9 +751,9 @@ export declare const hostApiProtocol: {
|
|
|
751
751
|
reason: string;
|
|
752
752
|
}, "LoginErr::Unknown">>>];
|
|
753
753
|
}>;
|
|
754
|
-
readonly
|
|
754
|
+
readonly host_sign_raw: VersionedProtocolRequest<{
|
|
755
755
|
readonly v1: [Codec<{
|
|
756
|
-
|
|
756
|
+
account: [string, number];
|
|
757
757
|
payload: {
|
|
758
758
|
tag: "Bytes";
|
|
759
759
|
value: Uint8Array<ArrayBufferLike>;
|
|
@@ -768,9 +768,9 @@ export declare const hostApiProtocol: {
|
|
|
768
768
|
reason: string;
|
|
769
769
|
}, "SigningErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::PermissionDenied"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::FailedToDecode">>>];
|
|
770
770
|
}>;
|
|
771
|
-
readonly
|
|
771
|
+
readonly host_sign_payload: VersionedProtocolRequest<{
|
|
772
772
|
readonly v1: [Codec<{
|
|
773
|
-
|
|
773
|
+
account: [string, number];
|
|
774
774
|
payload: {
|
|
775
775
|
blockHash: `0x${string}`;
|
|
776
776
|
blockNumber: `0x${string}`;
|
package/dist/protocol/impl.js
CHANGED
|
@@ -84,11 +84,11 @@ export const hostApiProtocol = {
|
|
|
84
84
|
host_create_transaction_with_legacy_account: versionedRequest({
|
|
85
85
|
v1: [CreateTransactionWithLegacyAccountV1_request, CreateTransactionWithLegacyAccountV1_response],
|
|
86
86
|
}),
|
|
87
|
-
|
|
88
|
-
v1: [
|
|
87
|
+
host_sign_raw_with_legacy_account: versionedRequest({
|
|
88
|
+
v1: [SignRawWithLegacyAccountV1_request, SignRawWithLegacyAccountV1_response],
|
|
89
89
|
}),
|
|
90
|
-
|
|
91
|
-
v1: [
|
|
90
|
+
host_sign_payload_with_legacy_account: versionedRequest({
|
|
91
|
+
v1: [SignPayloadWithLegacyAccountV1_request, SignPayloadWithLegacyAccountV1_response],
|
|
92
92
|
}),
|
|
93
93
|
host_chat_create_room: versionedRequest({
|
|
94
94
|
v1: [ChatCreateRoomV1_request, ChatCreateRoomV1_response],
|
|
@@ -186,11 +186,11 @@ export const hostApiProtocol = {
|
|
|
186
186
|
host_request_login: versionedRequest({
|
|
187
187
|
v1: [RequestLoginV1_request, RequestLoginV1_response],
|
|
188
188
|
}),
|
|
189
|
-
|
|
190
|
-
v1: [
|
|
189
|
+
host_sign_raw: versionedRequest({
|
|
190
|
+
v1: [SignRawV1_request, SignRawV1_response],
|
|
191
191
|
}),
|
|
192
|
-
|
|
193
|
-
v1: [
|
|
192
|
+
host_sign_payload: versionedRequest({
|
|
193
|
+
v1: [SignPayloadV1_request, SignPayloadV1_response],
|
|
194
194
|
}),
|
|
195
195
|
host_payment_balance_subscribe: versionedSubscription({
|
|
196
196
|
v1: [PaymentBalanceSubscribeV1_start, PaymentBalanceSubscribeV1_receive, PaymentBalanceSubscribeV1_interrupt],
|
|
@@ -141,9 +141,9 @@ export declare const MessagePayload: EnumCodec<Record<"host_handshake_request",
|
|
|
141
141
|
readonly v1: Codec<import("scale-ts").ResultPayload<Uint8Array<ArrayBufferLike>, import("@novasamatech/scale").CodecError<undefined, "CreateTransactionErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
142
142
|
reason: string;
|
|
143
143
|
}, "CreateTransactionErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "CreateTransactionErr::PermissionDenied"> | import("@novasamatech/scale").CodecError<undefined, "CreateTransactionErr::FailedToDecode"> | import("@novasamatech/scale").CodecError<string, "CreateTransactionErr::NotSupported">>>;
|
|
144
|
-
}>> & Record<"
|
|
144
|
+
}>> & Record<"host_sign_raw_with_legacy_account_request", EnumCodec<{
|
|
145
145
|
readonly v1: Codec<{
|
|
146
|
-
|
|
146
|
+
signer: string;
|
|
147
147
|
payload: {
|
|
148
148
|
tag: "Bytes";
|
|
149
149
|
value: Uint8Array<ArrayBufferLike>;
|
|
@@ -152,16 +152,16 @@ export declare const MessagePayload: EnumCodec<Record<"host_handshake_request",
|
|
|
152
152
|
value: string;
|
|
153
153
|
};
|
|
154
154
|
}>;
|
|
155
|
-
}>> & Record<"
|
|
155
|
+
}>> & Record<"host_sign_raw_with_legacy_account_response", EnumCodec<{
|
|
156
156
|
readonly v1: Codec<import("scale-ts").ResultPayload<{
|
|
157
157
|
signature: `0x${string}`;
|
|
158
158
|
signedTransaction: `0x${string}` | undefined;
|
|
159
159
|
}, import("@novasamatech/scale").CodecError<undefined, "SigningErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
160
160
|
reason: string;
|
|
161
161
|
}, "SigningErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::PermissionDenied"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::FailedToDecode">>>;
|
|
162
|
-
}>> & Record<"
|
|
162
|
+
}>> & Record<"host_sign_payload_with_legacy_account_request", EnumCodec<{
|
|
163
163
|
readonly v1: Codec<{
|
|
164
|
-
|
|
164
|
+
signer: string;
|
|
165
165
|
payload: {
|
|
166
166
|
blockHash: `0x${string}`;
|
|
167
167
|
blockNumber: `0x${string}`;
|
|
@@ -180,7 +180,7 @@ export declare const MessagePayload: EnumCodec<Record<"host_handshake_request",
|
|
|
180
180
|
withSignedTransaction: boolean | undefined;
|
|
181
181
|
};
|
|
182
182
|
}>;
|
|
183
|
-
}>> & Record<"
|
|
183
|
+
}>> & Record<"host_sign_payload_with_legacy_account_response", EnumCodec<{
|
|
184
184
|
readonly v1: Codec<import("scale-ts").ResultPayload<{
|
|
185
185
|
signature: `0x${string}`;
|
|
186
186
|
signedTransaction: `0x${string}` | undefined;
|
|
@@ -807,9 +807,9 @@ export declare const MessagePayload: EnumCodec<Record<"host_handshake_request",
|
|
|
807
807
|
readonly v1: Codec<import("scale-ts").ResultPayload<"success" | "alreadyConnected" | "rejected", import("@novasamatech/scale").CodecError<{
|
|
808
808
|
reason: string;
|
|
809
809
|
}, "LoginErr::Unknown">>>;
|
|
810
|
-
}>> & Record<"
|
|
810
|
+
}>> & Record<"host_sign_raw_request", EnumCodec<{
|
|
811
811
|
readonly v1: Codec<{
|
|
812
|
-
|
|
812
|
+
account: [string, number];
|
|
813
813
|
payload: {
|
|
814
814
|
tag: "Bytes";
|
|
815
815
|
value: Uint8Array<ArrayBufferLike>;
|
|
@@ -818,16 +818,16 @@ export declare const MessagePayload: EnumCodec<Record<"host_handshake_request",
|
|
|
818
818
|
value: string;
|
|
819
819
|
};
|
|
820
820
|
}>;
|
|
821
|
-
}>> & Record<"
|
|
821
|
+
}>> & Record<"host_sign_raw_response", EnumCodec<{
|
|
822
822
|
readonly v1: Codec<import("scale-ts").ResultPayload<{
|
|
823
823
|
signature: `0x${string}`;
|
|
824
824
|
signedTransaction: `0x${string}` | undefined;
|
|
825
825
|
}, import("@novasamatech/scale").CodecError<undefined, "SigningErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
826
826
|
reason: string;
|
|
827
827
|
}, "SigningErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::PermissionDenied"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::FailedToDecode">>>;
|
|
828
|
-
}>> & Record<"
|
|
828
|
+
}>> & Record<"host_sign_payload_request", EnumCodec<{
|
|
829
829
|
readonly v1: Codec<{
|
|
830
|
-
|
|
830
|
+
account: [string, number];
|
|
831
831
|
payload: {
|
|
832
832
|
blockHash: `0x${string}`;
|
|
833
833
|
blockNumber: `0x${string}`;
|
|
@@ -846,7 +846,7 @@ export declare const MessagePayload: EnumCodec<Record<"host_handshake_request",
|
|
|
846
846
|
withSignedTransaction: boolean | undefined;
|
|
847
847
|
};
|
|
848
848
|
}>;
|
|
849
|
-
}>> & Record<"
|
|
849
|
+
}>> & Record<"host_sign_payload_response", EnumCodec<{
|
|
850
850
|
readonly v1: Codec<import("scale-ts").ResultPayload<{
|
|
851
851
|
signature: `0x${string}`;
|
|
852
852
|
signedTransaction: `0x${string}` | undefined;
|
|
@@ -1205,11 +1205,11 @@ export declare const Message: Codec<{
|
|
|
1205
1205
|
}, "CreateTransactionErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "CreateTransactionErr::PermissionDenied"> | import("@novasamatech/scale").CodecError<undefined, "CreateTransactionErr::FailedToDecode"> | import("@novasamatech/scale").CodecError<string, "CreateTransactionErr::NotSupported">>;
|
|
1206
1206
|
};
|
|
1207
1207
|
} | {
|
|
1208
|
-
tag: "
|
|
1208
|
+
tag: "host_sign_raw_with_legacy_account_request";
|
|
1209
1209
|
value: {
|
|
1210
1210
|
tag: "v1";
|
|
1211
1211
|
value: {
|
|
1212
|
-
|
|
1212
|
+
signer: string;
|
|
1213
1213
|
payload: {
|
|
1214
1214
|
tag: "Bytes";
|
|
1215
1215
|
value: Uint8Array<ArrayBufferLike>;
|
|
@@ -1220,7 +1220,7 @@ export declare const Message: Codec<{
|
|
|
1220
1220
|
};
|
|
1221
1221
|
};
|
|
1222
1222
|
} | {
|
|
1223
|
-
tag: "
|
|
1223
|
+
tag: "host_sign_raw_with_legacy_account_response";
|
|
1224
1224
|
value: {
|
|
1225
1225
|
tag: "v1";
|
|
1226
1226
|
value: import("scale-ts").ResultPayload<{
|
|
@@ -1231,11 +1231,11 @@ export declare const Message: Codec<{
|
|
|
1231
1231
|
}, "SigningErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::PermissionDenied"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::FailedToDecode">>;
|
|
1232
1232
|
};
|
|
1233
1233
|
} | {
|
|
1234
|
-
tag: "
|
|
1234
|
+
tag: "host_sign_payload_with_legacy_account_request";
|
|
1235
1235
|
value: {
|
|
1236
1236
|
tag: "v1";
|
|
1237
1237
|
value: {
|
|
1238
|
-
|
|
1238
|
+
signer: string;
|
|
1239
1239
|
payload: {
|
|
1240
1240
|
blockHash: `0x${string}`;
|
|
1241
1241
|
blockNumber: `0x${string}`;
|
|
@@ -1256,7 +1256,7 @@ export declare const Message: Codec<{
|
|
|
1256
1256
|
};
|
|
1257
1257
|
};
|
|
1258
1258
|
} | {
|
|
1259
|
-
tag: "
|
|
1259
|
+
tag: "host_sign_payload_with_legacy_account_response";
|
|
1260
1260
|
value: {
|
|
1261
1261
|
tag: "v1";
|
|
1262
1262
|
value: import("scale-ts").ResultPayload<{
|
|
@@ -2183,11 +2183,11 @@ export declare const Message: Codec<{
|
|
|
2183
2183
|
}, "LoginErr::Unknown">>;
|
|
2184
2184
|
};
|
|
2185
2185
|
} | {
|
|
2186
|
-
tag: "
|
|
2186
|
+
tag: "host_sign_raw_request";
|
|
2187
2187
|
value: {
|
|
2188
2188
|
tag: "v1";
|
|
2189
2189
|
value: {
|
|
2190
|
-
|
|
2190
|
+
account: [string, number];
|
|
2191
2191
|
payload: {
|
|
2192
2192
|
tag: "Bytes";
|
|
2193
2193
|
value: Uint8Array<ArrayBufferLike>;
|
|
@@ -2198,7 +2198,7 @@ export declare const Message: Codec<{
|
|
|
2198
2198
|
};
|
|
2199
2199
|
};
|
|
2200
2200
|
} | {
|
|
2201
|
-
tag: "
|
|
2201
|
+
tag: "host_sign_raw_response";
|
|
2202
2202
|
value: {
|
|
2203
2203
|
tag: "v1";
|
|
2204
2204
|
value: import("scale-ts").ResultPayload<{
|
|
@@ -2209,11 +2209,11 @@ export declare const Message: Codec<{
|
|
|
2209
2209
|
}, "SigningErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::PermissionDenied"> | import("@novasamatech/scale").CodecError<undefined, "SigningErr::FailedToDecode">>;
|
|
2210
2210
|
};
|
|
2211
2211
|
} | {
|
|
2212
|
-
tag: "
|
|
2212
|
+
tag: "host_sign_payload_request";
|
|
2213
2213
|
value: {
|
|
2214
2214
|
tag: "v1";
|
|
2215
2215
|
value: {
|
|
2216
|
-
|
|
2216
|
+
account: [string, number];
|
|
2217
2217
|
payload: {
|
|
2218
2218
|
blockHash: `0x${string}`;
|
|
2219
2219
|
blockNumber: `0x${string}`;
|
|
@@ -2234,7 +2234,7 @@ export declare const Message: Codec<{
|
|
|
2234
2234
|
};
|
|
2235
2235
|
};
|
|
2236
2236
|
} | {
|
|
2237
|
-
tag: "
|
|
2237
|
+
tag: "host_sign_payload_response";
|
|
2238
2238
|
value: {
|
|
2239
2239
|
tag: "v1";
|
|
2240
2240
|
value: import("scale-ts").ResultPayload<{
|
|
@@ -6,6 +6,6 @@ export declare const PushNotificationV1_request: import("scale-ts").Codec<{
|
|
|
6
6
|
text: string;
|
|
7
7
|
deeplink: string | undefined;
|
|
8
8
|
}>;
|
|
9
|
-
export declare const PushNotificationV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, import("
|
|
9
|
+
export declare const PushNotificationV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
|
|
10
10
|
reason: string;
|
|
11
11
|
}, "GenericError">>>;
|
package/dist/transport.js
CHANGED
|
@@ -10,6 +10,38 @@ function isConnected(status) {
|
|
|
10
10
|
function getSubscriptionKey(method, payload) {
|
|
11
11
|
return `${method}_${toHex(MessagePayload.enc(payload))}`;
|
|
12
12
|
}
|
|
13
|
+
function createMessageProvider(provider) {
|
|
14
|
+
const subscribers = new Set();
|
|
15
|
+
let unsubscribeProvider = null;
|
|
16
|
+
return {
|
|
17
|
+
postMessage(message) {
|
|
18
|
+
provider.postMessage(Message.enc(message));
|
|
19
|
+
},
|
|
20
|
+
subscribe(fn) {
|
|
21
|
+
if (subscribers.size === 0) {
|
|
22
|
+
unsubscribeProvider = provider.subscribe(payload => {
|
|
23
|
+
try {
|
|
24
|
+
const message = Message.dec(payload);
|
|
25
|
+
for (const subscriber of subscribers) {
|
|
26
|
+
subscriber(message);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
provider.logger.error('Transport error', e);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
subscribers.add(fn);
|
|
35
|
+
return () => {
|
|
36
|
+
subscribers.delete(fn);
|
|
37
|
+
if (subscribers.size === 0 && unsubscribeProvider) {
|
|
38
|
+
unsubscribeProvider();
|
|
39
|
+
unsubscribeProvider = null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
13
45
|
export function createTransport(provider) {
|
|
14
46
|
let codecVersion = JAM_CODEC_PROTOCOL_ID;
|
|
15
47
|
const handshakeAbortController = new AbortController();
|
|
@@ -44,6 +76,7 @@ export function createTransport(provider) {
|
|
|
44
76
|
throwIfIncorrectEnvironment();
|
|
45
77
|
throwIfInvalidCodecVersion();
|
|
46
78
|
}
|
|
79
|
+
const messageProvider = createMessageProvider(provider);
|
|
47
80
|
// subscriptions management (multiplexing)
|
|
48
81
|
const activeSubscriptions = new Map();
|
|
49
82
|
const transport = {
|
|
@@ -253,15 +286,13 @@ export function createTransport(provider) {
|
|
|
253
286
|
},
|
|
254
287
|
postMessage(requestId, payload) {
|
|
255
288
|
checks();
|
|
256
|
-
|
|
257
|
-
provider.postMessage(encoded);
|
|
289
|
+
messageProvider.postMessage({ requestId, payload });
|
|
258
290
|
},
|
|
259
291
|
listenMessages(action, callback, onError) {
|
|
260
|
-
return
|
|
292
|
+
return messageProvider.subscribe(message => {
|
|
261
293
|
try {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
callback(result.requestId, result.payload);
|
|
294
|
+
if (isEnumVariant(message.payload, action)) {
|
|
295
|
+
callback(message.requestId, message.payload);
|
|
265
296
|
}
|
|
266
297
|
}
|
|
267
298
|
catch (e) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { CodecType } from 'scale-ts';
|
|
1
2
|
import type { HostApiProtocol } from './protocol/impl.js';
|
|
2
3
|
import type { ComposeMessageAction, MessageAction, MessagePayloadSchema, PickMessagePayload, PickMessagePayloadValue } from './protocol/messageCodec.js';
|
|
4
|
+
import { Message } from './protocol/messageCodec.js';
|
|
3
5
|
import type { Provider } from './provider.js';
|
|
4
6
|
export type HostApiMethod = keyof HostApiProtocol;
|
|
5
7
|
export type Logger = Record<'info' | 'warn' | 'error' | 'log', (...args: unknown[]) => void> & {
|
|
@@ -13,6 +15,10 @@ export type Subscription<InterruptPayload = unknown> = {
|
|
|
13
15
|
onInterrupt(callback: (payload: InterruptPayload) => void): VoidFunction;
|
|
14
16
|
};
|
|
15
17
|
export type SubscriptionFor<Method extends HostApiMethod> = Subscription<PickMessagePayloadValue<ComposeMessageAction<Method, 'interrupt'>>>;
|
|
18
|
+
export type MessageProvider = {
|
|
19
|
+
postMessage(message: CodecType<typeof Message>): void;
|
|
20
|
+
subscribe(fn: (message: CodecType<typeof Message>) => void): VoidFunction;
|
|
21
|
+
};
|
|
16
22
|
export type Transport = {
|
|
17
23
|
readonly provider: Provider;
|
|
18
24
|
isCorrectEnvironment(): boolean;
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import { Message } from './protocol/messageCodec.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/host-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.4-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
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@novasamatech/scale": "0.7.
|
|
25
|
+
"@novasamatech/scale": "0.7.4-0",
|
|
26
26
|
"nanoevents": "9.1.0",
|
|
27
27
|
"nanoid": "5.1.9",
|
|
28
28
|
"neverthrow": "^8.2.0",
|