@cityofzion/bs-multichain 3.0.4 → 3.0.6

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.
@@ -1,4 +1,4 @@
1
- import { ISwapService, TSwapServiceStatusResponse } from '@cityofzion/blockchain-service';
1
+ import type { ISwapService, TSwapServiceStatusResponse } from '@cityofzion/blockchain-service';
2
2
  export declare class SimpleSwapService<BSName extends string = string> implements ISwapService {
3
3
  #private;
4
4
  constructor();
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
3
  if (kind === "m") throw new TypeError("Private method is not writable");
13
4
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -28,28 +19,26 @@ class SimpleSwapService {
28
19
  _SimpleSwapService_api.set(this, void 0);
29
20
  __classPrivateFieldSet(this, _SimpleSwapService_api, new SimpleSwapApi_1.SimpleSwapApi(), "f");
30
21
  }
31
- getStatus(id) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const response = yield __classPrivateFieldGet(this, _SimpleSwapService_api, "f").getExchange(id);
34
- const statusBySimpleSwapStatus = {
35
- waiting: 'confirming',
36
- confirming: 'confirming',
37
- exchanging: 'exchanging',
38
- sending: 'exchanging',
39
- verifying: 'exchanging',
40
- finished: 'finished',
41
- expired: 'failed',
42
- failed: 'failed',
43
- refunded: 'refunded',
44
- };
45
- const status = statusBySimpleSwapStatus[response.status];
46
- return {
47
- status,
48
- txFrom: response.txFrom,
49
- txTo: response.txTo,
50
- log: response.log,
51
- };
52
- });
22
+ async getStatus(id) {
23
+ const response = await __classPrivateFieldGet(this, _SimpleSwapService_api, "f").getExchange(id);
24
+ const statusBySimpleSwapStatus = {
25
+ waiting: 'confirming',
26
+ confirming: 'confirming',
27
+ exchanging: 'exchanging',
28
+ sending: 'exchanging',
29
+ verifying: 'exchanging',
30
+ finished: 'finished',
31
+ expired: 'failed',
32
+ failed: 'failed',
33
+ refunded: 'refunded',
34
+ };
35
+ const status = statusBySimpleSwapStatus[response.status];
36
+ return {
37
+ status,
38
+ txFrom: response.txFrom,
39
+ txTo: response.txTo,
40
+ log: response.log,
41
+ };
53
42
  }
54
43
  }
55
44
  exports.SimpleSwapService = SimpleSwapService;
@@ -1,4 +1,4 @@
1
- import { IBlockchainService, TSwapToken } from '@cityofzion/blockchain-service';
1
+ import type { IBlockchainService, TSwapToken } from '@cityofzion/blockchain-service';
2
2
  export type TSimpleSwapOrchestratorInitParams<N extends string = string> = {
3
3
  blockchainServicesByName: Record<N, IBlockchainService<N>>;
4
4
  chainsByServiceName: Partial<Record<N, string[]>>;
@@ -1,8 +1,8 @@
1
- import { IBlockchainService, IBSWithWalletConnect } from '@cityofzion/blockchain-service';
1
+ import { type IBlockchainService, type IBSWithWalletConnect } from '@cityofzion/blockchain-service';
2
2
  import { ErrorResponse } from '@walletconnect/jsonrpc-utils';
3
3
  import type { PendingRequestTypes, SessionTypes } from '@walletconnect/types';
4
4
  import { SdkErrorKey } from '@walletconnect/utils';
5
- import { type TWalletKitHelperFilterSessionsParams, type TWalletKitHelperGetProposalDetailsParams, type TWalletKitHelperGetSessionDetailsParams, type TWalletKitHelperProcessRequestParams, type TWalletKitHelperProposalDetails, type TWalletKitHelperSessionDetails, type TWalletKitHelperGetProposalServicesParams } from './types';
5
+ import type { TWalletKitHelperFilterSessionsParams, TWalletKitHelperGetProposalDetailsParams, TWalletKitHelperGetSessionDetailsParams, TWalletKitHelperProcessRequestParams, TWalletKitHelperProposalDetails, TWalletKitHelperSessionDetails, TWalletKitHelperGetProposalServicesParams } from './types';
6
6
  export declare class WalletKitHelper {
7
7
  static getProposalDetails<N extends string>({ address, proposal, service, }: TWalletKitHelperGetProposalDetailsParams<N>): TWalletKitHelperProposalDetails<N>;
8
8
  static getProposalServices<N extends string>({ proposal, services }: TWalletKitHelperGetProposalServicesParams<N>): (IBlockchainService<N, string> & IBSWithWalletConnect<N>)[];
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.WalletKitHelper = void 0;
13
4
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
@@ -15,8 +6,7 @@ const jsonrpc_utils_1 = require("@walletconnect/jsonrpc-utils");
15
6
  const utils_1 = require("@walletconnect/utils");
16
7
  class WalletKitHelper {
17
8
  static getProposalDetails({ address, proposal, service, }) {
18
- var _a, _b;
19
- const mergedNamespacesObject = (0, utils_1.mergeRequiredAndOptionalNamespaces)((_a = proposal === null || proposal === void 0 ? void 0 : proposal.requiredNamespaces) !== null && _a !== void 0 ? _a : {}, (_b = proposal === null || proposal === void 0 ? void 0 : proposal.optionalNamespaces) !== null && _b !== void 0 ? _b : {});
9
+ const mergedNamespacesObject = (0, utils_1.mergeRequiredAndOptionalNamespaces)(proposal?.requiredNamespaces ?? {}, proposal?.optionalNamespaces ?? {});
20
10
  const allChains = new Set((0, utils_1.getChainsFromRequiredNamespaces)(mergedNamespacesObject));
21
11
  if (!(0, blockchain_service_1.hasWalletConnect)(service) || !allChains.has(service.walletConnectService.chain))
22
12
  throw new blockchain_service_1.BSError('Requested chain(s) not supported by any service', 'NO_SERVICE');
@@ -38,8 +28,7 @@ class WalletKitHelper {
38
28
  return { approvedNamespaces, methods, service, blockchain: service.name };
39
29
  }
40
30
  static getProposalServices({ proposal, services }) {
41
- var _a, _b;
42
- const mergedNamespacesObject = (0, utils_1.mergeRequiredAndOptionalNamespaces)((_a = proposal === null || proposal === void 0 ? void 0 : proposal.requiredNamespaces) !== null && _a !== void 0 ? _a : {}, (_b = proposal === null || proposal === void 0 ? void 0 : proposal.optionalNamespaces) !== null && _b !== void 0 ? _b : {});
31
+ const mergedNamespacesObject = (0, utils_1.mergeRequiredAndOptionalNamespaces)(proposal?.requiredNamespaces ?? {}, proposal?.optionalNamespaces ?? {});
43
32
  const allChains = new Set((0, utils_1.getChainsFromRequiredNamespaces)(mergedNamespacesObject));
44
33
  const proposalServices = services.filter((service) => (0, blockchain_service_1.hasWalletConnect)(service) && allChains.has(service.walletConnectService.chain));
45
34
  return proposalServices;
@@ -63,25 +52,23 @@ class WalletKitHelper {
63
52
  return (0, jsonrpc_utils_1.formatJsonRpcResult)(request.id, response);
64
53
  }
65
54
  static formatRequestError(request, reason) {
66
- return (0, jsonrpc_utils_1.formatJsonRpcError)(request.id, reason !== null && reason !== void 0 ? reason : (0, utils_1.getSdkError)('USER_REJECTED'));
55
+ return (0, jsonrpc_utils_1.formatJsonRpcError)(request.id, reason ?? (0, utils_1.getSdkError)('USER_REJECTED'));
67
56
  }
68
- static processRequest(_a) {
69
- return __awaiter(this, arguments, void 0, function* ({ sessionDetails, account, request, }) {
70
- if (account.address !== sessionDetails.address) {
71
- throw new blockchain_service_1.BSError('Account address does not match session address', 'INVALID_ACCOUNT');
72
- }
73
- const method = request.params.request.method;
74
- if (!sessionDetails.methods.includes(method)) {
75
- throw new blockchain_service_1.BSError('Method not supported by session', 'UNSUPPORTED_METHOD');
76
- }
77
- const serviceMethod = sessionDetails.service.walletConnectService[method];
78
- if (!serviceMethod || typeof serviceMethod !== 'function')
79
- throw new blockchain_service_1.BSError('Method not supported', 'UNSUPPORTED_METHOD');
80
- const response = yield serviceMethod.apply(sessionDetails.service.walletConnectService, [
81
- { account, params: request.params.request.params },
82
- ]);
83
- return response;
84
- });
57
+ static async processRequest({ sessionDetails, account, request, }) {
58
+ if (account.address !== sessionDetails.address) {
59
+ throw new blockchain_service_1.BSError('Account address does not match session address', 'INVALID_ACCOUNT');
60
+ }
61
+ const method = request.params.request.method;
62
+ if (!sessionDetails.methods.includes(method)) {
63
+ throw new blockchain_service_1.BSError('Method not supported by session', 'UNSUPPORTED_METHOD');
64
+ }
65
+ const serviceMethod = sessionDetails.service.walletConnectService[method];
66
+ if (!serviceMethod || typeof serviceMethod !== 'function')
67
+ throw new blockchain_service_1.BSError('Method not supported', 'UNSUPPORTED_METHOD');
68
+ const response = await serviceMethod.apply(sessionDetails.service.walletConnectService, [
69
+ { account, params: request.params.request.params },
70
+ ]);
71
+ return response;
85
72
  }
86
73
  static filterSessions(sessions, filters) {
87
74
  const filteredSessions = sessions.filter(session => {
@@ -96,7 +83,7 @@ class WalletKitHelper {
96
83
  }
97
84
  if (filters.chains) {
98
85
  const chains = (0, utils_1.getChainsFromNamespaces)(session.namespaces);
99
- if (chains.some(chain => { var _a; return (_a = filters.chains) === null || _a === void 0 ? void 0 : _a.includes(chain); })) {
86
+ if (chains.some(chain => filters.chains?.includes(chain))) {
100
87
  chainMatched = true;
101
88
  }
102
89
  }
@@ -1,5 +1,5 @@
1
- import { IBlockchainService, IBSWithWalletConnect, TBSAccount } from '@cityofzion/blockchain-service';
2
- import { PendingRequestTypes, ProposalTypes, SessionTypes } from '@walletconnect/types';
1
+ import type { IBlockchainService, IBSWithWalletConnect, TBSAccount } from '@cityofzion/blockchain-service';
2
+ import type { PendingRequestTypes, ProposalTypes, SessionTypes } from '@walletconnect/types';
3
3
  export type TWalletKitHelperGetProposalDetailsParams<N extends string = string> = {
4
4
  proposal: ProposalTypes.Struct;
5
5
  address: string;
package/package.json CHANGED
@@ -1,41 +1,38 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-multichain",
3
- "version": "3.0.4",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
3
+ "version": "3.0.6",
6
4
  "repository": "https://github.com/CityOfZion/blockchain-services",
7
- "author": "Coz",
8
5
  "license": "GPL-3.0-only",
6
+ "author": "Coz",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
9
  "files": [
10
10
  "/dist"
11
11
  ],
12
12
  "dependencies": {
13
- "axios": "~1.12.2",
14
13
  "@walletconnect/utils": "~2.21.9",
15
14
  "@walletconnect/jsonrpc-utils": "~1.0.8",
16
- "@cityofzion/blockchain-service": "3.0.4"
15
+ "axios": "~1.13.5",
16
+ "@cityofzion/blockchain-service": "3.0.6"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "~24.5.2",
20
- "@types/jest": "~30.0.0",
21
20
  "@walletconnect/types": "~2.21.9",
22
- "dotenv": "~17.2.2",
21
+ "dotenv": "~17.3.1",
23
22
  "eslint": "~9.36.0",
24
- "jest": "~30.1.3",
25
- "ts-jest": "~29.4.4",
26
- "ts-node": "~10.9.2",
27
- "typescript": "~5.9.2",
28
23
  "typed-emitter": "~2.1.0",
29
- "@cityofzion/bs-neo3": "3.0.4",
30
- "@cityofzion/bs-neox": "3.0.4",
31
- "@cityofzion/bs-ethereum": "3.0.4"
24
+ "typescript": "~5.9.2",
25
+ "vitest": "~4.0.18",
26
+ "@cityofzion/bs-neo3": "3.0.6",
27
+ "@cityofzion/bs-neox": "3.0.6",
28
+ "@cityofzion/bs-ethereum": "3.0.6"
32
29
  },
33
30
  "scripts": {
34
31
  "build": "rm -rf ./dist && npm run typecheck && tsc --project tsconfig.build.json",
35
- "test": "jest -i --config jest.config.ts",
36
- "lint": "eslint .",
37
32
  "format": "eslint --fix",
33
+ "lint": "eslint .",
38
34
  "package": "npm run build && npm pack",
35
+ "test": "vitest run",
39
36
  "typecheck": "tsc --noEmit"
40
37
  }
41
38
  }