@xyo-network/xl1-rpc 1.8.1 → 1.8.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/neutral/index.mjs +28 -77
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/provider/provider/{RpcXyoConnection.d.ts → HttpRpcXyoConnection.d.ts} +7 -2
- package/dist/neutral/provider/provider/HttpRpcXyoConnection.d.ts.map +1 -0
- package/dist/neutral/provider/provider/index.d.ts +1 -3
- package/dist/neutral/provider/provider/index.d.ts.map +1 -1
- package/dist/neutral/transport/post-message/PostMessageRpcTransport.d.ts +1 -0
- package/dist/neutral/transport/post-message/PostMessageRpcTransport.d.ts.map +1 -1
- package/dist/neutral/transport/post-message/SessionEnvelope.d.ts +1 -0
- package/dist/neutral/transport/post-message/SessionEnvelope.d.ts.map +1 -1
- package/dist/neutral/transport/post-message/helpers.d.ts +3 -0
- package/dist/neutral/transport/post-message/helpers.d.ts.map +1 -1
- package/dist/node/index-node.mjs +155 -206
- package/dist/node/index-node.mjs.map +1 -1
- package/dist/node/provider/provider/{RpcXyoConnection.d.ts → HttpRpcXyoConnection.d.ts} +7 -2
- package/dist/node/provider/provider/HttpRpcXyoConnection.d.ts.map +1 -0
- package/dist/node/provider/provider/index.d.ts +1 -3
- package/dist/node/provider/provider/index.d.ts.map +1 -1
- package/dist/node/transport/post-message/PostMessageRpcTransport.d.ts +1 -0
- package/dist/node/transport/post-message/PostMessageRpcTransport.d.ts.map +1 -1
- package/dist/node/transport/post-message/SessionEnvelope.d.ts +1 -0
- package/dist/node/transport/post-message/SessionEnvelope.d.ts.map +1 -1
- package/dist/node/transport/post-message/helpers.d.ts +3 -0
- package/dist/node/transport/post-message/helpers.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/provider/provider/HttpRpcXyoConnection.ts +32 -0
- package/src/provider/provider/index.ts +1 -3
- package/src/transport/post-message/PostMessageRpcTransport.ts +1 -0
- package/src/transport/post-message/SessionEnvelope.ts +1 -0
- package/src/transport/post-message/helpers.ts +3 -0
- package/dist/neutral/provider/provider/RpcXyoConnection.d.ts.map +0 -1
- package/dist/neutral/provider/provider/confirmSubmittedTransaction.d.ts +0 -21
- package/dist/neutral/provider/provider/confirmSubmittedTransaction.d.ts.map +0 -1
- package/dist/neutral/provider/provider/confirmTransaction.d.ts +0 -4
- package/dist/neutral/provider/provider/confirmTransaction.d.ts.map +0 -1
- package/dist/node/provider/provider/RpcXyoConnection.d.ts.map +0 -1
- package/dist/node/provider/provider/confirmSubmittedTransaction.d.ts +0 -21
- package/dist/node/provider/provider/confirmSubmittedTransaction.d.ts.map +0 -1
- package/dist/node/provider/provider/confirmTransaction.d.ts +0 -4
- package/dist/node/provider/provider/confirmTransaction.d.ts.map +0 -1
- package/src/provider/provider/RpcXyoConnection.ts +0 -26
- package/src/provider/provider/confirmSubmittedTransaction.ts +0 -55
- package/src/provider/provider/confirmTransaction.ts +0 -37
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/transport/post-message/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG;IAClD,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/transport/post-message/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,oEAAoE;AACpE,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG;IAClD,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,oEAAoE;AACpE,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,oEAAoE;AAEpE,eAAO,MAAM,UAAU,GAAI,MAAM,GAAG,KAAG,IAAI,IAAI,QAO9C,CAAA"}
|
package/dist/node/index-node.mjs
CHANGED
|
@@ -928,64 +928,151 @@ var MemoryXyoNetwork = class {
|
|
|
928
928
|
}
|
|
929
929
|
};
|
|
930
930
|
|
|
931
|
-
// src/provider/provider/
|
|
932
|
-
import {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
931
|
+
// src/provider/provider/HttpRpcXyoConnection.ts
|
|
932
|
+
import { isDefined as isDefined2 } from "@xylabs/typeof";
|
|
933
|
+
|
|
934
|
+
// src/transport/HttpRpcTransport.ts
|
|
935
|
+
import { AxiosJson } from "@xylabs/axios";
|
|
936
|
+
import { isError, isUndefinedOrNull } from "@xylabs/typeof";
|
|
937
|
+
import { isAxiosError } from "axios";
|
|
938
|
+
import { v4 } from "uuid";
|
|
939
|
+
var HttpRpcTransport = class {
|
|
940
|
+
static {
|
|
941
|
+
__name(this, "HttpRpcTransport");
|
|
942
|
+
}
|
|
943
|
+
_rpcUrl;
|
|
944
|
+
_schemas;
|
|
945
|
+
constructor(rpcUrl, schemas) {
|
|
946
|
+
this._rpcUrl = rpcUrl;
|
|
947
|
+
this._schemas = schemas;
|
|
948
|
+
}
|
|
949
|
+
async sendRequest(method, params) {
|
|
950
|
+
return await this.callRpc(this._rpcUrl, this._schemas, method, params);
|
|
951
|
+
}
|
|
952
|
+
async callRpc(url, schemas, method, params) {
|
|
953
|
+
try {
|
|
954
|
+
const id = v4();
|
|
955
|
+
const body = {
|
|
956
|
+
jsonrpc,
|
|
957
|
+
id,
|
|
958
|
+
method
|
|
959
|
+
};
|
|
960
|
+
if (params) {
|
|
961
|
+
body.params = schemas[method].params.to.parse(params);
|
|
962
|
+
}
|
|
963
|
+
const res = await new AxiosJson().post(url, body);
|
|
964
|
+
const json = res.data;
|
|
965
|
+
if (isUndefinedOrNull(json) || json.error) {
|
|
966
|
+
throw new Error(json.error.message);
|
|
955
967
|
}
|
|
968
|
+
return schemas[method].result.from.parse(json.result);
|
|
969
|
+
} catch (ex) {
|
|
970
|
+
let message = isError(ex) ? ex.message : String(ex);
|
|
971
|
+
if (isAxiosError(ex)) {
|
|
972
|
+
message = `Http error occurred [${ex.status}|${ex.code ?? "<unknown>"}]: ${ex.message}`;
|
|
973
|
+
}
|
|
974
|
+
throw new Error(`Error occurred while calling RPC method ${String(method)}: ${message}`);
|
|
956
975
|
}
|
|
957
976
|
}
|
|
958
|
-
}
|
|
977
|
+
};
|
|
959
978
|
|
|
960
|
-
// src/
|
|
961
|
-
import {
|
|
962
|
-
import {
|
|
963
|
-
var
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
979
|
+
// src/transport/MemoryRpcTransport.ts
|
|
980
|
+
import { isObject } from "@xylabs/typeof";
|
|
981
|
+
import { v4 as v42 } from "uuid";
|
|
982
|
+
var MemoryRpcTransport = class {
|
|
983
|
+
static {
|
|
984
|
+
__name(this, "MemoryRpcTransport");
|
|
985
|
+
}
|
|
986
|
+
_rpcEngine;
|
|
987
|
+
_schemas;
|
|
988
|
+
requestSchemas = {};
|
|
989
|
+
responseSchemas = {};
|
|
990
|
+
constructor(rpcEngine, schemas = AllRpcSchemas) {
|
|
991
|
+
this._rpcEngine = rpcEngine;
|
|
992
|
+
this._schemas = schemas;
|
|
993
|
+
}
|
|
994
|
+
async sendRequest(method, params) {
|
|
995
|
+
const schema = this._schemas[method];
|
|
996
|
+
let requestSchema = this.requestSchemas[method];
|
|
997
|
+
if (!isObject(requestSchema)) {
|
|
998
|
+
requestSchema = createRequestSchema(method, schema.params.to);
|
|
999
|
+
this.requestSchemas[method] = requestSchema;
|
|
1000
|
+
}
|
|
1001
|
+
const req = {
|
|
1002
|
+
jsonrpc,
|
|
1003
|
+
id: v42(),
|
|
1004
|
+
method,
|
|
1005
|
+
params
|
|
1006
|
+
};
|
|
1007
|
+
const request = requestSchema.parse(req);
|
|
1008
|
+
const response = await this._rpcEngine.handle(request);
|
|
1009
|
+
let responseSchema = this.responseSchemas[method];
|
|
1010
|
+
if (!isObject(responseSchema)) {
|
|
1011
|
+
responseSchema = createResponseSchema(schema.result.from);
|
|
1012
|
+
this.responseSchemas[method] = responseSchema;
|
|
986
1013
|
}
|
|
1014
|
+
return responseSchema.parse(response)?.result;
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
// src/transport/post-message/PostMessageRpcTransport.ts
|
|
1019
|
+
import { isDefined } from "@xylabs/typeof";
|
|
1020
|
+
import { v4 as v43 } from "uuid";
|
|
1021
|
+
|
|
1022
|
+
// src/transport/post-message/helpers.ts
|
|
1023
|
+
var isRpcError = /* @__PURE__ */ __name((data) => {
|
|
1024
|
+
return data && typeof data === "object" && "error" in data && data.error;
|
|
1025
|
+
}, "isRpcError");
|
|
1026
|
+
|
|
1027
|
+
// src/transport/post-message/SessionEnvelope.ts
|
|
1028
|
+
var buildSessionMessageRequest = /* @__PURE__ */ __name((data, destination) => {
|
|
1029
|
+
const request = {
|
|
1030
|
+
data,
|
|
1031
|
+
destination,
|
|
1032
|
+
sessionId: globalThis.xyo.walletExtensionId() ?? ""
|
|
1033
|
+
};
|
|
1034
|
+
return request;
|
|
1035
|
+
}, "buildSessionMessageRequest");
|
|
1036
|
+
|
|
1037
|
+
// src/transport/post-message/PostMessageRpcTransport.ts
|
|
1038
|
+
var PostMessageRpcTransport = class {
|
|
1039
|
+
static {
|
|
1040
|
+
__name(this, "PostMessageRpcTransport");
|
|
1041
|
+
}
|
|
1042
|
+
destination;
|
|
1043
|
+
schemas;
|
|
1044
|
+
constructor(defaultDestination, schemas = XyoGatewayRpcSchemas) {
|
|
1045
|
+
this.schemas = schemas;
|
|
1046
|
+
this.destination = defaultDestination;
|
|
1047
|
+
}
|
|
1048
|
+
async sendRequest(method, params) {
|
|
1049
|
+
const id = v43();
|
|
1050
|
+
return await this.callRpc(this.schemas, method, id, params);
|
|
1051
|
+
}
|
|
1052
|
+
async callRpc(schemas, method, id, params) {
|
|
1053
|
+
const body = {
|
|
1054
|
+
jsonrpc,
|
|
1055
|
+
id,
|
|
1056
|
+
method
|
|
1057
|
+
};
|
|
1058
|
+
body.params = isDefined(params) && isDefined(schemas[method]) ? schemas[method].params.to.parse(params) : params;
|
|
1059
|
+
return await new Promise((resolve, reject) => {
|
|
1060
|
+
const id2 = body.id;
|
|
1061
|
+
const handler = /* @__PURE__ */ __name((event) => {
|
|
1062
|
+
if (event.origin !== globalThis.window.origin) return;
|
|
1063
|
+
if (event.data.id !== id2) return;
|
|
1064
|
+
globalThis.removeEventListener("message", handler);
|
|
1065
|
+
if (event.data.result.some(isRpcError)) {
|
|
1066
|
+
reject(event.data.result[0]);
|
|
1067
|
+
} else {
|
|
1068
|
+
resolve(event.data.result[0]);
|
|
1069
|
+
}
|
|
1070
|
+
}, "handler");
|
|
1071
|
+
globalThis.addEventListener("message", handler);
|
|
1072
|
+
globalThis.postMessage(buildSessionMessageRequest(body, this.destination), globalThis.location.origin);
|
|
1073
|
+
});
|
|
987
1074
|
}
|
|
988
|
-
}
|
|
1075
|
+
};
|
|
989
1076
|
|
|
990
1077
|
// src/provider/runner/JsonRpcXyoRunner.ts
|
|
991
1078
|
var JsonRpcXyoRunner = class {
|
|
@@ -1005,7 +1092,7 @@ var JsonRpcXyoRunner = class {
|
|
|
1005
1092
|
|
|
1006
1093
|
// src/provider/runner/MemoryXyoRunner.ts
|
|
1007
1094
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
1008
|
-
import { PayloadBuilder
|
|
1095
|
+
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
1009
1096
|
import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
|
|
1010
1097
|
var MemoryXyoRunner = class {
|
|
1011
1098
|
static {
|
|
@@ -1015,7 +1102,7 @@ var MemoryXyoRunner = class {
|
|
|
1015
1102
|
async broadcastTransaction(transaction) {
|
|
1016
1103
|
const archivist = await this.getArchivist();
|
|
1017
1104
|
await archivist.insert(flattenHydratedTransaction(transaction));
|
|
1018
|
-
return await
|
|
1105
|
+
return await PayloadBuilder.hash(transaction[0]);
|
|
1019
1106
|
}
|
|
1020
1107
|
async getArchivist() {
|
|
1021
1108
|
if (!this._archivist) {
|
|
@@ -1030,7 +1117,7 @@ var MemoryXyoRunner = class {
|
|
|
1030
1117
|
// src/provider/runner/NodeXyoRunner.ts
|
|
1031
1118
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
1032
1119
|
import { asArchivistInstance } from "@xyo-network/archivist-model";
|
|
1033
|
-
import { PayloadBuilder as
|
|
1120
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
1034
1121
|
import { PayloadBundleSchema } from "@xyo-network/payload-model";
|
|
1035
1122
|
import { flattenHydratedTransaction as flattenHydratedTransaction2 } from "@xyo-network/xl1-protocol-sdk";
|
|
1036
1123
|
var NodeXyoRunner = class {
|
|
@@ -1047,7 +1134,7 @@ var NodeXyoRunner = class {
|
|
|
1047
1134
|
async broadcastTransaction(transaction) {
|
|
1048
1135
|
const flattened = flattenHydratedTransaction2(transaction);
|
|
1049
1136
|
const pendingArchivist = await this.getPendingArchivist();
|
|
1050
|
-
const txHash = await
|
|
1137
|
+
const txHash = await PayloadBuilder2.hash(transaction[0]);
|
|
1051
1138
|
const payloadBundle = {
|
|
1052
1139
|
schema: PayloadBundleSchema,
|
|
1053
1140
|
payloads: flattened,
|
|
@@ -1193,7 +1280,7 @@ var JsonRpcXyoViewer = class {
|
|
|
1193
1280
|
|
|
1194
1281
|
// src/provider/provider/XyoConnection.ts
|
|
1195
1282
|
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
1196
|
-
import { PayloadBuilder as
|
|
1283
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
1197
1284
|
import { isAnyPayload } from "@xyo-network/payload-model";
|
|
1198
1285
|
import { defaultTransactionFees, isDataLakeProvider } from "@xyo-network/xl1-protocol";
|
|
1199
1286
|
import { HydratedTransactionWrapper } from "@xyo-network/xl1-wrappers";
|
|
@@ -1252,8 +1339,8 @@ var XyoConnection = class {
|
|
|
1252
1339
|
if (fromResolved === void 0) throw new Error("Failed to determine from address");
|
|
1253
1340
|
const signedTransaction = assertEx3(await signer.createSignedTransaction(chainResolved, elevatedPayloads, additionalPayloads, nbfResolved, expResolved, feesResolved, fromResolved), () => "Failed to create transaction");
|
|
1254
1341
|
const hydratedTransaction = [
|
|
1255
|
-
await
|
|
1256
|
-
await
|
|
1342
|
+
await PayloadBuilder3.addStorageMeta(signedTransaction),
|
|
1343
|
+
await PayloadBuilder3.addStorageMeta(elevatedPayloads)
|
|
1257
1344
|
];
|
|
1258
1345
|
if (isDataLakeProvider(storage)) {
|
|
1259
1346
|
const wrapper = await HydratedTransactionWrapper.parse(hydratedTransaction);
|
|
@@ -1264,17 +1351,18 @@ var XyoConnection = class {
|
|
|
1264
1351
|
}
|
|
1265
1352
|
};
|
|
1266
1353
|
|
|
1267
|
-
// src/provider/provider/
|
|
1268
|
-
var
|
|
1354
|
+
// src/provider/provider/HttpRpcXyoConnection.ts
|
|
1355
|
+
var HttpRpcXyoConnection = class extends XyoConnection {
|
|
1269
1356
|
static {
|
|
1270
|
-
__name(this, "
|
|
1357
|
+
__name(this, "HttpRpcXyoConnection");
|
|
1271
1358
|
}
|
|
1272
1359
|
constructor(params) {
|
|
1273
|
-
const
|
|
1360
|
+
const { account, endpoint } = params;
|
|
1361
|
+
const signer = isDefined2(account) ? new MemoryXyoSigner(account) : void 0;
|
|
1362
|
+
const transport = new HttpRpcTransport(endpoint, {
|
|
1274
1363
|
...XyoRunnerRpcSchemas,
|
|
1275
1364
|
...XyoViewerRpcSchemas
|
|
1276
1365
|
});
|
|
1277
|
-
const signer = params.account ? new MemoryXyoSigner(params.account) : void 0;
|
|
1278
1366
|
const runner = new JsonRpcXyoRunner(transport);
|
|
1279
1367
|
const viewer = new JsonRpcXyoViewer(transport);
|
|
1280
1368
|
super({
|
|
@@ -1284,147 +1372,9 @@ var RpcXyoConnection = class extends XyoConnection {
|
|
|
1284
1372
|
});
|
|
1285
1373
|
}
|
|
1286
1374
|
};
|
|
1287
|
-
|
|
1288
|
-
// src/transport/HttpRpcTransport.ts
|
|
1289
|
-
import { AxiosJson } from "@xylabs/axios";
|
|
1290
|
-
import { isError, isUndefinedOrNull } from "@xylabs/typeof";
|
|
1291
|
-
import { isAxiosError } from "axios";
|
|
1292
|
-
import { v4 } from "uuid";
|
|
1293
|
-
var HttpRpcTransport = class {
|
|
1294
|
-
static {
|
|
1295
|
-
__name(this, "HttpRpcTransport");
|
|
1296
|
-
}
|
|
1297
|
-
_rpcUrl;
|
|
1298
|
-
_schemas;
|
|
1299
|
-
constructor(rpcUrl, schemas) {
|
|
1300
|
-
this._rpcUrl = rpcUrl;
|
|
1301
|
-
this._schemas = schemas;
|
|
1302
|
-
}
|
|
1303
|
-
async sendRequest(method, params) {
|
|
1304
|
-
return await this.callRpc(this._rpcUrl, this._schemas, method, params);
|
|
1305
|
-
}
|
|
1306
|
-
async callRpc(url, schemas, method, params) {
|
|
1307
|
-
try {
|
|
1308
|
-
const id = v4();
|
|
1309
|
-
const body = {
|
|
1310
|
-
jsonrpc,
|
|
1311
|
-
id,
|
|
1312
|
-
method
|
|
1313
|
-
};
|
|
1314
|
-
if (params) {
|
|
1315
|
-
body.params = schemas[method].params.to.parse(params);
|
|
1316
|
-
}
|
|
1317
|
-
const res = await new AxiosJson().post(url, body);
|
|
1318
|
-
const json = res.data;
|
|
1319
|
-
if (isUndefinedOrNull(json) || json.error) {
|
|
1320
|
-
throw new Error(json.error.message);
|
|
1321
|
-
}
|
|
1322
|
-
return schemas[method].result.from.parse(json.result);
|
|
1323
|
-
} catch (ex) {
|
|
1324
|
-
let message = isError(ex) ? ex.message : String(ex);
|
|
1325
|
-
if (isAxiosError(ex)) {
|
|
1326
|
-
message = `Http error occurred [${ex.status}|${ex.code ?? "<unknown>"}]: ${ex.message}`;
|
|
1327
|
-
}
|
|
1328
|
-
throw new Error(`Error occurred while calling RPC method ${String(method)}: ${message}`);
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
};
|
|
1332
|
-
|
|
1333
|
-
// src/transport/MemoryRpcTransport.ts
|
|
1334
|
-
import { isObject } from "@xylabs/typeof";
|
|
1335
|
-
import { v4 as v42 } from "uuid";
|
|
1336
|
-
var MemoryRpcTransport = class {
|
|
1337
|
-
static {
|
|
1338
|
-
__name(this, "MemoryRpcTransport");
|
|
1339
|
-
}
|
|
1340
|
-
_rpcEngine;
|
|
1341
|
-
_schemas;
|
|
1342
|
-
requestSchemas = {};
|
|
1343
|
-
responseSchemas = {};
|
|
1344
|
-
constructor(rpcEngine, schemas = AllRpcSchemas) {
|
|
1345
|
-
this._rpcEngine = rpcEngine;
|
|
1346
|
-
this._schemas = schemas;
|
|
1347
|
-
}
|
|
1348
|
-
async sendRequest(method, params) {
|
|
1349
|
-
const schema = this._schemas[method];
|
|
1350
|
-
let requestSchema = this.requestSchemas[method];
|
|
1351
|
-
if (!isObject(requestSchema)) {
|
|
1352
|
-
requestSchema = createRequestSchema(method, schema.params.to);
|
|
1353
|
-
this.requestSchemas[method] = requestSchema;
|
|
1354
|
-
}
|
|
1355
|
-
const req = {
|
|
1356
|
-
jsonrpc,
|
|
1357
|
-
id: v42(),
|
|
1358
|
-
method,
|
|
1359
|
-
params
|
|
1360
|
-
};
|
|
1361
|
-
const request = requestSchema.parse(req);
|
|
1362
|
-
const response = await this._rpcEngine.handle(request);
|
|
1363
|
-
let responseSchema = this.responseSchemas[method];
|
|
1364
|
-
if (!isObject(responseSchema)) {
|
|
1365
|
-
responseSchema = createResponseSchema(schema.result.from);
|
|
1366
|
-
this.responseSchemas[method] = responseSchema;
|
|
1367
|
-
}
|
|
1368
|
-
return responseSchema.parse(response)?.result;
|
|
1369
|
-
}
|
|
1370
|
-
};
|
|
1371
|
-
|
|
1372
|
-
// src/transport/post-message/PostMessageRpcTransport.ts
|
|
1373
|
-
import { isDefined as isDefined2 } from "@xylabs/typeof";
|
|
1374
|
-
import { v4 as v43 } from "uuid";
|
|
1375
|
-
|
|
1376
|
-
// src/transport/post-message/helpers.ts
|
|
1377
|
-
var isRpcError = /* @__PURE__ */ __name((data) => {
|
|
1378
|
-
return data && typeof data === "object" && "error" in data && data.error;
|
|
1379
|
-
}, "isRpcError");
|
|
1380
|
-
|
|
1381
|
-
// src/transport/post-message/SessionEnvelope.ts
|
|
1382
|
-
var buildSessionMessageRequest = /* @__PURE__ */ __name((data, destination) => {
|
|
1383
|
-
const request = {
|
|
1384
|
-
data,
|
|
1385
|
-
destination,
|
|
1386
|
-
sessionId: globalThis.xyo.walletExtensionId() ?? ""
|
|
1387
|
-
};
|
|
1388
|
-
return request;
|
|
1389
|
-
}, "buildSessionMessageRequest");
|
|
1390
|
-
|
|
1391
|
-
// src/transport/post-message/PostMessageRpcTransport.ts
|
|
1392
|
-
var PostMessageRpcTransport = class {
|
|
1375
|
+
var RpcXyoConnection = class extends HttpRpcXyoConnection {
|
|
1393
1376
|
static {
|
|
1394
|
-
__name(this, "
|
|
1395
|
-
}
|
|
1396
|
-
destination;
|
|
1397
|
-
schemas;
|
|
1398
|
-
constructor(defaultDestination, schemas = XyoGatewayRpcSchemas) {
|
|
1399
|
-
this.schemas = schemas;
|
|
1400
|
-
this.destination = defaultDestination;
|
|
1401
|
-
}
|
|
1402
|
-
async sendRequest(method, params) {
|
|
1403
|
-
const id = v43();
|
|
1404
|
-
return await this.callRpc(this.schemas, method, id, params);
|
|
1405
|
-
}
|
|
1406
|
-
async callRpc(schemas, method, id, params) {
|
|
1407
|
-
const body = {
|
|
1408
|
-
jsonrpc,
|
|
1409
|
-
id,
|
|
1410
|
-
method
|
|
1411
|
-
};
|
|
1412
|
-
body.params = isDefined2(params) && isDefined2(schemas[method]) ? schemas[method].params.to.parse(params) : params;
|
|
1413
|
-
return await new Promise((resolve, reject) => {
|
|
1414
|
-
const id2 = body.id;
|
|
1415
|
-
const handler = /* @__PURE__ */ __name((event) => {
|
|
1416
|
-
if (event.origin !== globalThis.window.origin) return;
|
|
1417
|
-
if (event.data.id !== id2) return;
|
|
1418
|
-
globalThis.removeEventListener("message", handler);
|
|
1419
|
-
if (event.data.result.some(isRpcError)) {
|
|
1420
|
-
reject(event.data.result[0]);
|
|
1421
|
-
} else {
|
|
1422
|
-
resolve(event.data.result[0]);
|
|
1423
|
-
}
|
|
1424
|
-
}, "handler");
|
|
1425
|
-
globalThis.addEventListener("message", handler);
|
|
1426
|
-
globalThis.postMessage(buildSessionMessageRequest(body, this.destination), globalThis.location.origin);
|
|
1427
|
-
});
|
|
1377
|
+
__name(this, "RpcXyoConnection");
|
|
1428
1378
|
}
|
|
1429
1379
|
};
|
|
1430
1380
|
export {
|
|
@@ -1434,6 +1384,7 @@ export {
|
|
|
1434
1384
|
CaveatsSchema,
|
|
1435
1385
|
ChainConnectionSchema,
|
|
1436
1386
|
HttpRpcTransport,
|
|
1387
|
+
HttpRpcXyoConnection,
|
|
1437
1388
|
InvokerPermissionSchema,
|
|
1438
1389
|
JsonRpcErrorCodes,
|
|
1439
1390
|
JsonRpcXyoRunner,
|
|
@@ -1458,8 +1409,6 @@ export {
|
|
|
1458
1409
|
XyoSignerRpcSchemas,
|
|
1459
1410
|
XyoViewerRpcSchemas,
|
|
1460
1411
|
buildSessionMessageRequest,
|
|
1461
|
-
confirmSubmittedTransaction,
|
|
1462
|
-
confirmTransaction,
|
|
1463
1412
|
createRequestSchema,
|
|
1464
1413
|
createResponseSchema,
|
|
1465
1414
|
getPermissionsStoreFromTransport,
|