@cityofzion/bs-multichain 1.0.15 → 1.1.0
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/BSAggregator.d.ts +1 -1
- package/dist/BSAggregator.js +9 -25
- package/dist/features/wallet-connect/WalletKitHelper.d.ts +17 -0
- package/dist/features/wallet-connect/WalletKitHelper.js +106 -0
- package/dist/features/wallet-connect/index.d.ts +2 -0
- package/dist/features/wallet-connect/index.js +18 -0
- package/dist/features/wallet-connect/types.d.ts +32 -0
- package/dist/features/wallet-connect/types.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +8 -5
package/dist/BSAggregator.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TBSAccount, IBlockchainService, TUntilIndexRecord } from '@cityofzion/blockchain-service';
|
|
2
2
|
export declare class BSAggregator<N extends string> {
|
|
3
|
-
#private;
|
|
4
3
|
readonly blockchainServicesByName: Record<N, IBlockchainService<N>>;
|
|
4
|
+
readonly blockchainServices: IBlockchainService<N>[];
|
|
5
5
|
constructor(blockchainServices: IBlockchainService<N>[]);
|
|
6
6
|
validateAddressAllBlockchains(address: string): boolean;
|
|
7
7
|
validateTextAllBlockchains(text: string): boolean;
|
package/dist/BSAggregator.js
CHANGED
|
@@ -8,60 +8,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var _BSAggregator_blockchainServices;
|
|
23
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
12
|
exports.BSAggregator = void 0;
|
|
25
13
|
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
26
14
|
class BSAggregator {
|
|
27
15
|
constructor(blockchainServices) {
|
|
28
|
-
|
|
29
|
-
__classPrivateFieldSet(this, _BSAggregator_blockchainServices, blockchainServices, "f");
|
|
16
|
+
this.blockchainServices = blockchainServices;
|
|
30
17
|
this.blockchainServicesByName = blockchainServices.reduce((acc, service) => {
|
|
31
18
|
acc[service.name] = service;
|
|
32
19
|
return acc;
|
|
33
20
|
}, {});
|
|
34
21
|
}
|
|
35
22
|
validateAddressAllBlockchains(address) {
|
|
36
|
-
return
|
|
23
|
+
return this.blockchainServices.some(bs => bs.validateAddress(address));
|
|
37
24
|
}
|
|
38
25
|
validateTextAllBlockchains(text) {
|
|
39
|
-
return
|
|
26
|
+
return this.blockchainServices.some(bs => [bs.validateAddress(text), (0, blockchain_service_1.hasEncryption)(bs) && bs.validateEncrypted(text), bs.validateKey(text)].some(it => it === true));
|
|
40
27
|
}
|
|
41
28
|
validateKeyAllBlockchains(wif) {
|
|
42
|
-
return
|
|
29
|
+
return this.blockchainServices.some(bs => bs.validateKey(wif));
|
|
43
30
|
}
|
|
44
31
|
validateEncryptedAllBlockchains(keyOrJson) {
|
|
45
|
-
return
|
|
32
|
+
return this.blockchainServices.some(bs => (0, blockchain_service_1.hasEncryption)(bs) && bs.validateEncrypted(keyOrJson));
|
|
46
33
|
}
|
|
47
34
|
getBlockchainNameByAddress(address) {
|
|
48
|
-
return
|
|
35
|
+
return this.blockchainServices.filter(bs => bs.validateAddress(address)).map(bs => bs.name);
|
|
49
36
|
}
|
|
50
37
|
getBlockchainNameByKey(wif) {
|
|
51
|
-
return
|
|
38
|
+
return this.blockchainServices.filter(bs => bs.validateKey(wif)).map(bs => bs.name);
|
|
52
39
|
}
|
|
53
40
|
getBlockchainNameByEncrypted(keyOrJson) {
|
|
54
|
-
return
|
|
55
|
-
.filter(bs => (0, blockchain_service_1.hasEncryption)(bs) && bs.validateEncrypted(keyOrJson))
|
|
56
|
-
.map(bs => bs.name);
|
|
41
|
+
return this.blockchainServices.filter(bs => (0, blockchain_service_1.hasEncryption)(bs) && bs.validateEncrypted(keyOrJson)).map(bs => bs.name);
|
|
57
42
|
}
|
|
58
43
|
generateAccountsFromMnemonic(mnemonic, untilIndexByBlockchainService) {
|
|
59
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
return (0, blockchain_service_1.generateAccountForBlockchainService)(
|
|
45
|
+
return (0, blockchain_service_1.generateAccountForBlockchainService)(this.blockchainServices, (service, index) => __awaiter(this, void 0, void 0, function* () {
|
|
61
46
|
return service.generateAccountFromMnemonic(mnemonic, index);
|
|
62
47
|
}), untilIndexByBlockchainService);
|
|
63
48
|
});
|
|
64
49
|
}
|
|
65
50
|
}
|
|
66
51
|
exports.BSAggregator = BSAggregator;
|
|
67
|
-
_BSAggregator_blockchainServices = new WeakMap();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ErrorResponse } from '@walletconnect/jsonrpc-utils';
|
|
2
|
+
import type { PendingRequestTypes, SessionTypes } from '@walletconnect/types';
|
|
3
|
+
import { SdkErrorKey } from '@walletconnect/utils';
|
|
4
|
+
import { TWalletKitHelperFilterSessionsParams, TWalletKitHelperGetProposalDetailsParams, TWalletKitHelperGetSessionDetailsParams, TWalletKitHelperProcessRequestParams, TWalletKitHelperProposalDetails, TWalletKitHelperSessionDetails } from './types';
|
|
5
|
+
export declare class WalletKitHelper {
|
|
6
|
+
static getProposalDetails<N extends string>({ address, proposal, services, }: TWalletKitHelperGetProposalDetailsParams<N>): TWalletKitHelperProposalDetails<N>;
|
|
7
|
+
static getSessionDetails<N extends string>({ session, services, }: TWalletKitHelperGetSessionDetailsParams<N>): TWalletKitHelperSessionDetails<N>;
|
|
8
|
+
static getError(key: SdkErrorKey): {
|
|
9
|
+
message: string;
|
|
10
|
+
code: number;
|
|
11
|
+
};
|
|
12
|
+
static formatRequestResult(request: PendingRequestTypes.Struct, response: any): import("@walletconnect/jsonrpc-utils").JsonRpcResult<any>;
|
|
13
|
+
static formatRequestError(request: PendingRequestTypes.Struct, reason: ErrorResponse): import("@walletconnect/jsonrpc-utils").JsonRpcError;
|
|
14
|
+
static processRequest<N extends string>({ sessionDetails, account, request, }: TWalletKitHelperProcessRequestParams<N>): Promise<any>;
|
|
15
|
+
static filterSessions(sessions: SessionTypes.Struct[], filters: TWalletKitHelperFilterSessionsParams): SessionTypes.Struct[];
|
|
16
|
+
static isValidURI(uri: string): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.WalletKitHelper = void 0;
|
|
13
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
14
|
+
const jsonrpc_utils_1 = require("@walletconnect/jsonrpc-utils");
|
|
15
|
+
const utils_1 = require("@walletconnect/utils");
|
|
16
|
+
class WalletKitHelper {
|
|
17
|
+
static getProposalDetails({ address, proposal, services, }) {
|
|
18
|
+
const mergedNamespacesObject = (0, utils_1.mergeRequiredAndOptionalNamespaces)(proposal.requiredNamespaces, proposal.optionalNamespaces);
|
|
19
|
+
const allChains = new Set((0, utils_1.getChainsFromRequiredNamespaces)(mergedNamespacesObject));
|
|
20
|
+
const service = services.find((service) => (0, blockchain_service_1.hasWalletConnect)(service) && allChains.has(service.walletConnectService.chain));
|
|
21
|
+
if (!service)
|
|
22
|
+
throw new blockchain_service_1.BSError('Requested chain(s) not supported by any service', 'NO_SERVICE');
|
|
23
|
+
const namespaceObject = mergedNamespacesObject[service.walletConnectService.namespace];
|
|
24
|
+
if (!namespaceObject)
|
|
25
|
+
throw new blockchain_service_1.BSError('Requested namespace not supported by any service', 'NO_SERVICE');
|
|
26
|
+
const approvedNamespaces = (0, utils_1.buildApprovedNamespaces)({
|
|
27
|
+
proposal: proposal,
|
|
28
|
+
supportedNamespaces: {
|
|
29
|
+
[service.walletConnectService.namespace]: {
|
|
30
|
+
chains: [service.walletConnectService.chain],
|
|
31
|
+
methods: service.walletConnectService.supportedMethods,
|
|
32
|
+
events: service.walletConnectService.supportedEvents,
|
|
33
|
+
accounts: [`${service.walletConnectService.chain}:${address}`],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const methods = namespaceObject.methods;
|
|
38
|
+
return { approvedNamespaces, methods, service, blockchain: service.name };
|
|
39
|
+
}
|
|
40
|
+
static getSessionDetails({ session, services, }) {
|
|
41
|
+
const sessionAccounts = (0, utils_1.getAccountsFromNamespaces)(session.namespaces);
|
|
42
|
+
const [sessionAddress] = (0, utils_1.getAddressesFromAccounts)(sessionAccounts);
|
|
43
|
+
if (!sessionAddress)
|
|
44
|
+
throw new blockchain_service_1.BSError('No accounts found in session', 'NO_ACCOUNTS');
|
|
45
|
+
const chains = (0, utils_1.getChainsFromNamespaces)(session.namespaces);
|
|
46
|
+
const service = services.find((service) => (0, blockchain_service_1.hasWalletConnect)(service) && chains.includes(service.walletConnectService.chain));
|
|
47
|
+
if (!service)
|
|
48
|
+
throw new blockchain_service_1.BSError('Requested chain not supported by any service', 'NO_SERVICE');
|
|
49
|
+
const methods = (0, utils_1.getNamespacesMethodsForChainId)(session.namespaces, service.walletConnectService.chain);
|
|
50
|
+
return { service, address: sessionAddress, methods, blockchain: service.name };
|
|
51
|
+
}
|
|
52
|
+
static getError(key) {
|
|
53
|
+
return (0, utils_1.getSdkError)(key);
|
|
54
|
+
}
|
|
55
|
+
static formatRequestResult(request, response) {
|
|
56
|
+
return (0, jsonrpc_utils_1.formatJsonRpcResult)(request.id, response);
|
|
57
|
+
}
|
|
58
|
+
static formatRequestError(request, reason) {
|
|
59
|
+
return (0, jsonrpc_utils_1.formatJsonRpcError)(request.id, reason !== null && reason !== void 0 ? reason : (0, utils_1.getSdkError)('USER_REJECTED'));
|
|
60
|
+
}
|
|
61
|
+
static processRequest(_a) {
|
|
62
|
+
return __awaiter(this, arguments, void 0, function* ({ sessionDetails, account, request, }) {
|
|
63
|
+
if (account.address !== sessionDetails.address) {
|
|
64
|
+
throw new blockchain_service_1.BSError('Account address does not match session address', 'INVALID_ACCOUNT');
|
|
65
|
+
}
|
|
66
|
+
const method = request.params.request.method;
|
|
67
|
+
if (!sessionDetails.methods.includes(method)) {
|
|
68
|
+
throw new blockchain_service_1.BSError('Method not supported by session', 'UNSUPPORTED_METHOD');
|
|
69
|
+
}
|
|
70
|
+
const serviceMethod = sessionDetails.service.walletConnectService[method];
|
|
71
|
+
if (!serviceMethod || typeof serviceMethod !== 'function')
|
|
72
|
+
throw new blockchain_service_1.BSError('Method not supported', 'UNSUPPORTED_METHOD');
|
|
73
|
+
const response = yield serviceMethod.apply(sessionDetails.service.walletConnectService, [
|
|
74
|
+
{ account, params: request.params.request.params },
|
|
75
|
+
]);
|
|
76
|
+
return response;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
static filterSessions(sessions, filters) {
|
|
80
|
+
let filteredSessions = sessions;
|
|
81
|
+
if (filters === null || filters === void 0 ? void 0 : filters.addresses) {
|
|
82
|
+
filteredSessions = filteredSessions.filter(session => {
|
|
83
|
+
let matched = false;
|
|
84
|
+
if (filters.addresses) {
|
|
85
|
+
const sessionAccounts = (0, utils_1.getAccountsFromNamespaces)(session.namespaces);
|
|
86
|
+
const [address] = (0, utils_1.getAddressesFromAccounts)(sessionAccounts);
|
|
87
|
+
if (address && filters.addresses.includes(address)) {
|
|
88
|
+
matched = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (filters.chains && !matched) {
|
|
92
|
+
const chains = (0, utils_1.getChainsFromNamespaces)(session.namespaces);
|
|
93
|
+
if (chains.some(namespace => { var _a; return (_a = filters.chains) === null || _a === void 0 ? void 0 : _a.includes(namespace); })) {
|
|
94
|
+
matched = true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return matched;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return filteredSessions;
|
|
101
|
+
}
|
|
102
|
+
static isValidURI(uri) {
|
|
103
|
+
return /^wc:.+@\d.*$/g.test(uri);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.WalletKitHelper = WalletKitHelper;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./WalletKitHelper"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IBlockchainService, IBSWithWalletConnect, TBSAccount } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { PendingRequestTypes, ProposalTypes, SessionTypes } from '@walletconnect/types';
|
|
3
|
+
export type TWalletKitHelperGetProposalDetailsParams<N extends string = string> = {
|
|
4
|
+
proposal: ProposalTypes.Struct;
|
|
5
|
+
address: string;
|
|
6
|
+
services: IBlockchainService<N>[];
|
|
7
|
+
};
|
|
8
|
+
export type TWalletKitHelperProposalDetails<N extends string = string> = {
|
|
9
|
+
methods: string[];
|
|
10
|
+
approvedNamespaces: SessionTypes.Namespaces;
|
|
11
|
+
service: IBlockchainService<N> & IBSWithWalletConnect;
|
|
12
|
+
blockchain: N;
|
|
13
|
+
};
|
|
14
|
+
export type TWalletKitHelperGetSessionDetailsParams<N extends string = string> = {
|
|
15
|
+
session: SessionTypes.Struct;
|
|
16
|
+
services: IBlockchainService<N>[];
|
|
17
|
+
};
|
|
18
|
+
export type TWalletKitHelperSessionDetails<N extends string = string> = {
|
|
19
|
+
address: string;
|
|
20
|
+
methods: string[];
|
|
21
|
+
service: IBlockchainService<N> & IBSWithWalletConnect;
|
|
22
|
+
blockchain: N;
|
|
23
|
+
};
|
|
24
|
+
export type TWalletKitHelperProcessRequestParams<N extends string = string> = {
|
|
25
|
+
request: PendingRequestTypes.Struct;
|
|
26
|
+
sessionDetails: TWalletKitHelperSessionDetails<N>;
|
|
27
|
+
account: TBSAccount<N>;
|
|
28
|
+
};
|
|
29
|
+
export type TWalletKitHelperFilterSessionsParams = {
|
|
30
|
+
addresses?: string[];
|
|
31
|
+
chains?: string[];
|
|
32
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./features/swap"), exports);
|
|
18
18
|
__exportStar(require("./features/bridge"), exports);
|
|
19
|
+
__exportStar(require("./features/wallet-connect"), exports);
|
|
19
20
|
__exportStar(require("./BSAggregator"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-multichain",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
@@ -11,11 +11,14 @@
|
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"axios": "~1.12.2",
|
|
14
|
-
"@
|
|
14
|
+
"@walletconnect/utils": "~2.21.9",
|
|
15
|
+
"@walletconnect/jsonrpc-utils": "~1.0.8",
|
|
16
|
+
"@cityofzion/blockchain-service": "1.22.0"
|
|
15
17
|
},
|
|
16
18
|
"devDependencies": {
|
|
17
19
|
"@types/node": "~24.5.2",
|
|
18
20
|
"@types/jest": "~30.0.0",
|
|
21
|
+
"@walletconnect/types": "~2.21.9",
|
|
19
22
|
"dotenv": "~17.2.2",
|
|
20
23
|
"eslint": "~9.36.0",
|
|
21
24
|
"jest": "~30.1.3",
|
|
@@ -23,10 +26,10 @@
|
|
|
23
26
|
"ts-node": "~10.9.2",
|
|
24
27
|
"typescript": "~5.9.2",
|
|
25
28
|
"typed-emitter": "~2.1.0",
|
|
26
|
-
"@cityofzion/bs-ethereum": "2.
|
|
29
|
+
"@cityofzion/bs-ethereum": "2.14.0",
|
|
30
|
+
"@cityofzion/bs-neo3": "1.17.0",
|
|
27
31
|
"@cityofzion/bs-neo-legacy": "1.13.5",
|
|
28
|
-
"@cityofzion/bs-neox": "1.
|
|
29
|
-
"@cityofzion/bs-neo3": "1.16.4"
|
|
32
|
+
"@cityofzion/bs-neox": "1.4.0"
|
|
30
33
|
},
|
|
31
34
|
"scripts": {
|
|
32
35
|
"build": "rm -rf ./dist && tsc --project tsconfig.build.json",
|