@novasamatech/host-api 0.6.1 → 0.6.3

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 CHANGED
@@ -465,5 +465,225 @@ export function createHostApi(transport) {
465
465
  jsonrpcMessageSubscribe(args, callback) {
466
466
  return transport.subscribe('host_jsonrpc_message_subscribe', args, callback);
467
467
  },
468
+ // chain interaction
469
+ chainHeadFollow(args, callback) {
470
+ return transport.subscribe('remote_chain_head_follow', args, callback);
471
+ },
472
+ chainHeadHeader(payload) {
473
+ const response = fromPromise(transport.request('remote_chain_head_header', payload), e => ({
474
+ tag: payload.tag,
475
+ value: new GenericError({ reason: extractErrorMessage(e) }),
476
+ }));
477
+ return response.andThen(response => {
478
+ if (response.value.success) {
479
+ return okAsync({
480
+ tag: response.tag,
481
+ value: response.value.value,
482
+ });
483
+ }
484
+ return errAsync({
485
+ tag: response.tag,
486
+ value: response.value.value,
487
+ });
488
+ });
489
+ },
490
+ chainHeadBody(payload) {
491
+ const response = fromPromise(transport.request('remote_chain_head_body', payload), e => ({
492
+ tag: payload.tag,
493
+ value: new GenericError({ reason: extractErrorMessage(e) }),
494
+ }));
495
+ return response.andThen(response => {
496
+ if (response.value.success) {
497
+ return okAsync({
498
+ tag: response.tag,
499
+ value: response.value.value,
500
+ });
501
+ }
502
+ return errAsync({
503
+ tag: response.tag,
504
+ value: response.value.value,
505
+ });
506
+ });
507
+ },
508
+ chainHeadStorage(payload) {
509
+ const response = fromPromise(transport.request('remote_chain_head_storage', payload), e => ({
510
+ tag: payload.tag,
511
+ value: new GenericError({ reason: extractErrorMessage(e) }),
512
+ }));
513
+ return response.andThen(response => {
514
+ if (response.value.success) {
515
+ return okAsync({
516
+ tag: response.tag,
517
+ value: response.value.value,
518
+ });
519
+ }
520
+ return errAsync({
521
+ tag: response.tag,
522
+ value: response.value.value,
523
+ });
524
+ });
525
+ },
526
+ chainHeadCall(payload) {
527
+ const response = fromPromise(transport.request('remote_chain_head_call', payload), e => ({
528
+ tag: payload.tag,
529
+ value: new GenericError({ reason: extractErrorMessage(e) }),
530
+ }));
531
+ return response.andThen(response => {
532
+ if (response.value.success) {
533
+ return okAsync({
534
+ tag: response.tag,
535
+ value: response.value.value,
536
+ });
537
+ }
538
+ return errAsync({
539
+ tag: response.tag,
540
+ value: response.value.value,
541
+ });
542
+ });
543
+ },
544
+ chainHeadUnpin(payload) {
545
+ const response = fromPromise(transport.request('remote_chain_head_unpin', payload), e => ({
546
+ tag: payload.tag,
547
+ value: new GenericError({ reason: extractErrorMessage(e) }),
548
+ }));
549
+ return response.andThen(response => {
550
+ if (response.value.success) {
551
+ return okAsync({
552
+ tag: response.tag,
553
+ value: response.value.value,
554
+ });
555
+ }
556
+ return errAsync({
557
+ tag: response.tag,
558
+ value: response.value.value,
559
+ });
560
+ });
561
+ },
562
+ chainHeadContinue(payload) {
563
+ const response = fromPromise(transport.request('remote_chain_head_continue', payload), e => ({
564
+ tag: payload.tag,
565
+ value: new GenericError({ reason: extractErrorMessage(e) }),
566
+ }));
567
+ return response.andThen(response => {
568
+ if (response.value.success) {
569
+ return okAsync({
570
+ tag: response.tag,
571
+ value: response.value.value,
572
+ });
573
+ }
574
+ return errAsync({
575
+ tag: response.tag,
576
+ value: response.value.value,
577
+ });
578
+ });
579
+ },
580
+ chainHeadStopOperation(payload) {
581
+ const response = fromPromise(transport.request('remote_chain_head_stop_operation', payload), e => ({
582
+ tag: payload.tag,
583
+ value: new GenericError({ reason: extractErrorMessage(e) }),
584
+ }));
585
+ return response.andThen(response => {
586
+ if (response.value.success) {
587
+ return okAsync({
588
+ tag: response.tag,
589
+ value: response.value.value,
590
+ });
591
+ }
592
+ return errAsync({
593
+ tag: response.tag,
594
+ value: response.value.value,
595
+ });
596
+ });
597
+ },
598
+ chainSpecGenesisHash(payload) {
599
+ const response = fromPromise(transport.request('remote_chain_spec_genesis_hash', payload), e => ({
600
+ tag: payload.tag,
601
+ value: new GenericError({ reason: extractErrorMessage(e) }),
602
+ }));
603
+ return response.andThen(response => {
604
+ if (response.value.success) {
605
+ return okAsync({
606
+ tag: response.tag,
607
+ value: response.value.value,
608
+ });
609
+ }
610
+ return errAsync({
611
+ tag: response.tag,
612
+ value: response.value.value,
613
+ });
614
+ });
615
+ },
616
+ chainSpecChainName(payload) {
617
+ const response = fromPromise(transport.request('remote_chain_spec_chain_name', payload), e => ({
618
+ tag: payload.tag,
619
+ value: new GenericError({ reason: extractErrorMessage(e) }),
620
+ }));
621
+ return response.andThen(response => {
622
+ if (response.value.success) {
623
+ return okAsync({
624
+ tag: response.tag,
625
+ value: response.value.value,
626
+ });
627
+ }
628
+ return errAsync({
629
+ tag: response.tag,
630
+ value: response.value.value,
631
+ });
632
+ });
633
+ },
634
+ chainSpecProperties(payload) {
635
+ const response = fromPromise(transport.request('remote_chain_spec_properties', payload), e => ({
636
+ tag: payload.tag,
637
+ value: new GenericError({ reason: extractErrorMessage(e) }),
638
+ }));
639
+ return response.andThen(response => {
640
+ if (response.value.success) {
641
+ return okAsync({
642
+ tag: response.tag,
643
+ value: response.value.value,
644
+ });
645
+ }
646
+ return errAsync({
647
+ tag: response.tag,
648
+ value: response.value.value,
649
+ });
650
+ });
651
+ },
652
+ chainTransactionBroadcast(payload) {
653
+ const response = fromPromise(transport.request('remote_chain_transaction_broadcast', payload), e => ({
654
+ tag: payload.tag,
655
+ value: new GenericError({ reason: extractErrorMessage(e) }),
656
+ }));
657
+ return response.andThen(response => {
658
+ if (response.value.success) {
659
+ return okAsync({
660
+ tag: response.tag,
661
+ value: response.value.value,
662
+ });
663
+ }
664
+ return errAsync({
665
+ tag: response.tag,
666
+ value: response.value.value,
667
+ });
668
+ });
669
+ },
670
+ chainTransactionStop(payload) {
671
+ const response = fromPromise(transport.request('remote_chain_transaction_stop', payload), e => ({
672
+ tag: payload.tag,
673
+ value: new GenericError({ reason: extractErrorMessage(e) }),
674
+ }));
675
+ return response.andThen(response => {
676
+ if (response.value.success) {
677
+ return okAsync({
678
+ tag: response.tag,
679
+ value: response.value.value,
680
+ });
681
+ }
682
+ return errAsync({
683
+ tag: response.tag,
684
+ value: response.value.value,
685
+ });
686
+ });
687
+ },
468
688
  };
469
689
  }
package/dist/index.d.ts CHANGED
@@ -24,3 +24,4 @@ export { PushNotification } from './protocol/v1/notification.js';
24
24
  export { NavigateToErr } from './protocol/v1/navigation.js';
25
25
  export { PreimageKey, PreimageSubmitErr, PreimageValue } from './protocol/v1/preimage.js';
26
26
  export { CustomRendererNode } from './protocol/v1/customRenderer.js';
27
+ export { ChainHeadEvent, ChainHeadFollowV1_start, OperationStartedResult, RuntimeType, StorageQueryItem, StorageQueryType, StorageResultItem, TransactionBroadcastV1_request, TransactionBroadcastV1_response, TransactionStopV1_request, TransactionStopV1_response, } from './protocol/v1/chainInteraction.js';
package/dist/index.js CHANGED
@@ -19,3 +19,4 @@ export { PushNotification } from './protocol/v1/notification.js';
19
19
  export { NavigateToErr } from './protocol/v1/navigation.js';
20
20
  export { PreimageKey, PreimageSubmitErr, PreimageValue } from './protocol/v1/preimage.js';
21
21
  export { CustomRendererNode } from './protocol/v1/customRenderer.js';
22
+ export { ChainHeadEvent, ChainHeadFollowV1_start, OperationStartedResult, RuntimeType, StorageQueryItem, StorageQueryType, StorageResultItem, TransactionBroadcastV1_request, TransactionBroadcastV1_response, TransactionStopV1_request, TransactionStopV1_response, } from './protocol/v1/chainInteraction.js';
@@ -322,6 +322,7 @@ export declare const hostApiProtocol: {
322
322
  }>;
323
323
  readonly product_chat_custom_message_render_subscribe: VersionedProtocolSubscription<{
324
324
  readonly v1: [Codec<{
325
+ messageId: string;
325
326
  messageType: string;
326
327
  payload: Uint8Array<ArrayBufferLike>;
327
328
  }>, Codec<import("./v1/customRenderer.js").CustomRendererNodeType>];
@@ -476,5 +477,237 @@ export declare const hostApiProtocol: {
476
477
  readonly host_jsonrpc_message_subscribe: VersionedProtocolSubscription<{
477
478
  readonly v1: [Codec<`0x${string}`>, Codec<string>];
478
479
  }>;
480
+ readonly remote_chain_head_follow: VersionedProtocolSubscription<{
481
+ readonly v1: [Codec<{
482
+ genesisHash: `0x${string}`;
483
+ withRuntime: boolean;
484
+ }>, Codec<{
485
+ tag: "Initialized";
486
+ value: {
487
+ finalizedBlockHashes: `0x${string}`[];
488
+ finalizedBlockRuntime: {
489
+ tag: "Valid";
490
+ value: {
491
+ specName: string;
492
+ implName: string;
493
+ specVersion: number;
494
+ implVersion: number;
495
+ transactionVersion: number | undefined;
496
+ apis: [string, number][];
497
+ };
498
+ } | {
499
+ tag: "Invalid";
500
+ value: {
501
+ error: string;
502
+ };
503
+ } | undefined;
504
+ };
505
+ } | {
506
+ tag: "NewBlock";
507
+ value: {
508
+ blockHash: `0x${string}`;
509
+ parentBlockHash: `0x${string}`;
510
+ newRuntime: {
511
+ tag: "Valid";
512
+ value: {
513
+ specName: string;
514
+ implName: string;
515
+ specVersion: number;
516
+ implVersion: number;
517
+ transactionVersion: number | undefined;
518
+ apis: [string, number][];
519
+ };
520
+ } | {
521
+ tag: "Invalid";
522
+ value: {
523
+ error: string;
524
+ };
525
+ } | undefined;
526
+ };
527
+ } | {
528
+ tag: "BestBlockChanged";
529
+ value: {
530
+ bestBlockHash: `0x${string}`;
531
+ };
532
+ } | {
533
+ tag: "Finalized";
534
+ value: {
535
+ finalizedBlockHashes: `0x${string}`[];
536
+ prunedBlockHashes: `0x${string}`[];
537
+ };
538
+ } | {
539
+ tag: "OperationBodyDone";
540
+ value: {
541
+ operationId: string;
542
+ value: `0x${string}`[];
543
+ };
544
+ } | {
545
+ tag: "OperationCallDone";
546
+ value: {
547
+ operationId: string;
548
+ output: `0x${string}`;
549
+ };
550
+ } | {
551
+ tag: "OperationStorageItems";
552
+ value: {
553
+ operationId: string;
554
+ items: {
555
+ key: `0x${string}`;
556
+ value: `0x${string}` | null;
557
+ hash: `0x${string}` | null;
558
+ closestDescendantMerkleValue: `0x${string}` | null;
559
+ }[];
560
+ };
561
+ } | {
562
+ tag: "OperationStorageDone";
563
+ value: {
564
+ operationId: string;
565
+ };
566
+ } | {
567
+ tag: "OperationWaitingForContinue";
568
+ value: {
569
+ operationId: string;
570
+ };
571
+ } | {
572
+ tag: "OperationInaccessible";
573
+ value: {
574
+ operationId: string;
575
+ };
576
+ } | {
577
+ tag: "OperationError";
578
+ value: {
579
+ operationId: string;
580
+ error: string;
581
+ };
582
+ } | {
583
+ tag: "Stop";
584
+ value: undefined;
585
+ }>];
586
+ }>;
587
+ readonly remote_chain_head_header: VersionedProtocolRequest<{
588
+ readonly v1: [Codec<{
589
+ genesisHash: `0x${string}`;
590
+ followSubscriptionId: string;
591
+ hash: `0x${string}`;
592
+ }>, Codec<import("scale-ts").ResultPayload<`0x${string}` | null, import("@novasamatech/scale").CodecError<{
593
+ reason: string;
594
+ }, "GenericError">>>];
595
+ }>;
596
+ readonly remote_chain_head_body: VersionedProtocolRequest<{
597
+ readonly v1: [Codec<{
598
+ genesisHash: `0x${string}`;
599
+ followSubscriptionId: string;
600
+ hash: `0x${string}`;
601
+ }>, Codec<import("scale-ts").ResultPayload<{
602
+ tag: "Started";
603
+ value: {
604
+ operationId: string;
605
+ };
606
+ } | {
607
+ tag: "LimitReached";
608
+ value: undefined;
609
+ }, import("@novasamatech/scale").CodecError<{
610
+ reason: string;
611
+ }, "GenericError">>>];
612
+ }>;
613
+ readonly remote_chain_head_storage: VersionedProtocolRequest<{
614
+ readonly v1: [Codec<{
615
+ genesisHash: `0x${string}`;
616
+ followSubscriptionId: string;
617
+ hash: `0x${string}`;
618
+ items: {
619
+ key: `0x${string}`;
620
+ type: "Value" | "Hash" | "ClosestDescendantMerkleValue" | "DescendantsValues" | "DescendantsHashes";
621
+ }[];
622
+ childTrie: `0x${string}` | null;
623
+ }>, Codec<import("scale-ts").ResultPayload<{
624
+ tag: "Started";
625
+ value: {
626
+ operationId: string;
627
+ };
628
+ } | {
629
+ tag: "LimitReached";
630
+ value: undefined;
631
+ }, import("@novasamatech/scale").CodecError<{
632
+ reason: string;
633
+ }, "GenericError">>>];
634
+ }>;
635
+ readonly remote_chain_head_call: VersionedProtocolRequest<{
636
+ readonly v1: [Codec<{
637
+ genesisHash: `0x${string}`;
638
+ followSubscriptionId: string;
639
+ hash: `0x${string}`;
640
+ function: string;
641
+ callParameters: `0x${string}`;
642
+ }>, Codec<import("scale-ts").ResultPayload<{
643
+ tag: "Started";
644
+ value: {
645
+ operationId: string;
646
+ };
647
+ } | {
648
+ tag: "LimitReached";
649
+ value: undefined;
650
+ }, import("@novasamatech/scale").CodecError<{
651
+ reason: string;
652
+ }, "GenericError">>>];
653
+ }>;
654
+ readonly remote_chain_head_unpin: VersionedProtocolRequest<{
655
+ readonly v1: [Codec<{
656
+ genesisHash: `0x${string}`;
657
+ followSubscriptionId: string;
658
+ hashes: `0x${string}`[];
659
+ }>, Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
660
+ reason: string;
661
+ }, "GenericError">>>];
662
+ }>;
663
+ readonly remote_chain_head_continue: VersionedProtocolRequest<{
664
+ readonly v1: [Codec<{
665
+ genesisHash: `0x${string}`;
666
+ followSubscriptionId: string;
667
+ operationId: string;
668
+ }>, Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
669
+ reason: string;
670
+ }, "GenericError">>>];
671
+ }>;
672
+ readonly remote_chain_head_stop_operation: VersionedProtocolRequest<{
673
+ readonly v1: [Codec<{
674
+ genesisHash: `0x${string}`;
675
+ followSubscriptionId: string;
676
+ operationId: string;
677
+ }>, Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
678
+ reason: string;
679
+ }, "GenericError">>>];
680
+ }>;
681
+ readonly remote_chain_spec_genesis_hash: VersionedProtocolRequest<{
682
+ readonly v1: [Codec<`0x${string}`>, Codec<import("scale-ts").ResultPayload<`0x${string}`, import("@novasamatech/scale").CodecError<{
683
+ reason: string;
684
+ }, "GenericError">>>];
685
+ }>;
686
+ readonly remote_chain_spec_chain_name: VersionedProtocolRequest<{
687
+ readonly v1: [Codec<`0x${string}`>, Codec<import("scale-ts").ResultPayload<string, import("@novasamatech/scale").CodecError<{
688
+ reason: string;
689
+ }, "GenericError">>>];
690
+ }>;
691
+ readonly remote_chain_spec_properties: VersionedProtocolRequest<{
692
+ readonly v1: [Codec<`0x${string}`>, Codec<import("scale-ts").ResultPayload<string, import("@novasamatech/scale").CodecError<{
693
+ reason: string;
694
+ }, "GenericError">>>];
695
+ }>;
696
+ readonly remote_chain_transaction_broadcast: VersionedProtocolRequest<{
697
+ readonly v1: [Codec<{
698
+ genesisHash: `0x${string}`;
699
+ transaction: `0x${string}`;
700
+ }>, Codec<import("scale-ts").ResultPayload<string | null, import("@novasamatech/scale").CodecError<{
701
+ reason: string;
702
+ }, "GenericError">>>];
703
+ }>;
704
+ readonly remote_chain_transaction_stop: VersionedProtocolRequest<{
705
+ readonly v1: [Codec<{
706
+ genesisHash: `0x${string}`;
707
+ operationId: string;
708
+ }>, Codec<import("scale-ts").ResultPayload<undefined, import("@novasamatech/scale").CodecError<{
709
+ reason: string;
710
+ }, "GenericError">>>];
711
+ }>;
479
712
  };
480
713
  export {};
@@ -1,5 +1,6 @@
1
1
  import { Enum } from '@novasamatech/scale';
2
2
  import { AccountConnectionStatusV1_receive, AccountConnectionStatusV1_start, AccountCreateProofV1_request, AccountCreateProofV1_response, AccountGetAliasV1_request, AccountGetAliasV1_response, AccountGetV1_request, AccountGetV1_response, GetNonProductAccountsV1_request, GetNonProductAccountsV1_response, } from './v1/accounts.js';
3
+ import { ChainHeadBodyV1_request, ChainHeadBodyV1_response, ChainHeadCallV1_request, ChainHeadCallV1_response, ChainHeadContinueV1_request, ChainHeadContinueV1_response, ChainHeadFollowV1_receive, ChainHeadFollowV1_start, ChainHeadHeaderV1_request, ChainHeadHeaderV1_response, ChainHeadStopOperationV1_request, ChainHeadStopOperationV1_response, ChainHeadStorageV1_request, ChainHeadStorageV1_response, ChainHeadUnpinV1_request, ChainHeadUnpinV1_response, ChainSpecChainNameV1_request, ChainSpecChainNameV1_response, ChainSpecGenesisHashV1_request, ChainSpecGenesisHashV1_response, ChainSpecPropertiesV1_request, ChainSpecPropertiesV1_response, TransactionBroadcastV1_request, TransactionBroadcastV1_response, TransactionStopV1_request, TransactionStopV1_response, } from './v1/chainInteraction.js';
3
4
  import { ChatActionSubscribeV1_receive, ChatActionSubscribeV1_start, ChatCreateRoomV1_request, ChatCreateRoomV1_response, ChatCustomMessageRenderingV1_receive, ChatCustomMessageRenderingV1_start, ChatListSubscribeV1_receive, ChatListSubscribeV1_start, ChatPostMessageV1_request, ChatPostMessageV1_response, ChatRegisterBotV1_request, ChatRegisterBotV1_response, } from './v1/chat.js';
4
5
  import { CreateTransactionV1_request, CreateTransactionV1_response, CreateTransactionWithNonProductAccountV1_request, CreateTransactionWithNonProductAccountV1_response, } from './v1/createTransaction.js';
5
6
  import { DevicePermissionV1_request, DevicePermissionV1_response } from './v1/devicePermission.js';
@@ -126,11 +127,51 @@ export const hostApiProtocol = {
126
127
  remote_preimage_submit: versionedRequest({
127
128
  v1: [PreimageSubmitV1_request, PreimageSubmitV1_response],
128
129
  }),
129
- // json rpc (temporary, kept until chain methods are added)
130
+ // json rpc (deprecated: use remote_chain_* methods instead)
130
131
  host_jsonrpc_message_send: versionedRequest({
131
132
  v1: [JsonRpcMessageSendV1_request, JsonRpcMessageSendV1_response],
132
133
  }),
133
134
  host_jsonrpc_message_subscribe: versionedSubscription({
134
135
  v1: [JsonRpcMessageSubscribeV1_start, JsonRpcMessageSubscribeV1_receive],
135
136
  }),
137
+ // chain interaction (remote namespace)
138
+ remote_chain_head_follow: versionedSubscription({
139
+ v1: [ChainHeadFollowV1_start, ChainHeadFollowV1_receive],
140
+ }),
141
+ remote_chain_head_header: versionedRequest({
142
+ v1: [ChainHeadHeaderV1_request, ChainHeadHeaderV1_response],
143
+ }),
144
+ remote_chain_head_body: versionedRequest({
145
+ v1: [ChainHeadBodyV1_request, ChainHeadBodyV1_response],
146
+ }),
147
+ remote_chain_head_storage: versionedRequest({
148
+ v1: [ChainHeadStorageV1_request, ChainHeadStorageV1_response],
149
+ }),
150
+ remote_chain_head_call: versionedRequest({
151
+ v1: [ChainHeadCallV1_request, ChainHeadCallV1_response],
152
+ }),
153
+ remote_chain_head_unpin: versionedRequest({
154
+ v1: [ChainHeadUnpinV1_request, ChainHeadUnpinV1_response],
155
+ }),
156
+ remote_chain_head_continue: versionedRequest({
157
+ v1: [ChainHeadContinueV1_request, ChainHeadContinueV1_response],
158
+ }),
159
+ remote_chain_head_stop_operation: versionedRequest({
160
+ v1: [ChainHeadStopOperationV1_request, ChainHeadStopOperationV1_response],
161
+ }),
162
+ remote_chain_spec_genesis_hash: versionedRequest({
163
+ v1: [ChainSpecGenesisHashV1_request, ChainSpecGenesisHashV1_response],
164
+ }),
165
+ remote_chain_spec_chain_name: versionedRequest({
166
+ v1: [ChainSpecChainNameV1_request, ChainSpecChainNameV1_response],
167
+ }),
168
+ remote_chain_spec_properties: versionedRequest({
169
+ v1: [ChainSpecPropertiesV1_request, ChainSpecPropertiesV1_response],
170
+ }),
171
+ remote_chain_transaction_broadcast: versionedRequest({
172
+ v1: [TransactionBroadcastV1_request, TransactionBroadcastV1_response],
173
+ }),
174
+ remote_chain_transaction_stop: versionedRequest({
175
+ v1: [TransactionStopV1_request, TransactionStopV1_response],
176
+ }),
136
177
  };