@novasamatech/host-api 0.7.9-3 → 0.7.9-5
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 +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/protocol/impl.d.ts +8 -2
- package/dist/protocol/impl.js +4 -1
- package/dist/protocol/messageCodec.d.ts +26 -4
- package/dist/protocol/v1/notification.d.ts +29 -1
- package/dist/protocol/v1/notification.js +12 -3
- package/package.json +2 -2
- package/dist/protocol/commonCodecs.spec.d.ts +0 -1
- package/dist/protocol/commonCodecs.spec.js +0 -72
- package/dist/protocol/types.d.ts +0 -1
- package/dist/protocol/types.js +0 -1
- package/dist/protocol/v1/devicePermission.spec.d.ts +0 -1
- package/dist/protocol/v1/devicePermission.spec.js +0 -60
- package/dist/protocol/v1/jsonRpc.d.ts +0 -7
- package/dist/protocol/v1/jsonRpc.js +0 -7
- package/dist/protocol/v1/permission.d.ts +0 -50
- package/dist/protocol/v1/permission.js +0 -19
- package/dist/protocol/v1/remotePermission.spec.d.ts +0 -1
- package/dist/protocol/v1/remotePermission.spec.js +0 -65
- package/dist/protocol/v1/storage.d.ts +0 -31
- package/dist/protocol/v1/storage.js +0 -17
package/dist/hostApi.js
CHANGED
|
@@ -8,6 +8,7 @@ import { DeriveEntropyErr } from './protocol/v1/deriveEntropy.js';
|
|
|
8
8
|
import { HandshakeErr } from './protocol/v1/handshake.js';
|
|
9
9
|
import { StorageErr } from './protocol/v1/localStorage.js';
|
|
10
10
|
import { NavigateToErr } from './protocol/v1/navigation.js';
|
|
11
|
+
import { PushNotificationError } from './protocol/v1/notification.js';
|
|
11
12
|
import { PaymentRequestErr, PaymentTopUpErr } from './protocol/v1/payments.js';
|
|
12
13
|
import { PreimageSubmitErr } from './protocol/v1/preimage.js';
|
|
13
14
|
import { ResourceAllocationErr } from './protocol/v1/resourceAllocation.js';
|
|
@@ -44,6 +45,12 @@ export function createHostApi(transport) {
|
|
|
44
45
|
},
|
|
45
46
|
pushNotification(payload) {
|
|
46
47
|
return makeRequest(transport.request('host_push_notification', payload), reason => ({
|
|
48
|
+
tag: payload.tag,
|
|
49
|
+
value: new PushNotificationError.Unknown({ reason }),
|
|
50
|
+
}));
|
|
51
|
+
},
|
|
52
|
+
pushNotificationCancel(payload) {
|
|
53
|
+
return makeRequest(transport.request('host_push_notification_cancel', payload), reason => ({
|
|
47
54
|
tag: payload.tag,
|
|
48
55
|
value: new GenericError({ reason }),
|
|
49
56
|
}));
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export { SignedStatement, SignedStatementsPage, Statement, StatementProofErr, To
|
|
|
21
21
|
export { StorageErr } from './protocol/v1/localStorage.js';
|
|
22
22
|
export { DevicePermission } from './protocol/v1/devicePermission.js';
|
|
23
23
|
export { RemotePermission } from './protocol/v1/remotePermission.js';
|
|
24
|
-
export { PushNotification } from './protocol/v1/notification.js';
|
|
24
|
+
export { NotificationId, PushNotification, PushNotificationError } from './protocol/v1/notification.js';
|
|
25
25
|
export { NavigateToErr } from './protocol/v1/navigation.js';
|
|
26
26
|
export { PreimageKey, PreimageSubmitErr, PreimageValue } from './protocol/v1/preimage.js';
|
|
27
27
|
export { AllocatableResource, AllocationOutcome, ResourceAllocationErr } from './protocol/v1/resourceAllocation.js';
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ export { SignedStatement, SignedStatementsPage, Statement, StatementProofErr, To
|
|
|
16
16
|
export { StorageErr } from './protocol/v1/localStorage.js';
|
|
17
17
|
export { DevicePermission } from './protocol/v1/devicePermission.js';
|
|
18
18
|
export { RemotePermission } from './protocol/v1/remotePermission.js';
|
|
19
|
-
export { PushNotification } from './protocol/v1/notification.js';
|
|
19
|
+
export { NotificationId, PushNotification, PushNotificationError } from './protocol/v1/notification.js';
|
|
20
20
|
export { NavigateToErr } from './protocol/v1/navigation.js';
|
|
21
21
|
export { PreimageKey, PreimageSubmitErr, PreimageValue } from './protocol/v1/preimage.js';
|
|
22
22
|
export { AllocatableResource, AllocationOutcome, ResourceAllocationErr } from './protocol/v1/resourceAllocation.js';
|
package/dist/protocol/impl.d.ts
CHANGED
|
@@ -36,9 +36,10 @@ export declare const hostApiProtocol: {
|
|
|
36
36
|
readonly v1: [Codec<{
|
|
37
37
|
text: string;
|
|
38
38
|
deeplink: string | undefined;
|
|
39
|
-
|
|
39
|
+
scheduledAt: bigint | undefined;
|
|
40
|
+
}>, Codec<import("scale-ts").ResultPayload<number, import("@novasamatech/scale").CodecError<{
|
|
40
41
|
reason: string;
|
|
41
|
-
}, "
|
|
42
|
+
}, "PushNotificationError::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PushNotificationError::ScheduleLimitReached">>>];
|
|
42
43
|
}>;
|
|
43
44
|
readonly host_navigate_to: VersionedProtocolRequest<{
|
|
44
45
|
readonly v1: [Codec<string>, Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
|
|
@@ -982,5 +983,10 @@ export declare const hostApiProtocol: {
|
|
|
982
983
|
reason: string;
|
|
983
984
|
}, "StatementProofErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StatementProofErr::UnableToSign"> | import("@novasamatech/scale").CodecError<undefined, "StatementProofErr::UnknownAccount">>>];
|
|
984
985
|
}>;
|
|
986
|
+
readonly host_push_notification_cancel: VersionedProtocolRequest<{
|
|
987
|
+
readonly v1: [Codec<number>, Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
|
|
988
|
+
reason: string;
|
|
989
|
+
}, "GenericError">>>];
|
|
990
|
+
}>;
|
|
985
991
|
};
|
|
986
992
|
export {};
|
package/dist/protocol/impl.js
CHANGED
|
@@ -10,7 +10,7 @@ import { FeatureV1_request, FeatureV1_response } from './v1/feature.js';
|
|
|
10
10
|
import { HandshakeV1_request, HandshakeV1_response } from './v1/handshake.js';
|
|
11
11
|
import { StorageClearV1_request, StorageClearV1_response, StorageReadV1_request, StorageReadV1_response, StorageWriteV1_request, StorageWriteV1_response, } from './v1/localStorage.js';
|
|
12
12
|
import { NavigateToV1_request, NavigateToV1_response } from './v1/navigation.js';
|
|
13
|
-
import { PushNotificationV1_request, PushNotificationV1_response } from './v1/notification.js';
|
|
13
|
+
import { PushNotificationCancelV1_request, PushNotificationCancelV1_response, PushNotificationV1_request, PushNotificationV1_response, } from './v1/notification.js';
|
|
14
14
|
import { PaymentBalanceSubscribeV1_interrupt, PaymentBalanceSubscribeV1_receive, PaymentBalanceSubscribeV1_start, PaymentRequestV1_request, PaymentRequestV1_response, PaymentStatusSubscribeV1_interrupt, PaymentStatusSubscribeV1_receive, PaymentStatusSubscribeV1_start, PaymentTopUpV1_request, PaymentTopUpV1_response, } from './v1/payments.js';
|
|
15
15
|
import { PreimageLookupSubscribeV1_interrupt, PreimageLookupSubscribeV1_receive, PreimageLookupSubscribeV1_start, PreimageSubmitV1_request, PreimageSubmitV1_response, } from './v1/preimage.js';
|
|
16
16
|
import { RemotePermissionV1_request, RemotePermissionV1_response } from './v1/remotePermission.js';
|
|
@@ -211,4 +211,7 @@ export const hostApiProtocol = {
|
|
|
211
211
|
remote_statement_store_create_proof_authorized: versionedRequest({
|
|
212
212
|
v1: [StatementStoreCreateProofAuthorizedV1_request, StatementStoreCreateProofAuthorizedV1_response],
|
|
213
213
|
}),
|
|
214
|
+
host_push_notification_cancel: versionedRequest({
|
|
215
|
+
v1: [PushNotificationCancelV1_request, PushNotificationCancelV1_response],
|
|
216
|
+
}),
|
|
214
217
|
};
|
|
@@ -28,11 +28,12 @@ export declare const MessagePayload: EnumCodec<Record<"host_handshake_request",
|
|
|
28
28
|
readonly v1: Codec<{
|
|
29
29
|
text: string;
|
|
30
30
|
deeplink: string | undefined;
|
|
31
|
+
scheduledAt: bigint | undefined;
|
|
31
32
|
}>;
|
|
32
33
|
}>> & Record<"host_push_notification_response", EnumCodec<{
|
|
33
|
-
readonly v1: Codec<import("scale-ts").ResultPayload<
|
|
34
|
+
readonly v1: Codec<import("scale-ts").ResultPayload<number, import("@novasamatech/scale").CodecError<{
|
|
34
35
|
reason: string;
|
|
35
|
-
}, "
|
|
36
|
+
}, "PushNotificationError::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PushNotificationError::ScheduleLimitReached">>>;
|
|
36
37
|
}>> & Record<"host_navigate_to_request", EnumCodec<{
|
|
37
38
|
readonly v1: Codec<string>;
|
|
38
39
|
}>> & Record<"host_navigate_to_response", EnumCodec<{
|
|
@@ -1050,6 +1051,12 @@ export declare const MessagePayload: EnumCodec<Record<"host_handshake_request",
|
|
|
1050
1051
|
}, import("@novasamatech/scale").CodecError<{
|
|
1051
1052
|
reason: string;
|
|
1052
1053
|
}, "StatementProofErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StatementProofErr::UnableToSign"> | import("@novasamatech/scale").CodecError<undefined, "StatementProofErr::UnknownAccount">>>;
|
|
1054
|
+
}>> & Record<"host_push_notification_cancel_request", EnumCodec<{
|
|
1055
|
+
readonly v1: Codec<number>;
|
|
1056
|
+
}>> & Record<"host_push_notification_cancel_response", EnumCodec<{
|
|
1057
|
+
readonly v1: Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
|
|
1058
|
+
reason: string;
|
|
1059
|
+
}, "GenericError">>>;
|
|
1053
1060
|
}>>>;
|
|
1054
1061
|
export declare const Message: Codec<{
|
|
1055
1062
|
requestId: string;
|
|
@@ -1091,15 +1098,16 @@ export declare const Message: Codec<{
|
|
|
1091
1098
|
value: {
|
|
1092
1099
|
text: string;
|
|
1093
1100
|
deeplink: string | undefined;
|
|
1101
|
+
scheduledAt: bigint | undefined;
|
|
1094
1102
|
};
|
|
1095
1103
|
};
|
|
1096
1104
|
} | {
|
|
1097
1105
|
tag: "host_push_notification_response";
|
|
1098
1106
|
value: {
|
|
1099
1107
|
tag: "v1";
|
|
1100
|
-
value: import("scale-ts").ResultPayload<
|
|
1108
|
+
value: import("scale-ts").ResultPayload<number, import("@novasamatech/scale").CodecError<{
|
|
1101
1109
|
reason: string;
|
|
1102
|
-
}, "
|
|
1110
|
+
}, "PushNotificationError::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PushNotificationError::ScheduleLimitReached">>;
|
|
1103
1111
|
};
|
|
1104
1112
|
} | {
|
|
1105
1113
|
tag: "host_navigate_to_request";
|
|
@@ -2583,6 +2591,20 @@ export declare const Message: Codec<{
|
|
|
2583
2591
|
reason: string;
|
|
2584
2592
|
}, "StatementProofErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StatementProofErr::UnableToSign"> | import("@novasamatech/scale").CodecError<undefined, "StatementProofErr::UnknownAccount">>;
|
|
2585
2593
|
};
|
|
2594
|
+
} | {
|
|
2595
|
+
tag: "host_push_notification_cancel_request";
|
|
2596
|
+
value: {
|
|
2597
|
+
tag: "v1";
|
|
2598
|
+
value: number;
|
|
2599
|
+
};
|
|
2600
|
+
} | {
|
|
2601
|
+
tag: "host_push_notification_cancel_response";
|
|
2602
|
+
value: {
|
|
2603
|
+
tag: "v1";
|
|
2604
|
+
value: import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
|
|
2605
|
+
reason: string;
|
|
2606
|
+
}, "GenericError">>;
|
|
2607
|
+
};
|
|
2586
2608
|
};
|
|
2587
2609
|
}>;
|
|
2588
2610
|
export type MessageAction = MessagePayloadSchema['tag'];
|
|
@@ -1,11 +1,39 @@
|
|
|
1
|
+
export declare const NotificationId: import("scale-ts").Codec<number>;
|
|
1
2
|
export declare const PushNotification: import("scale-ts").Codec<{
|
|
2
3
|
text: string;
|
|
3
4
|
deeplink: string | undefined;
|
|
5
|
+
scheduledAt: bigint | undefined;
|
|
4
6
|
}>;
|
|
7
|
+
export declare const PushNotificationError: [import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<{
|
|
8
|
+
reason: string;
|
|
9
|
+
}, "PushNotificationError::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PushNotificationError::ScheduleLimitReached">>, import("scale-ts").Decoder<import("@novasamatech/scale").CodecError<{
|
|
10
|
+
reason: string;
|
|
11
|
+
}, "PushNotificationError::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PushNotificationError::ScheduleLimitReached">>] & {
|
|
12
|
+
enc: import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<{
|
|
13
|
+
reason: string;
|
|
14
|
+
}, "PushNotificationError::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PushNotificationError::ScheduleLimitReached">>;
|
|
15
|
+
dec: import("scale-ts").Decoder<import("@novasamatech/scale").CodecError<{
|
|
16
|
+
reason: string;
|
|
17
|
+
}, "PushNotificationError::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PushNotificationError::ScheduleLimitReached">>;
|
|
18
|
+
} & {
|
|
19
|
+
readonly ScheduleLimitReached: import("@novasamatech/scale").ErrCodec<undefined, "PushNotificationError::ScheduleLimitReached">;
|
|
20
|
+
readonly Unknown: import("@novasamatech/scale").ErrCodec<{
|
|
21
|
+
reason: string;
|
|
22
|
+
}, "PushNotificationError::Unknown">;
|
|
23
|
+
} & {
|
|
24
|
+
[Symbol.hasInstance](v: unknown): v is import("@novasamatech/scale").CodecError<{
|
|
25
|
+
reason: string;
|
|
26
|
+
}, "PushNotificationError::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PushNotificationError::ScheduleLimitReached">;
|
|
27
|
+
};
|
|
5
28
|
export declare const PushNotificationV1_request: import("scale-ts").Codec<{
|
|
6
29
|
text: string;
|
|
7
30
|
deeplink: string | undefined;
|
|
31
|
+
scheduledAt: bigint | undefined;
|
|
8
32
|
}>;
|
|
9
|
-
export declare const PushNotificationV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<
|
|
33
|
+
export declare const PushNotificationV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<number, import("@novasamatech/scale").CodecError<{
|
|
34
|
+
reason: string;
|
|
35
|
+
}, "PushNotificationError::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "PushNotificationError::ScheduleLimitReached">>>;
|
|
36
|
+
export declare const PushNotificationCancelV1_request: import("scale-ts").Codec<number>;
|
|
37
|
+
export declare const PushNotificationCancelV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
|
|
10
38
|
reason: string;
|
|
11
39
|
}, "GenericError">>>;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ErrEnum } from '@novasamatech/scale';
|
|
2
|
+
import { Option, Result, Struct, _void, str, u32, u64 } from 'scale-ts';
|
|
3
|
+
import { GenericErr, GenericError } from '../commonCodecs.js';
|
|
4
|
+
export const NotificationId = u32;
|
|
3
5
|
export const PushNotification = Struct({
|
|
4
6
|
text: str,
|
|
5
7
|
deeplink: Option(str),
|
|
8
|
+
scheduledAt: Option(u64),
|
|
9
|
+
});
|
|
10
|
+
export const PushNotificationError = ErrEnum('PushNotificationError', {
|
|
11
|
+
ScheduleLimitReached: [_void, 'Schedule limit reached'],
|
|
12
|
+
Unknown: [GenericErr, 'Unknown error'],
|
|
6
13
|
});
|
|
7
14
|
export const PushNotificationV1_request = PushNotification;
|
|
8
|
-
export const PushNotificationV1_response = Result(
|
|
15
|
+
export const PushNotificationV1_response = Result(NotificationId, PushNotificationError);
|
|
16
|
+
export const PushNotificationCancelV1_request = NotificationId;
|
|
17
|
+
export const PushNotificationCancelV1_response = Result(_void, GenericError);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/host-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.9-
|
|
4
|
+
"version": "0.7.9-5",
|
|
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.9-
|
|
25
|
+
"@novasamatech/scale": "0.7.9-5",
|
|
26
26
|
"nanoevents": "9.1.0",
|
|
27
27
|
"nanoid": "5.1.9",
|
|
28
28
|
"neverthrow": "^8.2.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Struct, _void, bool } from 'scale-ts';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { Err, ErrEnum, Hex, Status } from './commonCodecs.js';
|
|
4
|
-
describe('Common codecs', () => {
|
|
5
|
-
describe('Hex', () => {
|
|
6
|
-
it('should correctly encode/decode Hex with arbitrary length', () => {
|
|
7
|
-
const hex = '0xffffff';
|
|
8
|
-
const codec = Hex();
|
|
9
|
-
expect(codec.enc(hex)).toEqual(new Uint8Array([12, 255, 255, 255]));
|
|
10
|
-
expect(codec.dec(codec.enc(hex))).toEqual(hex);
|
|
11
|
-
});
|
|
12
|
-
it('should correctly encode/decode Hex with fixed length', () => {
|
|
13
|
-
const hex = '0xffffff';
|
|
14
|
-
const codec = Hex(3);
|
|
15
|
-
expect(codec.enc(hex)).toEqual(new Uint8Array([255, 255, 255]));
|
|
16
|
-
expect(codec.dec(codec.enc(hex))).toEqual(hex);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
describe('Status', () => {
|
|
20
|
-
it('should correctly encode/decode Status', () => {
|
|
21
|
-
const codec = Status('New', 'Used');
|
|
22
|
-
expect(codec.enc('New')).toEqual(new Uint8Array([0]));
|
|
23
|
-
expect(codec.enc('Used')).toEqual(new Uint8Array([1]));
|
|
24
|
-
expect(codec.dec('0x00')).toEqual('New');
|
|
25
|
-
expect(codec.dec('0x01')).toEqual('Used');
|
|
26
|
-
// @ts-expect-error for test
|
|
27
|
-
expect(() => codec.enc('Unknown')).toThrowErrorMatchingInlineSnapshot(`[Error: Unknown status value: Unknown]`);
|
|
28
|
-
expect(() => codec.dec('0x03')).toThrowErrorMatchingInlineSnapshot(`[Error: Unknown status index: 3]`);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
describe('Err', () => {
|
|
32
|
-
it('should correctly construct Error', () => {
|
|
33
|
-
const ErrorCodec = Err('TestError', _void, 'Test message');
|
|
34
|
-
const error = new ErrorCodec(undefined);
|
|
35
|
-
expect(error).toBeInstanceOf(ErrorCodec);
|
|
36
|
-
expect(error.name).toBe('TestError');
|
|
37
|
-
expect(error.message).toBe('Test message');
|
|
38
|
-
});
|
|
39
|
-
it('should correctly encode/decode Err', () => {
|
|
40
|
-
const payload = Struct({ enable: bool });
|
|
41
|
-
const ErrorCodec = Err('TestError', payload, 'Test message');
|
|
42
|
-
const error = new ErrorCodec({ enable: true });
|
|
43
|
-
expect(ErrorCodec.enc(error)).toEqual(new Uint8Array([1]));
|
|
44
|
-
expect(ErrorCodec.dec(ErrorCodec.enc(error))).toEqual(new ErrorCodec({ enable: true }));
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
describe('ErrEnum', () => {
|
|
48
|
-
it('should correctly construct ErrorEnum field', () => {
|
|
49
|
-
const ErrorCodec = ErrEnum('ErrorCodec', {
|
|
50
|
-
TestError: [_void, 'Test message'],
|
|
51
|
-
});
|
|
52
|
-
const error = new ErrorCodec.TestError(undefined);
|
|
53
|
-
expect(error).toBeInstanceOf(ErrorCodec.TestError);
|
|
54
|
-
expect(error.name).toBe('ErrorCodec::TestError');
|
|
55
|
-
expect(error.message).toBe('Test message');
|
|
56
|
-
});
|
|
57
|
-
it('should correctly serialize/deserialize', () => {
|
|
58
|
-
const ErrorCodec = ErrEnum('ErrorCodec', {
|
|
59
|
-
First: [_void, 'First'],
|
|
60
|
-
Second: [_void, 'Second'],
|
|
61
|
-
});
|
|
62
|
-
const first = new ErrorCodec.First(undefined);
|
|
63
|
-
const second = new ErrorCodec.Second(undefined);
|
|
64
|
-
expect(ErrorCodec.enc(first)).toEqual(new Uint8Array([0]));
|
|
65
|
-
expect(ErrorCodec.enc(second)).toEqual(new Uint8Array([1]));
|
|
66
|
-
expect(ErrorCodec.dec(ErrorCodec.enc(first))).toEqual(first);
|
|
67
|
-
expect(ErrorCodec.dec(ErrorCodec.enc(second))).toEqual(second);
|
|
68
|
-
expect(ErrorCodec.dec(ErrorCodec.enc(first))).not.toEqual(second);
|
|
69
|
-
expect(ErrorCodec.dec(ErrorCodec.enc(second))).not.toEqual(first);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
package/dist/protocol/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type HexString = `0x${string}`;
|
package/dist/protocol/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { GenericError } from '../commonCodecs.js';
|
|
3
|
-
import { DevicePermission, DevicePermissionV1_request, DevicePermissionV1_response } from './devicePermission.js';
|
|
4
|
-
describe('DevicePermission codec', () => {
|
|
5
|
-
it('encodes Notifications at index 0', () => {
|
|
6
|
-
expect(DevicePermission.enc('Notifications')).toEqual(new Uint8Array([0]));
|
|
7
|
-
expect(DevicePermission.dec(new Uint8Array([0]))).toEqual('Notifications');
|
|
8
|
-
});
|
|
9
|
-
it('encodes Camera at index 1', () => {
|
|
10
|
-
expect(DevicePermission.enc('Camera')).toEqual(new Uint8Array([1]));
|
|
11
|
-
expect(DevicePermission.dec(new Uint8Array([1]))).toEqual('Camera');
|
|
12
|
-
});
|
|
13
|
-
it('encodes Microphone at index 2', () => {
|
|
14
|
-
expect(DevicePermission.enc('Microphone')).toEqual(new Uint8Array([2]));
|
|
15
|
-
expect(DevicePermission.dec(new Uint8Array([2]))).toEqual('Microphone');
|
|
16
|
-
});
|
|
17
|
-
it('encodes Bluetooth at index 3', () => {
|
|
18
|
-
expect(DevicePermission.enc('Bluetooth')).toEqual(new Uint8Array([3]));
|
|
19
|
-
expect(DevicePermission.dec(new Uint8Array([3]))).toEqual('Bluetooth');
|
|
20
|
-
});
|
|
21
|
-
it('encodes NFC at index 4', () => {
|
|
22
|
-
expect(DevicePermission.enc('NFC')).toEqual(new Uint8Array([4]));
|
|
23
|
-
expect(DevicePermission.dec(new Uint8Array([4]))).toEqual('NFC');
|
|
24
|
-
});
|
|
25
|
-
it('encodes Location at index 5', () => {
|
|
26
|
-
expect(DevicePermission.enc('Location')).toEqual(new Uint8Array([5]));
|
|
27
|
-
expect(DevicePermission.dec(new Uint8Array([5]))).toEqual('Location');
|
|
28
|
-
});
|
|
29
|
-
it('encodes Clipboard at index 6', () => {
|
|
30
|
-
expect(DevicePermission.enc('Clipboard')).toEqual(new Uint8Array([6]));
|
|
31
|
-
expect(DevicePermission.dec(new Uint8Array([6]))).toEqual('Clipboard');
|
|
32
|
-
});
|
|
33
|
-
it('encodes OpenUrl at index 7', () => {
|
|
34
|
-
expect(DevicePermission.enc('OpenUrl')).toEqual(new Uint8Array([7]));
|
|
35
|
-
expect(DevicePermission.dec(new Uint8Array([7]))).toEqual('OpenUrl');
|
|
36
|
-
});
|
|
37
|
-
it('encodes Biometrics at index 8', () => {
|
|
38
|
-
expect(DevicePermission.enc('Biometrics')).toEqual(new Uint8Array([8]));
|
|
39
|
-
expect(DevicePermission.dec(new Uint8Array([8]))).toEqual('Biometrics');
|
|
40
|
-
});
|
|
41
|
-
it('DevicePermissionV1_request is DevicePermission', () => {
|
|
42
|
-
expect(DevicePermissionV1_request).toBe(DevicePermission);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe('DevicePermissionV1_response codec', () => {
|
|
46
|
-
it('encodes and decodes ok(true)', () => {
|
|
47
|
-
const encoded = DevicePermissionV1_response.enc({ success: true, value: true });
|
|
48
|
-
expect(DevicePermissionV1_response.dec(encoded)).toEqual({ success: true, value: true });
|
|
49
|
-
});
|
|
50
|
-
it('encodes and decodes err with GenericError', () => {
|
|
51
|
-
const error = new GenericError({ reason: 'denied' });
|
|
52
|
-
const encoded = DevicePermissionV1_response.enc({ success: false, value: error });
|
|
53
|
-
const decoded = DevicePermissionV1_response.dec(encoded);
|
|
54
|
-
expect(decoded.success).toBe(false);
|
|
55
|
-
if (decoded.success === false) {
|
|
56
|
-
expect(decoded.value).toBeInstanceOf(GenericError);
|
|
57
|
-
expect(decoded.value.message).toContain('denied');
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const JsonRpcMessageSendV1_request: import("scale-ts").Codec<[`0x${string}`, string]>;
|
|
2
|
-
export declare const JsonRpcMessageSendV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, import("packages/scale/src/err.js").CodecError<{
|
|
3
|
-
reason: string;
|
|
4
|
-
}, "GenericError">>>;
|
|
5
|
-
export declare const JsonRpcMessageSubscribeV1_start: import("scale-ts").Codec<`0x${string}`>;
|
|
6
|
-
export declare const JsonRpcMessageSubscribeV1_receive: import("scale-ts").Codec<string>;
|
|
7
|
-
export declare const JsonRpcMessageSubscribeV1_interrupt: import("scale-ts").Codec<undefined>;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Result, Tuple, _void, str } from 'scale-ts';
|
|
2
|
-
import { GenericError, GenesisHash } from '../commonCodecs.js';
|
|
3
|
-
export const JsonRpcMessageSendV1_request = Tuple(GenesisHash, str);
|
|
4
|
-
export const JsonRpcMessageSendV1_response = Result(_void, GenericError);
|
|
5
|
-
export const JsonRpcMessageSubscribeV1_start = GenesisHash;
|
|
6
|
-
export const JsonRpcMessageSubscribeV1_receive = str;
|
|
7
|
-
export const JsonRpcMessageSubscribeV1_interrupt = _void;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export declare const PermissionErr: [import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<undefined, "PermissionErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
2
|
-
reason: string;
|
|
3
|
-
}, "PermissionErr::Unknown">>, import("scale-ts").Decoder<import("@novasamatech/scale").CodecError<undefined, "PermissionErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
4
|
-
reason: string;
|
|
5
|
-
}, "PermissionErr::Unknown">>] & {
|
|
6
|
-
enc: import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<undefined, "PermissionErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
7
|
-
reason: string;
|
|
8
|
-
}, "PermissionErr::Unknown">>;
|
|
9
|
-
dec: import("scale-ts").Decoder<import("@novasamatech/scale").CodecError<undefined, "PermissionErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
10
|
-
reason: string;
|
|
11
|
-
}, "PermissionErr::Unknown">>;
|
|
12
|
-
} & {
|
|
13
|
-
readonly Rejected: import("@novasamatech/scale").ErrCodec<undefined, "PermissionErr::Rejected">;
|
|
14
|
-
readonly Unknown: import("@novasamatech/scale").ErrCodec<{
|
|
15
|
-
reason: string;
|
|
16
|
-
}, "PermissionErr::Unknown">;
|
|
17
|
-
};
|
|
18
|
-
export declare const ChainConnectPermission: import("scale-ts").Codec<{
|
|
19
|
-
genesisHash: `0x${string}`;
|
|
20
|
-
name: string;
|
|
21
|
-
}>;
|
|
22
|
-
export declare const Permission: import("scale-ts").Codec<{
|
|
23
|
-
tag: "ChainSubmit";
|
|
24
|
-
value: `0x${string}`;
|
|
25
|
-
} | {
|
|
26
|
-
tag: "ChainConnect";
|
|
27
|
-
value: {
|
|
28
|
-
genesisHash: `0x${string}`;
|
|
29
|
-
name: string;
|
|
30
|
-
};
|
|
31
|
-
} | {
|
|
32
|
-
tag: "NetworkRequest";
|
|
33
|
-
value: string[];
|
|
34
|
-
}>;
|
|
35
|
-
export declare const PermissionRequestV1_request: import("scale-ts").Codec<{
|
|
36
|
-
tag: "ChainSubmit";
|
|
37
|
-
value: `0x${string}`;
|
|
38
|
-
} | {
|
|
39
|
-
tag: "ChainConnect";
|
|
40
|
-
value: {
|
|
41
|
-
genesisHash: `0x${string}`;
|
|
42
|
-
name: string;
|
|
43
|
-
};
|
|
44
|
-
} | {
|
|
45
|
-
tag: "NetworkRequest";
|
|
46
|
-
value: string[];
|
|
47
|
-
}>;
|
|
48
|
-
export declare const PermissionRequestV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<undefined, "PermissionErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
49
|
-
reason: string;
|
|
50
|
-
}, "PermissionErr::Unknown">>>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Enum, ErrEnum } from '@novasamatech/scale';
|
|
2
|
-
import { Result, Struct, Vector, _void, str } from 'scale-ts';
|
|
3
|
-
import { GenericErr, GenesisHash } from '../commonCodecs.js';
|
|
4
|
-
export const PermissionErr = ErrEnum('PermissionErr', {
|
|
5
|
-
Rejected: [_void, 'Permission: rejected'],
|
|
6
|
-
Unknown: [GenericErr, 'Permission: unknown error'],
|
|
7
|
-
});
|
|
8
|
-
export const ChainConnectPermission = Struct({
|
|
9
|
-
genesisHash: GenesisHash,
|
|
10
|
-
name: str,
|
|
11
|
-
});
|
|
12
|
-
export const Permission = Enum({
|
|
13
|
-
ChainSubmit: GenesisHash,
|
|
14
|
-
ChainConnect: ChainConnectPermission,
|
|
15
|
-
NetworkRequest: Vector(str),
|
|
16
|
-
// TBD
|
|
17
|
-
});
|
|
18
|
-
export const PermissionRequestV1_request = Permission;
|
|
19
|
-
export const PermissionRequestV1_response = Result(_void, PermissionErr);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { GenericError } from '../commonCodecs.js';
|
|
3
|
-
import { RemotePermission, RemotePermissionV1_request, RemotePermissionV1_response } from './remotePermission.js';
|
|
4
|
-
describe('RemotePermission codec', () => {
|
|
5
|
-
it('encodes and decodes Remote (index 0) with domain list', () => {
|
|
6
|
-
const value = { tag: 'Remote', value: ['api.coingecko.com', '*.example.com'] };
|
|
7
|
-
const encoded = RemotePermission.enc(value);
|
|
8
|
-
expect(encoded[0]).toBe(0);
|
|
9
|
-
expect(RemotePermission.dec(encoded)).toEqual(value);
|
|
10
|
-
});
|
|
11
|
-
it('encodes and decodes WebRTC at index 1', () => {
|
|
12
|
-
const value = { tag: 'WebRTC', value: undefined };
|
|
13
|
-
const encoded = RemotePermission.enc(value);
|
|
14
|
-
expect(encoded[0]).toBe(1);
|
|
15
|
-
expect(RemotePermission.dec(encoded)).toEqual(value);
|
|
16
|
-
});
|
|
17
|
-
it('encodes and decodes ChainSubmit at index 2', () => {
|
|
18
|
-
const value = { tag: 'ChainSubmit', value: undefined };
|
|
19
|
-
const encoded = RemotePermission.enc(value);
|
|
20
|
-
expect(encoded[0]).toBe(2);
|
|
21
|
-
expect(RemotePermission.dec(encoded)).toEqual(value);
|
|
22
|
-
});
|
|
23
|
-
it('encodes and decodes PreimageSubmit at index 3', () => {
|
|
24
|
-
const value = { tag: 'PreimageSubmit', value: undefined };
|
|
25
|
-
const encoded = RemotePermission.enc(value);
|
|
26
|
-
expect(encoded[0]).toBe(3);
|
|
27
|
-
expect(RemotePermission.dec(encoded)).toEqual(value);
|
|
28
|
-
});
|
|
29
|
-
it('encodes and decodes StatementSubmit at index 4', () => {
|
|
30
|
-
const value = { tag: 'StatementSubmit', value: undefined };
|
|
31
|
-
const encoded = RemotePermission.enc(value);
|
|
32
|
-
expect(encoded[0]).toBe(4);
|
|
33
|
-
expect(RemotePermission.dec(encoded)).toEqual(value);
|
|
34
|
-
});
|
|
35
|
-
it('RemotePermissionV1_request encodes a batch of multiple permissions', () => {
|
|
36
|
-
const batch = [
|
|
37
|
-
{ tag: 'Remote', value: ['api.example.com'] },
|
|
38
|
-
{ tag: 'ChainSubmit', value: undefined },
|
|
39
|
-
{ tag: 'StatementSubmit', value: undefined },
|
|
40
|
-
];
|
|
41
|
-
const encoded = RemotePermissionV1_request.enc(batch);
|
|
42
|
-
const decoded = RemotePermissionV1_request.dec(encoded);
|
|
43
|
-
expect(decoded).toEqual(batch);
|
|
44
|
-
});
|
|
45
|
-
it('RemotePermissionV1_request encodes an empty batch', () => {
|
|
46
|
-
RemotePermissionV1_request.enc([]);
|
|
47
|
-
expect(RemotePermissionV1_request.dec(RemotePermissionV1_request.enc([]))).toEqual([]);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe('RemotePermissionV1_response codec', () => {
|
|
51
|
-
it('encodes and decodes ok(true)', () => {
|
|
52
|
-
const encoded = RemotePermissionV1_response.enc({ success: true, value: true });
|
|
53
|
-
expect(RemotePermissionV1_response.dec(encoded)).toEqual({ success: true, value: true });
|
|
54
|
-
});
|
|
55
|
-
it('encodes and decodes err with GenericError', () => {
|
|
56
|
-
const error = new GenericError({ reason: 'denied' });
|
|
57
|
-
const encoded = RemotePermissionV1_response.enc({ success: false, value: error });
|
|
58
|
-
const decoded = RemotePermissionV1_response.dec(encoded);
|
|
59
|
-
expect(decoded.success).toBe(false);
|
|
60
|
-
if (decoded.success === false) {
|
|
61
|
-
expect(decoded.value).toBeInstanceOf(GenericError);
|
|
62
|
-
expect(decoded.value.message).toContain('denied');
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export declare const StorageErr: [import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<{
|
|
2
|
-
reason: string;
|
|
3
|
-
}, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>, import("scale-ts").Decoder<import("@novasamatech/scale").CodecError<{
|
|
4
|
-
reason: string;
|
|
5
|
-
}, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>] & {
|
|
6
|
-
enc: import("scale-ts").Encoder<import("@novasamatech/scale").CodecError<{
|
|
7
|
-
reason: string;
|
|
8
|
-
}, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>;
|
|
9
|
-
dec: import("scale-ts").Decoder<import("@novasamatech/scale").CodecError<{
|
|
10
|
-
reason: string;
|
|
11
|
-
}, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>;
|
|
12
|
-
} & {
|
|
13
|
-
readonly Full: import("@novasamatech/scale").ErrCodec<undefined, "StorageErr::Full">;
|
|
14
|
-
readonly Unknown: import("@novasamatech/scale").ErrCodec<{
|
|
15
|
-
reason: string;
|
|
16
|
-
}, "StorageErr::Unknown">;
|
|
17
|
-
};
|
|
18
|
-
export declare const StorageKey: import("scale-ts").Codec<string>;
|
|
19
|
-
export declare const StorageValue: import("scale-ts").Codec<Uint8Array<ArrayBufferLike>>;
|
|
20
|
-
export declare const StorageReadV1_request: import("scale-ts").Codec<string>;
|
|
21
|
-
export declare const StorageReadV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<Uint8Array<ArrayBufferLike> | undefined, import("@novasamatech/scale").CodecError<{
|
|
22
|
-
reason: string;
|
|
23
|
-
}, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>>;
|
|
24
|
-
export declare const StorageWriteV1_request: import("scale-ts").Codec<[string, Uint8Array<ArrayBufferLike>]>;
|
|
25
|
-
export declare const StorageWriteV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
|
|
26
|
-
reason: string;
|
|
27
|
-
}, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>>;
|
|
28
|
-
export declare const StorageClearV1_request: import("scale-ts").Codec<string>;
|
|
29
|
-
export declare const StorageClearV1_response: import("scale-ts").Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
|
|
30
|
-
reason: string;
|
|
31
|
-
}, "StorageErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "StorageErr::Full">>>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ErrEnum } from '@novasamatech/scale';
|
|
2
|
-
import { Bytes, Option, Result, Tuple, _void, str } from 'scale-ts';
|
|
3
|
-
import { GenericErr } from '../commonCodecs.js';
|
|
4
|
-
// common structures
|
|
5
|
-
export const StorageErr = ErrEnum('StorageErr', {
|
|
6
|
-
Full: [_void, 'Storage is full'],
|
|
7
|
-
Unknown: [GenericErr, 'Unknown storage error'],
|
|
8
|
-
});
|
|
9
|
-
export const StorageKey = str;
|
|
10
|
-
export const StorageValue = Bytes();
|
|
11
|
-
// actions
|
|
12
|
-
export const StorageReadV1_request = StorageKey;
|
|
13
|
-
export const StorageReadV1_response = Result(Option(StorageValue), StorageErr);
|
|
14
|
-
export const StorageWriteV1_request = Tuple(StorageKey, StorageValue);
|
|
15
|
-
export const StorageWriteV1_response = Result(_void, StorageErr);
|
|
16
|
-
export const StorageClearV1_request = StorageKey;
|
|
17
|
-
export const StorageClearV1_response = Result(_void, StorageErr);
|