@novasamatech/host-api 0.9.3 → 0.10.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/hostApi.js +87 -3
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -1
- package/dist/protocol/callError.d.ts +63 -0
- package/dist/protocol/callError.js +57 -0
- package/dist/protocol/impl.d.ts +349 -54
- package/dist/protocol/impl.js +70 -10
- package/dist/protocol/messageCodec.d.ts +820 -109
- package/dist/protocol/v1/accounts.d.ts +10 -10
- package/dist/protocol/v1/accounts.js +12 -11
- package/dist/protocol/v1/chainInteraction.d.ts +44 -12
- package/dist/protocol/v1/chainInteraction.js +25 -15
- package/dist/protocol/v1/chat.d.ts +3 -3
- package/dist/protocol/v1/chat.js +5 -4
- package/dist/protocol/v1/coinPayment.d.ts +345 -0
- package/dist/protocol/v1/coinPayment.js +105 -0
- package/dist/protocol/v1/createTransaction.d.ts +9 -9
- package/dist/protocol/v1/createTransaction.js +4 -3
- package/dist/protocol/v1/deriveEntropy.d.ts +1 -1
- package/dist/protocol/v1/deriveEntropy.js +2 -2
- package/dist/protocol/v1/devicePermission.d.ts +1 -1
- package/dist/protocol/v1/devicePermission.js +3 -2
- package/dist/protocol/v1/feature.d.ts +1 -1
- package/dist/protocol/v1/feature.js +3 -2
- package/dist/protocol/v1/handshake.d.ts +1 -1
- package/dist/protocol/v1/handshake.js +3 -2
- package/dist/protocol/v1/localStorage.d.ts +10 -3
- package/dist/protocol/v1/localStorage.js +10 -4
- package/dist/protocol/v1/navigation.d.ts +1 -1
- package/dist/protocol/v1/navigation.js +3 -2
- package/dist/protocol/v1/notification.d.ts +2 -2
- package/dist/protocol/v1/notification.js +4 -3
- package/dist/protocol/v1/payments.d.ts +8 -8
- package/dist/protocol/v1/payments.js +4 -3
- package/dist/protocol/v1/preimage.d.ts +1 -1
- package/dist/protocol/v1/preimage.js +3 -2
- package/dist/protocol/v1/remotePermission.d.ts +1 -1
- package/dist/protocol/v1/remotePermission.js +3 -2
- package/dist/protocol/v1/resourceAllocation.d.ts +1 -1
- package/dist/protocol/v1/resourceAllocation.js +3 -2
- package/dist/protocol/v1/sign.d.ts +4 -4
- package/dist/protocol/v1/sign.js +6 -5
- package/dist/protocol/v1/statementStore.d.ts +3 -3
- package/dist/protocol/v1/statementStore.js +5 -4
- package/dist/protocol/v1/worker.d.ts +37 -0
- package/dist/protocol/v1/worker.js +20 -0
- package/dist/transport.js +16 -2
- package/dist/transport.spec.js +18 -0
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Status } from '@novasamatech/scale';
|
|
2
|
-
import {
|
|
2
|
+
import { bool } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericError } from '../commonCodecs.js';
|
|
4
5
|
export const DevicePermission = Status('Notifications', 'Camera', 'Microphone', 'Bluetooth', 'NFC', 'Location', 'Clipboard', 'OpenUrl', 'Biometrics');
|
|
5
6
|
export const DevicePermissionV1_request = DevicePermission;
|
|
6
|
-
export const DevicePermissionV1_response =
|
|
7
|
+
export const DevicePermissionV1_response = CallResult(bool, GenericError);
|
|
@@ -6,6 +6,6 @@ export declare const FeatureV1_request: import("scale-ts").Codec<{
|
|
|
6
6
|
tag: "Chain";
|
|
7
7
|
value: `0x${string}`;
|
|
8
8
|
}>;
|
|
9
|
-
export declare const FeatureV1_response: import("scale-ts").Codec<import("
|
|
9
|
+
export declare const FeatureV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<boolean, import("@novasamatech/scale").CodecError<{
|
|
10
10
|
reason: string;
|
|
11
11
|
}, "GenericError">>>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Enum, Hex } from '@novasamatech/scale';
|
|
2
|
-
import {
|
|
2
|
+
import { bool } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericError } from '../commonCodecs.js';
|
|
4
5
|
export const Feature = Enum({
|
|
5
6
|
Chain: Hex(),
|
|
6
7
|
});
|
|
7
8
|
export const FeatureV1_request = Feature;
|
|
8
|
-
export const FeatureV1_response =
|
|
9
|
+
export const FeatureV1_response = CallResult(bool, GenericError);
|
|
@@ -24,6 +24,6 @@ export declare const HandshakeErr: [import("scale-ts").Encoder<import("@novasama
|
|
|
24
24
|
* HandshakeV1_request = 1 - SCALE codec
|
|
25
25
|
*/
|
|
26
26
|
export declare const HandshakeV1_request: import("scale-ts").Codec<number>;
|
|
27
|
-
export declare const HandshakeV1_response: import("scale-ts").Codec<import("
|
|
27
|
+
export declare const HandshakeV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<undefined, import("@novasamatech/scale").CodecError<{
|
|
28
28
|
reason: string;
|
|
29
29
|
}, "HandshakeErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "HandshakeErr::Timeout"> | import("@novasamatech/scale").CodecError<undefined, "HandshakeErr::UnsupportedProtocolVersion">>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ErrEnum } from '@novasamatech/scale';
|
|
2
|
-
import {
|
|
2
|
+
import { _void, u8 } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericErr } from '../commonCodecs.js';
|
|
4
5
|
export const HandshakeErr = ErrEnum('HandshakeErr', {
|
|
5
6
|
Timeout: [_void, 'Handshake: timeout'],
|
|
@@ -10,4 +11,4 @@ export const HandshakeErr = ErrEnum('HandshakeErr', {
|
|
|
10
11
|
* HandshakeV1_request = 1 - SCALE codec
|
|
11
12
|
*/
|
|
12
13
|
export const HandshakeV1_request = u8;
|
|
13
|
-
export const HandshakeV1_response =
|
|
14
|
+
export const HandshakeV1_response = CallResult(_void, HandshakeErr);
|
|
@@ -22,14 +22,21 @@ export declare const StorageErr: [import("scale-ts").Encoder<import("@novasamate
|
|
|
22
22
|
export declare const StorageKey: import("scale-ts").Codec<string>;
|
|
23
23
|
export declare const StorageValue: import("@novasamatech/scale").BytesCodec<undefined>;
|
|
24
24
|
export declare const StorageReadV1_request: import("scale-ts").Codec<string>;
|
|
25
|
-
export declare const StorageReadV1_response: import("scale-ts").Codec<import("
|
|
25
|
+
export declare const StorageReadV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<Uint8Array<ArrayBufferLike> | undefined, import("@novasamatech/scale").CodecError<{
|
|
26
26
|
reason: string;
|
|
27
27
|
}, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>>;
|
|
28
28
|
export declare const StorageWriteV1_request: import("scale-ts").Codec<[string, Uint8Array<ArrayBufferLike>]>;
|
|
29
|
-
export declare const StorageWriteV1_response: import("scale-ts").Codec<import("
|
|
29
|
+
export declare const StorageWriteV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<undefined, import("@novasamatech/scale").CodecError<{
|
|
30
30
|
reason: string;
|
|
31
31
|
}, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>>;
|
|
32
32
|
export declare const StorageClearV1_request: import("scale-ts").Codec<string>;
|
|
33
|
-
export declare const StorageClearV1_response: import("scale-ts").Codec<import("
|
|
33
|
+
export declare const StorageClearV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<undefined, import("@novasamatech/scale").CodecError<{
|
|
34
34
|
reason: string;
|
|
35
35
|
}, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>>;
|
|
36
|
+
export declare const StorageSubscribeV1_start: import("scale-ts").Codec<{
|
|
37
|
+
key: string;
|
|
38
|
+
}>;
|
|
39
|
+
export declare const StorageSubscribeV1_receive: import("scale-ts").Codec<{
|
|
40
|
+
value: Uint8Array<ArrayBufferLike> | undefined;
|
|
41
|
+
}>;
|
|
42
|
+
export declare const StorageSubscribeV1_interrupt: import("scale-ts").Codec<undefined>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Bytes, ErrEnum } from '@novasamatech/scale';
|
|
2
|
-
import { Option,
|
|
2
|
+
import { Option, Struct, Tuple, _void, str } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericErr } from '../commonCodecs.js';
|
|
4
5
|
// common structures
|
|
5
6
|
export const StorageErr = ErrEnum('StorageErr', {
|
|
@@ -10,8 +11,13 @@ export const StorageKey = str;
|
|
|
10
11
|
export const StorageValue = Bytes();
|
|
11
12
|
// actions
|
|
12
13
|
export const StorageReadV1_request = StorageKey;
|
|
13
|
-
export const StorageReadV1_response =
|
|
14
|
+
export const StorageReadV1_response = CallResult(Option(StorageValue), StorageErr);
|
|
14
15
|
export const StorageWriteV1_request = Tuple(StorageKey, StorageValue);
|
|
15
|
-
export const StorageWriteV1_response =
|
|
16
|
+
export const StorageWriteV1_response = CallResult(_void, StorageErr);
|
|
16
17
|
export const StorageClearV1_request = StorageKey;
|
|
17
|
-
export const StorageClearV1_response =
|
|
18
|
+
export const StorageClearV1_response = CallResult(_void, StorageErr);
|
|
19
|
+
// Emits the current value first, then one item per later write or clear of the
|
|
20
|
+
// key. `None` represents a cleared or absent key.
|
|
21
|
+
export const StorageSubscribeV1_start = Struct({ key: StorageKey });
|
|
22
|
+
export const StorageSubscribeV1_receive = Struct({ value: Option(StorageValue) });
|
|
23
|
+
export const StorageSubscribeV1_interrupt = _void;
|
|
@@ -20,6 +20,6 @@ export declare const NavigateToErr: [import("scale-ts").Encoder<import("@novasam
|
|
|
20
20
|
}, "NavigateToErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "NavigateToErr::PermissionDenied">;
|
|
21
21
|
};
|
|
22
22
|
export declare const NavigateToV1_request: import("scale-ts").Codec<string>;
|
|
23
|
-
export declare const NavigateToV1_response: import("scale-ts").Codec<import("
|
|
23
|
+
export declare const NavigateToV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<undefined, import("@novasamatech/scale").CodecError<{
|
|
24
24
|
reason: string;
|
|
25
25
|
}, "NavigateToErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "NavigateToErr::PermissionDenied">>>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ErrEnum } from '@novasamatech/scale';
|
|
2
|
-
import {
|
|
2
|
+
import { _void, str } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericErr } from '../commonCodecs.js';
|
|
4
5
|
export const NavigateToErr = ErrEnum('NavigateToErr', {
|
|
5
6
|
PermissionDenied: [_void, 'Permission denied'],
|
|
6
7
|
Unknown: [GenericErr, 'Unknown error'],
|
|
7
8
|
});
|
|
8
9
|
export const NavigateToV1_request = str;
|
|
9
|
-
export const NavigateToV1_response =
|
|
10
|
+
export const NavigateToV1_response = CallResult(_void, NavigateToErr);
|
|
@@ -30,10 +30,10 @@ export declare const PushNotificationV1_request: import("scale-ts").Codec<{
|
|
|
30
30
|
deeplink: string | undefined;
|
|
31
31
|
scheduledAt: bigint | undefined;
|
|
32
32
|
}>;
|
|
33
|
-
export declare const PushNotificationV1_response: import("scale-ts").Codec<import("
|
|
33
|
+
export declare const PushNotificationV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<number, import("@novasamatech/scale").CodecError<{
|
|
34
34
|
reason: string;
|
|
35
35
|
}, "PushNotificationError::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PushNotificationError::ScheduleLimitReached">>>;
|
|
36
36
|
export declare const PushNotificationCancelV1_request: import("scale-ts").Codec<number>;
|
|
37
|
-
export declare const PushNotificationCancelV1_response: import("scale-ts").Codec<import("
|
|
37
|
+
export declare const PushNotificationCancelV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<undefined, import("@novasamatech/scale").CodecError<{
|
|
38
38
|
reason: string;
|
|
39
39
|
}, "GenericError">>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ErrEnum } from '@novasamatech/scale';
|
|
2
|
-
import { Option,
|
|
2
|
+
import { Option, Struct, _void, str, u32, u64 } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericErr, GenericError } from '../commonCodecs.js';
|
|
4
5
|
export const NotificationId = u32;
|
|
5
6
|
export const PushNotification = Struct({
|
|
@@ -12,6 +13,6 @@ export const PushNotificationError = ErrEnum('PushNotificationError', {
|
|
|
12
13
|
Unknown: [GenericErr, 'Unknown error'],
|
|
13
14
|
});
|
|
14
15
|
export const PushNotificationV1_request = PushNotification;
|
|
15
|
-
export const PushNotificationV1_response =
|
|
16
|
+
export const PushNotificationV1_response = CallResult(NotificationId, PushNotificationError);
|
|
16
17
|
export const PushNotificationCancelV1_request = NotificationId;
|
|
17
|
-
export const PushNotificationCancelV1_response =
|
|
18
|
+
export const PushNotificationCancelV1_response = CallResult(_void, GenericError);
|
|
@@ -24,14 +24,14 @@ export declare const PaymentReceipt: import("scale-ts").Codec<{
|
|
|
24
24
|
id: string;
|
|
25
25
|
}>;
|
|
26
26
|
export declare const PaymentStatus: import("scale-ts").Codec<{
|
|
27
|
+
tag: "Failed";
|
|
28
|
+
value: string;
|
|
29
|
+
} | {
|
|
27
30
|
tag: "Processing";
|
|
28
31
|
value: undefined;
|
|
29
32
|
} | {
|
|
30
33
|
tag: "Completed";
|
|
31
34
|
value: undefined;
|
|
32
|
-
} | {
|
|
33
|
-
tag: "Failed";
|
|
34
|
-
value: string;
|
|
35
35
|
}>;
|
|
36
36
|
export declare const PaymentBalanceErr: [import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<{
|
|
37
37
|
reason: string;
|
|
@@ -182,7 +182,7 @@ export declare const PaymentTopUpV1_request: import("scale-ts").Codec<{
|
|
|
182
182
|
value: Uint8Array<ArrayBufferLike>[];
|
|
183
183
|
};
|
|
184
184
|
}>;
|
|
185
|
-
export declare const PaymentTopUpV1_response: import("scale-ts").Codec<import("
|
|
185
|
+
export declare const PaymentTopUpV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<undefined, import("@novasamatech/scale").CodecError<{
|
|
186
186
|
reason: string;
|
|
187
187
|
}, "PaymentTopUpErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PaymentTopUpErr::InsufficientFunds"> | import("@novasamatech/scale").CodecError<undefined, "PaymentTopUpErr::InvalidSource"> | import("@novasamatech/scale").CodecError<{
|
|
188
188
|
credited: bigint;
|
|
@@ -192,21 +192,21 @@ export declare const PaymentRequestV1_request: import("scale-ts").Codec<{
|
|
|
192
192
|
amount: bigint;
|
|
193
193
|
destination: Uint8Array<ArrayBufferLike>;
|
|
194
194
|
}>;
|
|
195
|
-
export declare const PaymentRequestV1_response: import("scale-ts").Codec<import("
|
|
195
|
+
export declare const PaymentRequestV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<{
|
|
196
196
|
id: string;
|
|
197
197
|
}, import("@novasamatech/scale").CodecError<undefined, "PaymentRequestErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
198
198
|
reason: string;
|
|
199
199
|
}, "PaymentRequestErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PaymentRequestErr::InsufficientBalance">>>;
|
|
200
200
|
export declare const PaymentStatusSubscribeV1_start: import("scale-ts").Codec<string>;
|
|
201
201
|
export declare const PaymentStatusSubscribeV1_receive: import("scale-ts").Codec<{
|
|
202
|
+
tag: "Failed";
|
|
203
|
+
value: string;
|
|
204
|
+
} | {
|
|
202
205
|
tag: "Processing";
|
|
203
206
|
value: undefined;
|
|
204
207
|
} | {
|
|
205
208
|
tag: "Completed";
|
|
206
209
|
value: undefined;
|
|
207
|
-
} | {
|
|
208
|
-
tag: "Failed";
|
|
209
|
-
value: string;
|
|
210
210
|
}>;
|
|
211
211
|
export declare const PaymentStatusSubscribeV1_interrupt: [import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<{
|
|
212
212
|
reason: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Bytes, Enum, ErrEnum } from '@novasamatech/scale';
|
|
2
|
-
import { Option,
|
|
2
|
+
import { Option, Struct, Vector, _void, str, u128, u32 } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericErr } from '../commonCodecs.js';
|
|
4
5
|
import { DerivationIndex } from './accounts.js';
|
|
5
6
|
// common types
|
|
@@ -60,14 +61,14 @@ export const PaymentTopUpV1_request = Struct({
|
|
|
60
61
|
amount: u128,
|
|
61
62
|
source: PaymentTopUpSource,
|
|
62
63
|
});
|
|
63
|
-
export const PaymentTopUpV1_response =
|
|
64
|
+
export const PaymentTopUpV1_response = CallResult(_void, PaymentTopUpErr);
|
|
64
65
|
// host_payment_request
|
|
65
66
|
export const PaymentRequestV1_request = Struct({
|
|
66
67
|
from: Option(CoinPaymentPurseId),
|
|
67
68
|
amount: u128,
|
|
68
69
|
destination: Bytes(32),
|
|
69
70
|
});
|
|
70
|
-
export const PaymentRequestV1_response =
|
|
71
|
+
export const PaymentRequestV1_response = CallResult(PaymentReceipt, PaymentRequestErr);
|
|
71
72
|
// host_payment_status_subscribe
|
|
72
73
|
export const PaymentStatusSubscribeV1_start = PaymentId;
|
|
73
74
|
export const PaymentStatusSubscribeV1_receive = PaymentStatus;
|
|
@@ -24,6 +24,6 @@ export declare const PreimageSubmitErr: [import("scale-ts").Encoder<import("@nov
|
|
|
24
24
|
}, "PreimageSubmitErr::Unknown">;
|
|
25
25
|
};
|
|
26
26
|
export declare const PreimageSubmitV1_request: import("@novasamatech/scale").BytesCodec<undefined>;
|
|
27
|
-
export declare const PreimageSubmitV1_response: import("scale-ts").Codec<import("
|
|
27
|
+
export declare const PreimageSubmitV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<`0x${string}`, import("@novasamatech/scale").CodecError<{
|
|
28
28
|
reason: string;
|
|
29
29
|
}, "PreimageSubmitErr::Unknown">>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Bytes, ErrEnum, Hex, Nullable } from '@novasamatech/scale';
|
|
2
|
-
import {
|
|
2
|
+
import { _void } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericErr } from '../commonCodecs.js';
|
|
4
5
|
export const PreimageKey = Hex();
|
|
5
6
|
export const PreimageValue = Bytes();
|
|
@@ -10,4 +11,4 @@ export const PreimageSubmitErr = ErrEnum('PreimageSubmitErr', {
|
|
|
10
11
|
Unknown: [GenericErr, 'Unknown error'],
|
|
11
12
|
});
|
|
12
13
|
export const PreimageSubmitV1_request = PreimageValue;
|
|
13
|
-
export const PreimageSubmitV1_response =
|
|
14
|
+
export const PreimageSubmitV1_response = CallResult(PreimageKey, PreimageSubmitErr);
|
|
@@ -30,6 +30,6 @@ export declare const RemotePermissionV1_request: import("scale-ts").Codec<{
|
|
|
30
30
|
tag: "StatementSubmit";
|
|
31
31
|
value: undefined;
|
|
32
32
|
}>;
|
|
33
|
-
export declare const RemotePermissionV1_response: import("scale-ts").Codec<import("
|
|
33
|
+
export declare const RemotePermissionV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<boolean, import("@novasamatech/scale").CodecError<{
|
|
34
34
|
reason: string;
|
|
35
35
|
}, "GenericError">>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Enum } from '@novasamatech/scale';
|
|
2
|
-
import {
|
|
2
|
+
import { Vector, _void, bool, str } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericError } from '../commonCodecs.js';
|
|
4
5
|
export const RemotePermission = Enum({
|
|
5
6
|
Remote: Vector(str),
|
|
@@ -9,4 +10,4 @@ export const RemotePermission = Enum({
|
|
|
9
10
|
StatementSubmit: _void,
|
|
10
11
|
});
|
|
11
12
|
export const RemotePermissionV1_request = RemotePermission;
|
|
12
|
-
export const RemotePermissionV1_response =
|
|
13
|
+
export const RemotePermissionV1_response = CallResult(bool, GenericError);
|
|
@@ -66,7 +66,7 @@ export declare const RequestResourceAllocationV1_request: import("scale-ts").Cod
|
|
|
66
66
|
tag: "AutoSigning";
|
|
67
67
|
value: undefined;
|
|
68
68
|
})[]>;
|
|
69
|
-
export declare const RequestResourceAllocationV1_response: import("scale-ts").Codec<import("
|
|
69
|
+
export declare const RequestResourceAllocationV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<({
|
|
70
70
|
tag: "Rejected";
|
|
71
71
|
value: undefined;
|
|
72
72
|
} | {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Enum, ErrEnum } from '@novasamatech/scale';
|
|
2
|
-
import {
|
|
2
|
+
import { Vector, _void } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericErr } from '../commonCodecs.js';
|
|
4
5
|
import { DerivationIndex } from './accounts.js';
|
|
5
6
|
// resources requested by a product
|
|
@@ -22,4 +23,4 @@ export const ResourceAllocationErr = ErrEnum('ResourceAllocationErr', {
|
|
|
22
23
|
});
|
|
23
24
|
// host_request_resource_allocation
|
|
24
25
|
export const RequestResourceAllocationV1_request = Vector(AllocatableResource);
|
|
25
|
-
export const RequestResourceAllocationV1_response =
|
|
26
|
+
export const RequestResourceAllocationV1_response = CallResult(Vector(AllocationOutcome), ResourceAllocationErr);
|
|
@@ -74,7 +74,7 @@ export declare const SignRawV1_request: import("scale-ts").Codec<{
|
|
|
74
74
|
value: string;
|
|
75
75
|
};
|
|
76
76
|
}>;
|
|
77
|
-
export declare const SignRawV1_response: import("scale-ts").Codec<import("
|
|
77
|
+
export declare const SignRawV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<{
|
|
78
78
|
signature: `0x${string}`;
|
|
79
79
|
signedTransaction: `0x${string}` | undefined;
|
|
80
80
|
}, import("@novasamatech/scale").CodecError<undefined, "SigningErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
@@ -90,7 +90,7 @@ export declare const SignRawWithLegacyAccountV1_request: import("scale-ts").Code
|
|
|
90
90
|
value: string;
|
|
91
91
|
};
|
|
92
92
|
}>;
|
|
93
|
-
export declare const SignRawWithLegacyAccountV1_response: import("scale-ts").Codec<import("
|
|
93
|
+
export declare const SignRawWithLegacyAccountV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<{
|
|
94
94
|
signature: `0x${string}`;
|
|
95
95
|
signedTransaction: `0x${string}` | undefined;
|
|
96
96
|
}, import("@novasamatech/scale").CodecError<undefined, "SigningErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
@@ -168,7 +168,7 @@ export declare const SignPayloadV1_request: import("scale-ts").Codec<{
|
|
|
168
168
|
withSignedTransaction: boolean | undefined;
|
|
169
169
|
};
|
|
170
170
|
}>;
|
|
171
|
-
export declare const SignPayloadV1_response: import("scale-ts").Codec<import("
|
|
171
|
+
export declare const SignPayloadV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<{
|
|
172
172
|
signature: `0x${string}`;
|
|
173
173
|
signedTransaction: `0x${string}` | undefined;
|
|
174
174
|
}, import("@novasamatech/scale").CodecError<undefined, "SigningErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
@@ -194,7 +194,7 @@ export declare const SignPayloadWithLegacyAccountV1_request: import("scale-ts").
|
|
|
194
194
|
withSignedTransaction: boolean | undefined;
|
|
195
195
|
};
|
|
196
196
|
}>;
|
|
197
|
-
export declare const SignPayloadWithLegacyAccountV1_response: import("scale-ts").Codec<import("
|
|
197
|
+
export declare const SignPayloadWithLegacyAccountV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<{
|
|
198
198
|
signature: `0x${string}`;
|
|
199
199
|
signedTransaction: `0x${string}` | undefined;
|
|
200
200
|
}, import("@novasamatech/scale").CodecError<undefined, "SigningErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
package/dist/protocol/v1/sign.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Bytes, Enum, ErrEnum, Hex } from '@novasamatech/scale';
|
|
2
|
-
import { Option,
|
|
2
|
+
import { Option, Struct, Vector, _void, bool, str, u32 } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericErr } from '../commonCodecs.js';
|
|
4
5
|
import { ProductAccountId } from './accounts.js';
|
|
5
6
|
// common structures
|
|
@@ -27,9 +28,9 @@ export const SigningRawPayloadWithoutAccount = Struct({
|
|
|
27
28
|
payload: RawPayload,
|
|
28
29
|
});
|
|
29
30
|
export const SignRawV1_request = SigningRawPayload;
|
|
30
|
-
export const SignRawV1_response =
|
|
31
|
+
export const SignRawV1_response = CallResult(SigningResult, SigningErr);
|
|
31
32
|
export const SignRawWithLegacyAccountV1_request = SigningRawPayloadWithoutAccount;
|
|
32
|
-
export const SignRawWithLegacyAccountV1_response =
|
|
33
|
+
export const SignRawWithLegacyAccountV1_response = CallResult(SigningResult, SigningErr);
|
|
33
34
|
// sign payload
|
|
34
35
|
const SigningPayloadPayload = Struct({
|
|
35
36
|
blockHash: Hex(),
|
|
@@ -57,6 +58,6 @@ export const SigningPayloadWithoutAccount = Struct({
|
|
|
57
58
|
payload: SigningPayloadPayload,
|
|
58
59
|
});
|
|
59
60
|
export const SignPayloadV1_request = SigningPayload;
|
|
60
|
-
export const SignPayloadV1_response =
|
|
61
|
+
export const SignPayloadV1_response = CallResult(SigningResult, SigningErr);
|
|
61
62
|
export const SignPayloadWithLegacyAccountV1_request = SigningPayloadWithoutAccount;
|
|
62
|
-
export const SignPayloadWithLegacyAccountV1_response =
|
|
63
|
+
export const SignPayloadWithLegacyAccountV1_response = CallResult(SigningResult, SigningErr);
|
|
@@ -215,7 +215,7 @@ export declare const StatementStoreCreateProofV1_request: import("scale-ts").Cod
|
|
|
215
215
|
topics: Uint8Array<ArrayBufferLike>[];
|
|
216
216
|
data: Uint8Array<ArrayBufferLike> | undefined;
|
|
217
217
|
}]>;
|
|
218
|
-
export declare const StatementStoreCreateProofV1_response: import("scale-ts").Codec<import("
|
|
218
|
+
export declare const StatementStoreCreateProofV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<{
|
|
219
219
|
tag: "Sr25519";
|
|
220
220
|
value: {
|
|
221
221
|
signature: Uint8Array<ArrayBufferLike>;
|
|
@@ -276,7 +276,7 @@ export declare const StatementStoreCreateProofAuthorizedV1_request: import("scal
|
|
|
276
276
|
topics: Uint8Array<ArrayBufferLike>[];
|
|
277
277
|
data: Uint8Array<ArrayBufferLike> | undefined;
|
|
278
278
|
}>;
|
|
279
|
-
export declare const StatementStoreCreateProofAuthorizedV1_response: import("scale-ts").Codec<import("
|
|
279
|
+
export declare const StatementStoreCreateProofAuthorizedV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<{
|
|
280
280
|
tag: "Sr25519";
|
|
281
281
|
value: {
|
|
282
282
|
signature: Uint8Array<ArrayBufferLike>;
|
|
@@ -337,6 +337,6 @@ export declare const StatementStoreSubmitV1_request: import("scale-ts").Codec<{
|
|
|
337
337
|
topics: Uint8Array<ArrayBufferLike>[];
|
|
338
338
|
data: Uint8Array<ArrayBufferLike> | undefined;
|
|
339
339
|
}>;
|
|
340
|
-
export declare const StatementStoreSubmitV1_response: import("scale-ts").Codec<import("
|
|
340
|
+
export declare const StatementStoreSubmitV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<undefined, import("@novasamatech/scale").CodecError<{
|
|
341
341
|
reason: string;
|
|
342
342
|
}, "GenericError">>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Bytes, Enum, ErrEnum } from '@novasamatech/scale';
|
|
2
|
-
import { Option,
|
|
2
|
+
import { Option, Struct, Tuple, Vector, _void, bool, u64 } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
3
4
|
import { GenericErr, GenericError } from '../commonCodecs.js';
|
|
4
5
|
import { ProductAccountId } from './accounts.js';
|
|
5
6
|
// structs definition
|
|
@@ -65,10 +66,10 @@ export const StatementProofErr = ErrEnum('StatementProofErr', {
|
|
|
65
66
|
Unknown: [GenericErr, 'StatementProof: unknown error'],
|
|
66
67
|
});
|
|
67
68
|
export const StatementStoreCreateProofV1_request = Tuple(ProductAccountId, Statement);
|
|
68
|
-
export const StatementStoreCreateProofV1_response =
|
|
69
|
+
export const StatementStoreCreateProofV1_response = CallResult(StatementProof, StatementProofErr);
|
|
69
70
|
// creating proof using a host-internal allowance account (no product account required)
|
|
70
71
|
export const StatementStoreCreateProofAuthorizedV1_request = Statement;
|
|
71
|
-
export const StatementStoreCreateProofAuthorizedV1_response =
|
|
72
|
+
export const StatementStoreCreateProofAuthorizedV1_response = CallResult(StatementProof, StatementProofErr);
|
|
72
73
|
// submit
|
|
73
74
|
export const StatementStoreSubmitV1_request = SignedStatement;
|
|
74
|
-
export const StatementStoreSubmitV1_response =
|
|
75
|
+
export const StatementStoreSubmitV1_response = CallResult(_void, GenericError);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const WorkerErr: [import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<{
|
|
2
|
+
reason: string;
|
|
3
|
+
}, "WorkerErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "WorkerErr::TooManyOpen">>, import("scale-ts").Decoder<import("@novasamatech/scale").CodecError<{
|
|
4
|
+
reason: string;
|
|
5
|
+
}, "WorkerErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "WorkerErr::TooManyOpen">>] & {
|
|
6
|
+
enc: import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<{
|
|
7
|
+
reason: string;
|
|
8
|
+
}, "WorkerErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "WorkerErr::TooManyOpen">>;
|
|
9
|
+
dec: import("scale-ts").Decoder<import("@novasamatech/scale").CodecError<{
|
|
10
|
+
reason: string;
|
|
11
|
+
}, "WorkerErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "WorkerErr::TooManyOpen">>;
|
|
12
|
+
} & {
|
|
13
|
+
readonly TooManyOpen: import("@novasamatech/scale").ErrCodec<undefined, "WorkerErr::TooManyOpen">;
|
|
14
|
+
readonly Unknown: import("@novasamatech/scale").ErrCodec<{
|
|
15
|
+
reason: string;
|
|
16
|
+
}, "WorkerErr::Unknown">;
|
|
17
|
+
} & {
|
|
18
|
+
[Symbol.hasInstance](v: unknown): v is import("@novasamatech/scale").CodecError<{
|
|
19
|
+
reason: string;
|
|
20
|
+
}, "WorkerErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "WorkerErr::TooManyOpen">;
|
|
21
|
+
};
|
|
22
|
+
/** Host-assigned pending-operation id, unique per product. */
|
|
23
|
+
export declare const OperationId: import("scale-ts").Codec<number>;
|
|
24
|
+
export declare const WorkerBeginOperationV1_request: import("scale-ts").Codec<{
|
|
25
|
+
label: string | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const WorkerBeginOperationV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<{
|
|
28
|
+
id: number;
|
|
29
|
+
}, import("@novasamatech/scale").CodecError<{
|
|
30
|
+
reason: string;
|
|
31
|
+
}, "WorkerErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "WorkerErr::TooManyOpen">>>;
|
|
32
|
+
export declare const WorkerEndOperationV1_request: import("scale-ts").Codec<{
|
|
33
|
+
id: number;
|
|
34
|
+
}>;
|
|
35
|
+
export declare const WorkerEndOperationV1_response: import("scale-ts").Codec<import("../callError.js").CallResultValue<undefined, import("@novasamatech/scale").CodecError<{
|
|
36
|
+
reason: string;
|
|
37
|
+
}, "WorkerErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "WorkerErr::TooManyOpen">>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ErrEnum } from '@novasamatech/scale';
|
|
2
|
+
import { Option, Struct, _void, str, u32 } from 'scale-ts';
|
|
3
|
+
import { CallResult } from '../callError.js';
|
|
4
|
+
import { GenericErr } from '../commonCodecs.js';
|
|
5
|
+
// common structures
|
|
6
|
+
export const WorkerErr = ErrEnum('WorkerErr', {
|
|
7
|
+
TooManyOpen: [_void, 'Too many open operations'],
|
|
8
|
+
Unknown: [GenericErr, 'Unknown worker operation error'],
|
|
9
|
+
});
|
|
10
|
+
/** Host-assigned pending-operation id, unique per product. */
|
|
11
|
+
export const OperationId = u32;
|
|
12
|
+
// actions
|
|
13
|
+
// The worker keeps itself alive by holding an open operation; the host keeps
|
|
14
|
+
// the product's worker running while it has at least one open operation. The
|
|
15
|
+
// request carries an optional label for host logs and UI.
|
|
16
|
+
export const WorkerBeginOperationV1_request = Struct({ label: Option(str) });
|
|
17
|
+
export const WorkerBeginOperationV1_response = CallResult(Struct({ id: OperationId }), WorkerErr);
|
|
18
|
+
// Idempotent: ending an unknown or already-ended id still succeeds.
|
|
19
|
+
export const WorkerEndOperationV1_request = Struct({ id: OperationId });
|
|
20
|
+
export const WorkerEndOperationV1_response = CallResult(_void, WorkerErr);
|
package/dist/transport.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { enumValue, isEnumVariant, resultErr, resultOk, toHex } from '@novasamatech/scale';
|
|
2
2
|
import { createNanoEvents } from 'nanoevents';
|
|
3
3
|
import { HANDSHAKE_INTERVAL, HANDSHAKE_TIMEOUT, SCALE_CODEC_PROTOCOL_ID } from './constants.js';
|
|
4
|
-
import { composeAction, createRequestId, delay, promiseWithResolvers } from './helpers.js';
|
|
4
|
+
import { composeAction, createRequestId, delay, extractErrorMessage, promiseWithResolvers } from './helpers.js';
|
|
5
|
+
import { CALL_ERROR_FAILURE } from './protocol/callError.js';
|
|
5
6
|
import { Message, MessagePayload } from './protocol/messageCodec.js';
|
|
6
7
|
import { HandshakeErr } from './protocol/v1/handshake.js';
|
|
7
8
|
function isConnected(status) {
|
|
@@ -194,6 +195,14 @@ export function createTransport(provider) {
|
|
|
194
195
|
transport.postMessage(requestId, responseMessage);
|
|
195
196
|
}, (error) => {
|
|
196
197
|
provider.logger.error(`handleRequest: handler for "${method}" rejected`, error);
|
|
198
|
+
// Answer a transport-level CallError so the caller sees a failed
|
|
199
|
+
// request rather than a hung promise. Domain errors are the
|
|
200
|
+
// handler's job; this is the fallback when the handler itself threw.
|
|
201
|
+
const failure = enumValue('v1', {
|
|
202
|
+
[CALL_ERROR_FAILURE]: { tag: 'HostFailure', value: { reason: extractErrorMessage(error) } },
|
|
203
|
+
});
|
|
204
|
+
const responseMessage = enumValue(responseAction, failure);
|
|
205
|
+
transport.postMessage(requestId, responseMessage);
|
|
197
206
|
});
|
|
198
207
|
});
|
|
199
208
|
},
|
|
@@ -238,7 +247,12 @@ export function createTransport(provider) {
|
|
|
238
247
|
const subscription = activeSubscriptions.get(subscriptionKey);
|
|
239
248
|
if (subscription) {
|
|
240
249
|
for (const listener of subscription.listeners) {
|
|
241
|
-
|
|
250
|
+
try {
|
|
251
|
+
listener.call(data.value);
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
254
|
+
provider.logger.error(`subscription "${method}" listener threw`, e);
|
|
255
|
+
}
|
|
242
256
|
}
|
|
243
257
|
}
|
|
244
258
|
}
|
package/dist/transport.spec.js
CHANGED
|
@@ -57,6 +57,24 @@ describe('transport', () => {
|
|
|
57
57
|
expect(s1Handler).toHaveBeenCalledTimes(1);
|
|
58
58
|
expect(s2Handler).toHaveBeenCalledTimes(2);
|
|
59
59
|
});
|
|
60
|
+
it('isolates a throwing subscriber so siblings on the same subscription still receive', () => {
|
|
61
|
+
const providers = createProviders();
|
|
62
|
+
const events = createNanoEvents();
|
|
63
|
+
const host = createTransport(providers.host);
|
|
64
|
+
const sdk = createTransport(providers.sdk);
|
|
65
|
+
host.handleSubscription('host_account_connection_status_subscribe', (_, send) => events.on('push', () => send({ tag: 'v1', value: 'connected' })));
|
|
66
|
+
const throwing = vi.fn(() => {
|
|
67
|
+
throw new Error('subscriber boom');
|
|
68
|
+
});
|
|
69
|
+
const healthy = vi.fn();
|
|
70
|
+
sdk.subscribe('host_account_connection_status_subscribe', { tag: 'v1', value: undefined }, throwing);
|
|
71
|
+
sdk.subscribe('host_account_connection_status_subscribe', { tag: 'v1', value: undefined }, healthy);
|
|
72
|
+
// A throw in the first subscriber must neither escape the dispatch nor
|
|
73
|
+
// starve the second subscriber on the same subscription.
|
|
74
|
+
expect(() => events.emit('push')).not.toThrow();
|
|
75
|
+
expect(throwing).toHaveBeenCalledTimes(1);
|
|
76
|
+
expect(healthy).toHaveBeenCalledTimes(1);
|
|
77
|
+
});
|
|
60
78
|
});
|
|
61
79
|
describe('debug hook', () => {
|
|
62
80
|
it('emits outgoing events when postMessage is called and still delivers the message', () => {
|
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.10.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.
|
|
25
|
+
"@novasamatech/scale": "0.10.0",
|
|
26
26
|
"nanoevents": "10.0.0",
|
|
27
27
|
"nanoid": "6.0.0",
|
|
28
28
|
"neverthrow": "^8.2.0",
|