@cityofzion/blockchain-service 0.1.1 → 0.2.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,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BSAgreggator = void 0;
4
- const excpetions_1 = require("./excpetions");
4
+ const exceptions_1 = require("./exceptions");
5
5
  class BSAgreggator {
6
6
  constructor(blockchainservices) {
7
7
  this.blockchainservices = blockchainservices;
@@ -17,46 +17,46 @@ class BSAgreggator {
17
17
  }
18
18
  addBlockchain(name, blockchain) {
19
19
  if (this.blockchainservices[name])
20
- excpetions_1.exception.blockchainAlreadyExist(name);
20
+ exceptions_1.exceptions.blockchainAlreadyExist(name);
21
21
  this.blockchainservices[name] = blockchain;
22
22
  this.bsList = Object.values(this.blockchainservices);
23
23
  }
24
24
  validateAddressesAllBlockchains(address) {
25
25
  if (this.haveBlockchainServices())
26
- excpetions_1.exception.invalidBlockchainService(JSON.stringify(this.blockchainservices));
26
+ exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
27
27
  return this.bsList.some(bs => bs.validateAddress(address));
28
28
  }
29
29
  validateTextAllBlockchains(text) {
30
30
  if (this.haveBlockchainServices())
31
- excpetions_1.exception.invalidBlockchainService(JSON.stringify(this.blockchainservices));
31
+ exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
32
32
  return this.bsList.some(bs => [bs.validateAddress(text), bs.validateEncryptedKey(text), bs.validateWif(text)].some(it => it === true));
33
33
  }
34
34
  validateWifAllBlockchains(wif) {
35
35
  if (this.haveBlockchainServices())
36
- excpetions_1.exception.invalidBlockchainService(JSON.stringify(this.blockchainservices));
36
+ exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
37
37
  return this.bsList.some(bs => bs.validateWif(wif));
38
38
  }
39
39
  validateEncryptedKeyAllBlockchains(encryptedKey) {
40
40
  if (this.haveBlockchainServices())
41
- excpetions_1.exception.invalidBlockchainService(JSON.stringify(this.blockchainservices));
41
+ exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
42
42
  return this.bsList.some(bs => bs.validateEncryptedKey(encryptedKey));
43
43
  }
44
44
  getBlockchainByAddress(address) {
45
45
  var _a;
46
46
  if (this.haveBlockchainServices())
47
- excpetions_1.exception.invalidBlockchainService(JSON.stringify(this.blockchainservices));
47
+ exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
48
48
  return (_a = this.bsList.find(bs => bs.validateAddress(address))) !== null && _a !== void 0 ? _a : null;
49
49
  }
50
50
  getBlockchainByWif(wif) {
51
51
  var _a;
52
52
  if (this.haveBlockchainServices())
53
- excpetions_1.exception.invalidBlockchainService(JSON.stringify(this.blockchainservices));
53
+ exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
54
54
  return (_a = this.bsList.find(bs => bs.validateWif(wif))) !== null && _a !== void 0 ? _a : null;
55
55
  }
56
56
  getBlockchainByEncryptedKey(encryptedKey) {
57
57
  var _a;
58
58
  if (this.haveBlockchainServices())
59
- excpetions_1.exception.invalidBlockchainService(JSON.stringify(this.blockchainservices));
59
+ exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
60
60
  return (_a = this.bsList.find(bs => bs.validateEncryptedKey(encryptedKey))) !== null && _a !== void 0 ? _a : null;
61
61
  }
62
62
  getBlockchainsClaimable() {
@@ -1,4 +1,4 @@
1
- export declare const exception: {
1
+ export declare const exceptions: {
2
2
  invalidBlockchainService: (message?: string) => never;
3
3
  blockchainAlreadyExist: (blockchainName: string) => never;
4
4
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exception = void 0;
4
- exports.exception = {
3
+ exports.exceptions = void 0;
4
+ exports.exceptions = {
5
5
  invalidBlockchainService: (message) => {
6
6
  throw new Error(`Invalid blockchainServices => ${message}`);
7
7
  },
@@ -0,0 +1,3 @@
1
+ import { BlockchainService, Claimable, NeoNameService } from "./interfaces";
2
+ export declare function hasNNS(service: BlockchainService): service is NeoNameService & BlockchainService;
3
+ export declare function isClaimable(service: BlockchainService): service is Claimable & BlockchainService;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isClaimable = exports.hasNNS = void 0;
4
+ function hasNNS(service) {
5
+ return "getNeoNsRecord" in service && "getOwnerOfNeoNsRecord" in service && "validateNNSDomain" in service;
6
+ }
7
+ exports.hasNNS = hasNNS;
8
+ function isClaimable(service) {
9
+ return "claim" in this && "tokenClaim" in this && "getUnclaimed" in this.dataService;
10
+ }
11
+ exports.isClaimable = isClaimable;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './interfaces';
2
2
  export * from './BSAgreggator';
3
3
  export * from './exchanges';
4
+ export * from "./functions";
package/dist/index.js CHANGED
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./interfaces"), exports);
18
18
  __exportStar(require("./BSAgreggator"), exports);
19
19
  __exportStar(require("./exchanges"), exports);
20
+ __exportStar(require("./functions"), exports);
@@ -8,10 +8,6 @@ export type IntentTransactionParam = {
8
8
  tokenHash: string;
9
9
  amount: number;
10
10
  };
11
- export interface Account {
12
- getWif(): string;
13
- getAddress(): string;
14
- }
15
11
  export type CalculateTransferFeeDetails = {
16
12
  systemFee?: string;
17
13
  networkFee?: string;
@@ -21,12 +17,13 @@ export type ExchangeInfo = {
21
17
  symbol: string;
22
18
  amount: number;
23
19
  };
20
+ export type ClaimResponse = {
21
+ txid: string;
22
+ symbol: string;
23
+ hash: string;
24
+ };
24
25
  export interface Claimable {
25
- claim(account: Account): Promise<{
26
- txid: string;
27
- symbol: string;
28
- hash: string;
29
- }>;
26
+ claim(account: Account): Promise<ClaimResponse>;
30
27
  dataService: BlockchainDataService & BDSClaimable;
31
28
  tokenClaim: {
32
29
  hash: string;
@@ -40,23 +37,10 @@ export declare enum NNSRecordTypes {
40
37
  TEXT = "16",
41
38
  IPV6 = "28"
42
39
  }
43
- export type NNSResponse = {
44
- jsonrpc: string;
45
- id: number;
46
- result: {
47
- script: string;
48
- state: string;
49
- gasconsumed: string;
50
- exception: string;
51
- stack: {
52
- type: string;
53
- value: string;
54
- }[];
55
- };
56
- };
57
40
  export interface NeoNameService {
58
- getNeoNsRecord(domainName: string, type: typeof NNSRecordTypes): Promise<NNSResponse>;
59
- getOwnerOfNeoNsRecord(domainName: string): Promise<NNSResponse>;
41
+ getNNSRecord(domainName: string, type: NNSRecordTypes): Promise<string>;
42
+ getOwnerOfNNS(domainName: string): Promise<string>;
43
+ validateNNSFormat(domainName: string): boolean;
60
44
  }
61
45
  export type Token = {
62
46
  name: string;
@@ -64,6 +48,14 @@ export type Token = {
64
48
  hash: string;
65
49
  decimals: number;
66
50
  };
51
+ export type Account = {
52
+ wif: string;
53
+ address: string;
54
+ };
55
+ export type CalculateTransferFeeResponse = {
56
+ result: number;
57
+ details?: CalculateTransferFeeDetails;
58
+ };
67
59
  export interface BlockchainService<BSCustomName extends string = string> {
68
60
  readonly dataService: BlockchainDataService;
69
61
  readonly blockchainName: BSCustomName;
@@ -78,22 +70,13 @@ export interface BlockchainService<BSCustomName extends string = string> {
78
70
  sendTransaction(param: SendTransactionParam): Promise<string>;
79
71
  generateMnemonic(): string;
80
72
  generateWif(mnemonic: string, index: number): string;
81
- generateAccount(mnemonic: string, index: number): {
82
- wif: string;
83
- address: string;
84
- };
73
+ generateAccount(mnemonic: string, index: number): Account;
85
74
  generateAccountFromWif(wif: string): string;
86
- decryptKey(encryptedKey: string, password: string): Promise<{
87
- wif: string;
88
- address: string;
89
- }>;
75
+ decryptKey(encryptedKey: string, password: string): Promise<Account>;
90
76
  validateAddress(address: string): boolean;
91
77
  validateEncryptedKey(encryptedKey: string): boolean;
92
78
  validateWif(wif: string): boolean;
93
- calculateTransferFee(param: SendTransactionParam, details?: boolean): Promise<{
94
- result: number;
95
- details?: CalculateTransferFeeDetails;
96
- }>;
79
+ calculateTransferFee(param: SendTransactionParam, details?: boolean): Promise<CalculateTransferFeeResponse>;
97
80
  }
98
81
  export type TransactionNotifications = {
99
82
  contract: string;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
+ "repository": "https://github.com/CityOfZion/blockchain-services",
6
7
  "author": "Coz",
7
8
  "license": "MIT",
8
9
  "files": ["/dist"],
@@ -16,10 +17,5 @@
16
17
  "ts-node": "10.9.1",
17
18
  "typescript": "4.9.5",
18
19
  "typedoc": "0.23.24"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/CityOfZion/blockchain-services",
23
- "directory": "packages/blockchain-service"
24
20
  }
25
21
  }