@xyo-network/xl1-rpc 1.8.1 → 1.8.2

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.
@@ -4,7 +4,12 @@ export interface RpcXyoProviderParams {
4
4
  account?: AccountInstance;
5
5
  endpoint: string;
6
6
  }
7
- export declare class RpcXyoConnection extends XyoConnection {
7
+ export declare class HttpRpcXyoConnection extends XyoConnection {
8
8
  constructor(params: RpcXyoProviderParams);
9
9
  }
10
- //# sourceMappingURL=RpcXyoConnection.d.ts.map
10
+ /**
11
+ * @deprecated Use `HttpRpcXyoConnection` instead.
12
+ */
13
+ export declare class RpcXyoConnection extends HttpRpcXyoConnection {
14
+ }
15
+ //# sourceMappingURL=HttpRpcXyoConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpRpcXyoConnection.d.ts","sourceRoot":"","sources":["../../../../src/provider/provider/HttpRpcXyoConnection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAOjE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,eAAe,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,qBAAa,oBAAqB,SAAQ,aAAa;gBACzC,MAAM,EAAE,oBAAoB;CAUzC;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,oBAAoB;CAAG"}
@@ -1,5 +1,5 @@
1
1
  export * from './confirmSubmittedTransaction.ts';
2
2
  export * from './confirmTransaction.ts';
3
- export * from './RpcXyoConnection.ts';
3
+ export * from './HttpRpcXyoConnection.ts';
4
4
  export * from './XyoConnection.ts';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/provider/provider/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAA;AAChD,cAAc,yBAAyB,CAAA;AACvC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/provider/provider/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAA;AAChD,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA"}
@@ -987,6 +987,152 @@ var confirmTransaction = /* @__PURE__ */ __name(async (provider, txBW, onConfirm
987
987
  }
988
988
  }, "confirmTransaction");
989
989
 
990
+ // src/provider/provider/HttpRpcXyoConnection.ts
991
+ import { isDefined as isDefined3 } from "@xylabs/typeof";
992
+
993
+ // src/transport/HttpRpcTransport.ts
994
+ import { AxiosJson } from "@xylabs/axios";
995
+ import { isError, isUndefinedOrNull } from "@xylabs/typeof";
996
+ import { isAxiosError } from "axios";
997
+ import { v4 } from "uuid";
998
+ var HttpRpcTransport = class {
999
+ static {
1000
+ __name(this, "HttpRpcTransport");
1001
+ }
1002
+ _rpcUrl;
1003
+ _schemas;
1004
+ constructor(rpcUrl, schemas) {
1005
+ this._rpcUrl = rpcUrl;
1006
+ this._schemas = schemas;
1007
+ }
1008
+ async sendRequest(method, params) {
1009
+ return await this.callRpc(this._rpcUrl, this._schemas, method, params);
1010
+ }
1011
+ async callRpc(url, schemas, method, params) {
1012
+ try {
1013
+ const id = v4();
1014
+ const body = {
1015
+ jsonrpc,
1016
+ id,
1017
+ method
1018
+ };
1019
+ if (params) {
1020
+ body.params = schemas[method].params.to.parse(params);
1021
+ }
1022
+ const res = await new AxiosJson().post(url, body);
1023
+ const json = res.data;
1024
+ if (isUndefinedOrNull(json) || json.error) {
1025
+ throw new Error(json.error.message);
1026
+ }
1027
+ return schemas[method].result.from.parse(json.result);
1028
+ } catch (ex) {
1029
+ let message = isError(ex) ? ex.message : String(ex);
1030
+ if (isAxiosError(ex)) {
1031
+ message = `Http error occurred [${ex.status}|${ex.code ?? "<unknown>"}]: ${ex.message}`;
1032
+ }
1033
+ throw new Error(`Error occurred while calling RPC method ${String(method)}: ${message}`);
1034
+ }
1035
+ }
1036
+ };
1037
+
1038
+ // src/transport/MemoryRpcTransport.ts
1039
+ import { isObject } from "@xylabs/typeof";
1040
+ import { v4 as v42 } from "uuid";
1041
+ var MemoryRpcTransport = class {
1042
+ static {
1043
+ __name(this, "MemoryRpcTransport");
1044
+ }
1045
+ _rpcEngine;
1046
+ _schemas;
1047
+ requestSchemas = {};
1048
+ responseSchemas = {};
1049
+ constructor(rpcEngine, schemas = AllRpcSchemas) {
1050
+ this._rpcEngine = rpcEngine;
1051
+ this._schemas = schemas;
1052
+ }
1053
+ async sendRequest(method, params) {
1054
+ const schema = this._schemas[method];
1055
+ let requestSchema = this.requestSchemas[method];
1056
+ if (!isObject(requestSchema)) {
1057
+ requestSchema = createRequestSchema(method, schema.params.to);
1058
+ this.requestSchemas[method] = requestSchema;
1059
+ }
1060
+ const req = {
1061
+ jsonrpc,
1062
+ id: v42(),
1063
+ method,
1064
+ params
1065
+ };
1066
+ const request = requestSchema.parse(req);
1067
+ const response = await this._rpcEngine.handle(request);
1068
+ let responseSchema = this.responseSchemas[method];
1069
+ if (!isObject(responseSchema)) {
1070
+ responseSchema = createResponseSchema(schema.result.from);
1071
+ this.responseSchemas[method] = responseSchema;
1072
+ }
1073
+ return responseSchema.parse(response)?.result;
1074
+ }
1075
+ };
1076
+
1077
+ // src/transport/post-message/PostMessageRpcTransport.ts
1078
+ import { isDefined as isDefined2 } from "@xylabs/typeof";
1079
+ import { v4 as v43 } from "uuid";
1080
+
1081
+ // src/transport/post-message/helpers.ts
1082
+ var isRpcError = /* @__PURE__ */ __name((data) => {
1083
+ return data && typeof data === "object" && "error" in data && data.error;
1084
+ }, "isRpcError");
1085
+
1086
+ // src/transport/post-message/SessionEnvelope.ts
1087
+ var buildSessionMessageRequest = /* @__PURE__ */ __name((data, destination) => {
1088
+ const request = {
1089
+ data,
1090
+ destination,
1091
+ sessionId: globalThis.xyo.walletExtensionId() ?? ""
1092
+ };
1093
+ return request;
1094
+ }, "buildSessionMessageRequest");
1095
+
1096
+ // src/transport/post-message/PostMessageRpcTransport.ts
1097
+ var PostMessageRpcTransport = class {
1098
+ static {
1099
+ __name(this, "PostMessageRpcTransport");
1100
+ }
1101
+ destination;
1102
+ schemas;
1103
+ constructor(defaultDestination, schemas = XyoGatewayRpcSchemas) {
1104
+ this.schemas = schemas;
1105
+ this.destination = defaultDestination;
1106
+ }
1107
+ async sendRequest(method, params) {
1108
+ const id = v43();
1109
+ return await this.callRpc(this.schemas, method, id, params);
1110
+ }
1111
+ async callRpc(schemas, method, id, params) {
1112
+ const body = {
1113
+ jsonrpc,
1114
+ id,
1115
+ method
1116
+ };
1117
+ body.params = isDefined2(params) && isDefined2(schemas[method]) ? schemas[method].params.to.parse(params) : params;
1118
+ return await new Promise((resolve, reject) => {
1119
+ const id2 = body.id;
1120
+ const handler = /* @__PURE__ */ __name((event) => {
1121
+ if (event.origin !== globalThis.window.origin) return;
1122
+ if (event.data.id !== id2) return;
1123
+ globalThis.removeEventListener("message", handler);
1124
+ if (event.data.result.some(isRpcError)) {
1125
+ reject(event.data.result[0]);
1126
+ } else {
1127
+ resolve(event.data.result[0]);
1128
+ }
1129
+ }, "handler");
1130
+ globalThis.addEventListener("message", handler);
1131
+ globalThis.postMessage(buildSessionMessageRequest(body, this.destination), globalThis.location.origin);
1132
+ });
1133
+ }
1134
+ };
1135
+
990
1136
  // src/provider/runner/JsonRpcXyoRunner.ts
991
1137
  var JsonRpcXyoRunner = class {
992
1138
  static {
@@ -1264,17 +1410,18 @@ var XyoConnection = class {
1264
1410
  }
1265
1411
  };
1266
1412
 
1267
- // src/provider/provider/RpcXyoConnection.ts
1268
- var RpcXyoConnection = class extends XyoConnection {
1413
+ // src/provider/provider/HttpRpcXyoConnection.ts
1414
+ var HttpRpcXyoConnection = class extends XyoConnection {
1269
1415
  static {
1270
- __name(this, "RpcXyoConnection");
1416
+ __name(this, "HttpRpcXyoConnection");
1271
1417
  }
1272
1418
  constructor(params) {
1273
- const transport = new HttpRpcTransport(params.endpoint, {
1419
+ const { account, endpoint } = params;
1420
+ const signer = isDefined3(account) ? new MemoryXyoSigner(account) : void 0;
1421
+ const transport = new HttpRpcTransport(endpoint, {
1274
1422
  ...XyoRunnerRpcSchemas,
1275
1423
  ...XyoViewerRpcSchemas
1276
1424
  });
1277
- const signer = params.account ? new MemoryXyoSigner(params.account) : void 0;
1278
1425
  const runner = new JsonRpcXyoRunner(transport);
1279
1426
  const viewer = new JsonRpcXyoViewer(transport);
1280
1427
  super({
@@ -1284,147 +1431,9 @@ var RpcXyoConnection = class extends XyoConnection {
1284
1431
  });
1285
1432
  }
1286
1433
  };
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 {
1434
+ var RpcXyoConnection = class extends HttpRpcXyoConnection {
1337
1435
  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 {
1393
- static {
1394
- __name(this, "PostMessageRpcTransport");
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
- });
1436
+ __name(this, "RpcXyoConnection");
1428
1437
  }
1429
1438
  };
1430
1439
  export {
@@ -1434,6 +1443,7 @@ export {
1434
1443
  CaveatsSchema,
1435
1444
  ChainConnectionSchema,
1436
1445
  HttpRpcTransport,
1446
+ HttpRpcXyoConnection,
1437
1447
  InvokerPermissionSchema,
1438
1448
  JsonRpcErrorCodes,
1439
1449
  JsonRpcXyoRunner,