@cityofzion/blockchain-service 0.9.1 → 0.11.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.
@@ -1,16 +1,16 @@
1
- import { AccountWithDerivationPath, BlockchainService } from './interfaces';
1
+ import { AccountWithDerivationPath, BlockchainService, Network, PartialBy } from './interfaces';
2
2
  export declare class BSAggregator<BSCustomName extends string = string, BSCustom extends BlockchainService<BSCustomName> = BlockchainService<BSCustomName>> {
3
+ #private;
3
4
  readonly blockchainServicesByName: Record<BSCustomName, BSCustom>;
4
- readonly blockchainServices: BlockchainService<BSCustomName>[];
5
5
  constructor(blockchainServices: Record<BSCustomName, BSCustom>);
6
+ setNetwork(network: PartialBy<Network, 'url'>): void;
6
7
  addBlockchain(name: BSCustomName, blockchain: BSCustom): void;
7
8
  validateAddressAllBlockchains(address: string): boolean;
8
9
  validateTextAllBlockchains(text: string): boolean;
9
10
  validateKeyAllBlockchains(wif: string): boolean;
10
11
  validateEncryptedAllBlockchains(keyOrJson: string): boolean;
11
- getBlockchainByName(name: BSCustomName): BlockchainService<BSCustomName>;
12
- getBlockchainByAddress(address: string): BlockchainService<BSCustomName> | undefined;
13
- getBlockchainByKey(wif: string): BlockchainService<BSCustomName> | undefined;
14
- getBlockchainByEncrypted(keyOrJson: string): BlockchainService<BSCustomName> | undefined;
12
+ getBlockchainNameByAddress(address: string): BSCustomName | undefined;
13
+ getBlockchainNameByKey(wif: string): BSCustomName | undefined;
14
+ getBlockchainNameByEncrypted(keyOrJson: string): BSCustomName | undefined;
15
15
  generateAccountFromMnemonicAllBlockchains(mnemonic: string, skippedAddresses?: string[]): Promise<Map<BSCustomName, AccountWithDerivationPath[]>>;
16
16
  }
@@ -8,51 +8,63 @@ 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;
11
23
  Object.defineProperty(exports, "__esModule", { value: true });
12
24
  exports.BSAggregator = void 0;
13
- const exceptions_1 = require("./exceptions");
14
25
  class BSAggregator {
15
26
  constructor(blockchainServices) {
27
+ _BSAggregator_blockchainServices.set(this, void 0);
16
28
  this.blockchainServicesByName = blockchainServices;
17
- this.blockchainServices = Object.values(blockchainServices);
29
+ __classPrivateFieldSet(this, _BSAggregator_blockchainServices, Object.values(blockchainServices), "f");
30
+ }
31
+ setNetwork(network) {
32
+ __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").forEach(bs => bs.setNetwork(network));
18
33
  }
19
34
  addBlockchain(name, blockchain) {
20
35
  if (this.blockchainServicesByName[name])
21
- throw new exceptions_1.BlockchainAlreadyExistError(name);
36
+ throw new Error(`The blockchain ${name} already exist`);
22
37
  this.blockchainServicesByName[name] = blockchain;
23
- this.blockchainServices.push(blockchain);
38
+ __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").push(blockchain);
24
39
  }
25
40
  validateAddressAllBlockchains(address) {
26
- return this.blockchainServices.some(bs => bs.validateAddress(address));
41
+ return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").some(bs => bs.validateAddress(address));
27
42
  }
28
43
  validateTextAllBlockchains(text) {
29
- return this.blockchainServices.some(bs => [bs.validateAddress(text), bs.validateEncrypted(text), bs.validateKey(text)].some(it => it === true));
44
+ return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").some(bs => [bs.validateAddress(text), bs.validateEncrypted(text), bs.validateKey(text)].some(it => it === true));
30
45
  }
31
46
  validateKeyAllBlockchains(wif) {
32
- return this.blockchainServices.some(bs => bs.validateKey(wif));
47
+ return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").some(bs => bs.validateKey(wif));
33
48
  }
34
49
  validateEncryptedAllBlockchains(keyOrJson) {
35
- return this.blockchainServices.some(bs => bs.validateEncrypted(keyOrJson));
36
- }
37
- getBlockchainByName(name) {
38
- const service = this.blockchainServicesByName[name];
39
- if (!service)
40
- throw new exceptions_1.BlockchainNotFoundError(name);
41
- return this.blockchainServicesByName[name];
50
+ return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").some(bs => bs.validateEncrypted(keyOrJson));
42
51
  }
43
- getBlockchainByAddress(address) {
44
- return this.blockchainServices.find(bs => bs.validateAddress(address));
52
+ getBlockchainNameByAddress(address) {
53
+ var _a;
54
+ return (_a = __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").find(bs => bs.validateAddress(address))) === null || _a === void 0 ? void 0 : _a.blockchainName;
45
55
  }
46
- getBlockchainByKey(wif) {
47
- return this.blockchainServices.find(bs => bs.validateKey(wif));
56
+ getBlockchainNameByKey(wif) {
57
+ var _a;
58
+ return (_a = __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").find(bs => bs.validateKey(wif))) === null || _a === void 0 ? void 0 : _a.blockchainName;
48
59
  }
49
- getBlockchainByEncrypted(keyOrJson) {
50
- return this.blockchainServices.find(bs => bs.validateEncrypted(keyOrJson));
60
+ getBlockchainNameByEncrypted(keyOrJson) {
61
+ var _a;
62
+ return (_a = __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").find(bs => bs.validateEncrypted(keyOrJson))) === null || _a === void 0 ? void 0 : _a.blockchainName;
51
63
  }
52
64
  generateAccountFromMnemonicAllBlockchains(mnemonic, skippedAddresses) {
53
65
  return __awaiter(this, void 0, void 0, function* () {
54
66
  const mnemonicAccounts = new Map();
55
- const promises = this.blockchainServices.map((service) => __awaiter(this, void 0, void 0, function* () {
67
+ const promises = __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").map((service) => __awaiter(this, void 0, void 0, function* () {
56
68
  let index = 0;
57
69
  const accounts = [];
58
70
  let hasError = false;
@@ -85,3 +97,4 @@ class BSAggregator {
85
97
  }
86
98
  }
87
99
  exports.BSAggregator = BSAggregator;
100
+ _BSAggregator_blockchainServices = new WeakMap();
@@ -1,7 +1,8 @@
1
- import { BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithNameService, BSWithNft } from './interfaces';
1
+ import { BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft } from './interfaces';
2
2
  export declare function hasNameService(service: BlockchainService): service is BlockchainService & BSWithNameService;
3
3
  export declare function isClaimable(service: BlockchainService): service is BlockchainService & BSClaimable;
4
4
  export declare function isCalculableFee(service: BlockchainService): service is BlockchainService & BSCalculableFee;
5
5
  export declare function hasNft(service: BlockchainService): service is BlockchainService & BSWithNft;
6
6
  export declare function hasExplorerService(service: BlockchainService): service is BlockchainService & BSWithExplorerService;
7
+ export declare function hasLedger(service: BlockchainService): service is BlockchainService & BSWithLedger;
7
8
  export declare function waitForTransaction(service: BlockchainService, txId: string): Promise<boolean>;
package/dist/functions.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.waitForTransaction = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
12
+ exports.waitForTransaction = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
13
13
  function hasNameService(service) {
14
14
  return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
15
15
  }
@@ -30,6 +30,10 @@ function hasExplorerService(service) {
30
30
  return 'explorerService' in service;
31
31
  }
32
32
  exports.hasExplorerService = hasExplorerService;
33
+ function hasLedger(service) {
34
+ return 'ledgerService' in service;
35
+ }
36
+ exports.hasLedger = hasLedger;
33
37
  function wait(ms) {
34
38
  return new Promise(resolve => setTimeout(resolve, ms));
35
39
  }
@@ -1,7 +1,8 @@
1
+ import Transport from '@ledgerhq/hw-transport';
1
2
  export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
2
3
  export type Account = {
3
4
  key: string;
4
- type: 'wif' | 'privateKey';
5
+ type: 'wif' | 'privateKey' | 'publicKey';
5
6
  address: string;
6
7
  };
7
8
  export type AccountWithDerivationPath = Account & {
@@ -29,6 +30,7 @@ export type TransferParam = {
29
30
  intent: IntentTransferParam;
30
31
  tipIntent?: IntentTransferParam;
31
32
  priorityFee?: string;
33
+ isLedger?: boolean;
32
34
  };
33
35
  export type TokenPricesResponse = {
34
36
  price: number;
@@ -64,7 +66,7 @@ export interface BSClaimable {
64
66
  readonly claimToken: Token;
65
67
  readonly burnToken: Token;
66
68
  blockchainDataService: BlockchainDataService & BDSClaimable;
67
- claim(account: Account): Promise<string>;
69
+ claim(account: Account, isLedger?: boolean): Promise<string>;
68
70
  }
69
71
  export interface BSWithNameService {
70
72
  resolveNameServiceDomain(domainName: string): Promise<string>;
@@ -76,6 +78,10 @@ export interface BSWithExplorerService {
76
78
  export interface BSWithNft {
77
79
  nftDataService: NftDataService;
78
80
  }
81
+ export interface BSWithLedger {
82
+ ledgerService: LedgerService;
83
+ generateAccountFromPublicKey(publicKey: string): Account;
84
+ }
79
85
  export type TransactionNotifications = {
80
86
  eventName: string;
81
87
  state: {
@@ -185,3 +191,8 @@ export interface ExplorerService {
185
191
  buildTransactionUrl(hash: string): string;
186
192
  buildNftUrl(params: BuildNftUrlParams): string;
187
193
  }
194
+ export interface LedgerService {
195
+ getLedgerTransport?: (account: Account) => Promise<Transport>;
196
+ getAddress(transport: Transport): Promise<string>;
197
+ getPublicKey(transport: Transport): Promise<string>;
198
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "0.9.1",
3
+ "version": "0.11.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -17,6 +17,9 @@
17
17
  "ts-node": "10.9.1",
18
18
  "typescript": "4.9.5"
19
19
  },
20
+ "dependencies": {
21
+ "@ledgerhq/hw-transport": "~6.30.5"
22
+ },
20
23
  "scripts": {
21
24
  "build": "tsc",
22
25
  "lint": "eslint .",
@@ -1,9 +0,0 @@
1
- export declare class BlockchainAlreadyExistError extends Error {
2
- constructor(blockchainName: string);
3
- }
4
- export declare class InvalidBlockchainServiceError extends Error {
5
- constructor(message?: string);
6
- }
7
- export declare class BlockchainNotFoundError extends Error {
8
- constructor(blockchainName: string);
9
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlockchainNotFoundError = exports.InvalidBlockchainServiceError = exports.BlockchainAlreadyExistError = void 0;
4
- class BlockchainAlreadyExistError extends Error {
5
- constructor(blockchainName) {
6
- super(`The blockchain ${blockchainName} already exist`);
7
- }
8
- }
9
- exports.BlockchainAlreadyExistError = BlockchainAlreadyExistError;
10
- class InvalidBlockchainServiceError extends Error {
11
- constructor(message) {
12
- super(`Invalid blockchainServices => ${message}`);
13
- }
14
- }
15
- exports.InvalidBlockchainServiceError = InvalidBlockchainServiceError;
16
- class BlockchainNotFoundError extends Error {
17
- constructor(blockchainName) {
18
- super(`The blockchain ${blockchainName} not found`);
19
- }
20
- }
21
- exports.BlockchainNotFoundError = BlockchainNotFoundError;