@novasamatech/host-container 0.5.0-16 → 0.5.0-17
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/createContainer.d.ts +2 -2
- package/dist/createContainer.js +15 -13
- package/package.json +2 -2
|
@@ -11,14 +11,14 @@ type ContainerHandlers = {
|
|
|
11
11
|
signPayload(payload: SignerPayloadJSON): Promise<SignerResult>;
|
|
12
12
|
createTransaction(payload: TxPayloadV1): Promise<HexString>;
|
|
13
13
|
};
|
|
14
|
-
chainSupport(
|
|
14
|
+
chainSupport(genesisHash: HexString): Promise<boolean>;
|
|
15
15
|
};
|
|
16
16
|
type Params = {
|
|
17
17
|
handshakeTimeout: number;
|
|
18
18
|
};
|
|
19
19
|
export type Container = ReturnType<typeof createContainer>;
|
|
20
20
|
export declare function createContainer(provider: TransportProvider, params?: Params): {
|
|
21
|
-
connectToPapiProvider(
|
|
21
|
+
connectToPapiProvider(genesisHash: HexString, provider: JsonRpcProvider): VoidFunction;
|
|
22
22
|
handleAccounts(handler: ContainerHandlers["accounts"]): void;
|
|
23
23
|
handleSignRequest(handler: ContainerHandlers["sign"]): void;
|
|
24
24
|
handleChainSupportCheck(handler: ContainerHandlers["chainSupport"]): void;
|
package/dist/createContainer.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { createTransport } from '@novasamatech/host-api';
|
|
2
2
|
import { createComplexSubscriber } from './createComplexSubscriber.js';
|
|
3
|
+
function errorToString(e) {
|
|
4
|
+
return e instanceof Error ? e.message : typeof e === 'string' ? e : 'Unknown error';
|
|
5
|
+
}
|
|
3
6
|
function formatOk(value) {
|
|
4
|
-
return {
|
|
7
|
+
return { success: true, value };
|
|
5
8
|
}
|
|
6
9
|
function formatErr(e) {
|
|
7
|
-
|
|
8
|
-
return { tag: 'Err', value: message };
|
|
10
|
+
return { success: false, value: e };
|
|
9
11
|
}
|
|
10
12
|
const defaultHandlers = {
|
|
11
13
|
accounts: {
|
|
@@ -40,7 +42,7 @@ export function createContainer(provider, params) {
|
|
|
40
42
|
catch (e) {
|
|
41
43
|
return {
|
|
42
44
|
tag: 'getAccountsResponseV1',
|
|
43
|
-
value: formatErr(e),
|
|
45
|
+
value: formatErr(errorToString(e)),
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
48
|
});
|
|
@@ -75,7 +77,7 @@ export function createContainer(provider, params) {
|
|
|
75
77
|
catch (e) {
|
|
76
78
|
return {
|
|
77
79
|
tag: 'signResponseV1',
|
|
78
|
-
value: formatErr(e),
|
|
80
|
+
value: formatErr(errorToString(e)),
|
|
79
81
|
};
|
|
80
82
|
}
|
|
81
83
|
});
|
|
@@ -91,7 +93,7 @@ export function createContainer(provider, params) {
|
|
|
91
93
|
catch (e) {
|
|
92
94
|
return {
|
|
93
95
|
tag: 'signResponseV1',
|
|
94
|
-
value: formatErr(e),
|
|
96
|
+
value: formatErr(errorToString(e)),
|
|
95
97
|
};
|
|
96
98
|
}
|
|
97
99
|
});
|
|
@@ -107,7 +109,7 @@ export function createContainer(provider, params) {
|
|
|
107
109
|
catch (e) {
|
|
108
110
|
return {
|
|
109
111
|
tag: 'createTransactionResponseV1',
|
|
110
|
-
value: formatErr(e),
|
|
112
|
+
value: formatErr(errorToString(e)),
|
|
111
113
|
};
|
|
112
114
|
}
|
|
113
115
|
});
|
|
@@ -116,16 +118,16 @@ export function createContainer(provider, params) {
|
|
|
116
118
|
if (message.tag === 'chain') {
|
|
117
119
|
try {
|
|
118
120
|
const checkChainSupport = externalHandlers.chainSupport ?? defaultHandlers.chainSupport;
|
|
119
|
-
const result = await checkChainSupport(message.value.
|
|
121
|
+
const result = await checkChainSupport(message.value.genesisHash);
|
|
120
122
|
return {
|
|
121
123
|
tag: 'supportFeatureResponseV1',
|
|
122
|
-
value: formatOk({ tag: 'chain', value: {
|
|
124
|
+
value: formatOk({ tag: 'chain', value: { genesisHash: message.value.genesisHash, result } }),
|
|
123
125
|
};
|
|
124
126
|
}
|
|
125
127
|
catch (e) {
|
|
126
128
|
return {
|
|
127
129
|
tag: 'supportFeatureResponseV1',
|
|
128
|
-
value: formatErr(e),
|
|
130
|
+
value: formatErr(errorToString(e)),
|
|
129
131
|
};
|
|
130
132
|
}
|
|
131
133
|
}
|
|
@@ -135,7 +137,7 @@ export function createContainer(provider, params) {
|
|
|
135
137
|
transport.isReady();
|
|
136
138
|
}
|
|
137
139
|
return {
|
|
138
|
-
connectToPapiProvider(
|
|
140
|
+
connectToPapiProvider(genesisHash, provider) {
|
|
139
141
|
init();
|
|
140
142
|
let connection = null;
|
|
141
143
|
return transport.handleMessage('papiProviderSendMessageV1', async (message) => {
|
|
@@ -143,11 +145,11 @@ export function createContainer(provider, params) {
|
|
|
143
145
|
connection = provider(message => {
|
|
144
146
|
transport.postMessage('_', {
|
|
145
147
|
tag: 'papiProviderReceiveMessageV1',
|
|
146
|
-
value: {
|
|
148
|
+
value: formatOk({ genesisHash, message }),
|
|
147
149
|
});
|
|
148
150
|
});
|
|
149
151
|
}
|
|
150
|
-
if (message.
|
|
152
|
+
if (message.genesisHash === genesisHash) {
|
|
151
153
|
connection.send(message.message);
|
|
152
154
|
}
|
|
153
155
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/host-container",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.0-
|
|
4
|
+
"version": "0.5.0-17",
|
|
5
5
|
"description": "Host container for hosting and managing products within the Polkadot ecosystem.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@polkadot-api/json-rpc-provider": "^0.0.4",
|
|
30
|
-
"@novasamatech/host-api": "0.5.0-
|
|
30
|
+
"@novasamatech/host-api": "0.5.0-17"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|