@cityofzion/bs-solana 0.0.1 → 2.0.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/BSSolana.d.ts +36 -0
- package/dist/BSSolana.js +271 -0
- package/dist/constants/BSSolanaConstants.d.ts +15 -0
- package/dist/constants/BSSolanaConstants.js +34 -0
- package/dist/helpers/BSSolanaCachedMethodsHelper.d.ts +13 -0
- package/dist/helpers/BSSolanaCachedMethodsHelper.js +148 -0
- package/dist/helpers/BSSolanaHelper.d.ts +7 -0
- package/dist/helpers/BSSolanaHelper.js +16 -0
- package/dist/services/blockchain-data/TatumRpcBDSSolana.d.ts +19 -0
- package/dist/services/blockchain-data/TatumRpcBDSSolana.js +408 -0
- package/dist/services/exchange/MoralisEDSSolana.d.ts +8 -0
- package/dist/services/exchange/MoralisEDSSolana.js +104 -0
- package/dist/services/explorer/SolScanESSolana.d.ts +13 -0
- package/dist/services/explorer/SolScanESSolana.js +50 -0
- package/dist/services/ledger/Web3LedgerServiceSolana.d.ts +13 -0
- package/dist/services/ledger/Web3LedgerServiceSolana.js +85 -0
- package/dist/services/nft-data/TatumRpcNDSSolana.d.ts +9 -0
- package/dist/services/nft-data/TatumRpcNDSSolana.js +129 -0
- package/dist/services/token/TokenServiceSolana.d.ts +4 -0
- package/dist/services/token/TokenServiceSolana.js +10 -0
- package/package.json +40 -11
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
var _Web3LedgerServiceSolana_blockchainService;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.Web3LedgerServiceSolana = void 0;
|
|
28
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
29
|
+
const hw_app_solana_1 = __importDefault(require("@ledgerhq/hw-app-solana"));
|
|
30
|
+
const events_1 = __importDefault(require("events"));
|
|
31
|
+
const web3_js_1 = __importDefault(require("@solana/web3.js"));
|
|
32
|
+
const BSSolanaHelper_1 = require("../../helpers/BSSolanaHelper");
|
|
33
|
+
class Web3LedgerServiceSolana {
|
|
34
|
+
constructor(blockchainService, getLedgerTransport) {
|
|
35
|
+
_Web3LedgerServiceSolana_blockchainService.set(this, void 0);
|
|
36
|
+
this.emitter = new events_1.default();
|
|
37
|
+
__classPrivateFieldSet(this, _Web3LedgerServiceSolana_blockchainService, blockchainService, "f");
|
|
38
|
+
this.getLedgerTransport = getLedgerTransport;
|
|
39
|
+
}
|
|
40
|
+
getAccounts(transport, untilIndexByBlockchainService) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const accountsByBlockchainService = yield (0, blockchain_service_1.generateAccountForBlockchainService)([__classPrivateFieldGet(this, _Web3LedgerServiceSolana_blockchainService, "f")], (_service, index) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return this.getAccount(transport, index);
|
|
44
|
+
}), untilIndexByBlockchainService);
|
|
45
|
+
const accounts = accountsByBlockchainService.get(__classPrivateFieldGet(this, _Web3LedgerServiceSolana_blockchainService, "f").name);
|
|
46
|
+
return accounts !== null && accounts !== void 0 ? accounts : [];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
getAccount(transport, index) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const ledgerApp = new hw_app_solana_1.default(transport);
|
|
52
|
+
const bip44Path = BSSolanaHelper_1.BSSolanaHelper.getBip44Path(__classPrivateFieldGet(this, _Web3LedgerServiceSolana_blockchainService, "f").bip44DerivationPath, index);
|
|
53
|
+
const publicKey = yield blockchain_service_1.BSUtilsHelper.retry(() => __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const response = yield ledgerApp.getAddress(bip44Path);
|
|
55
|
+
return new web3_js_1.default.PublicKey(response.address);
|
|
56
|
+
}));
|
|
57
|
+
const address = publicKey.toBase58();
|
|
58
|
+
return {
|
|
59
|
+
address,
|
|
60
|
+
key: address,
|
|
61
|
+
type: 'publicKey',
|
|
62
|
+
bip44Path,
|
|
63
|
+
isHardware: true,
|
|
64
|
+
blockchain: __classPrivateFieldGet(this, _Web3LedgerServiceSolana_blockchainService, "f").name,
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
signTransaction(transport, transaction, account) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if (!account.bip44Path)
|
|
72
|
+
throw new Error('Account must have bip44Path to sign with Ledger');
|
|
73
|
+
const ledgerApp = new hw_app_solana_1.default(transport);
|
|
74
|
+
const serializedTransaction = transaction.compileMessage().serialize();
|
|
75
|
+
(_a = this.emitter) === null || _a === void 0 ? void 0 : _a.emit('getSignatureStart');
|
|
76
|
+
const bip44Path = BSSolanaHelper_1.BSSolanaHelper.fixBip44Path(account.bip44Path);
|
|
77
|
+
const { signature } = yield ledgerApp.signTransaction(bip44Path, serializedTransaction);
|
|
78
|
+
(_b = this.emitter) === null || _b === void 0 ? void 0 : _b.emit('getSignatureEnd');
|
|
79
|
+
transaction.addSignature(new web3_js_1.default.PublicKey(account.address), signature);
|
|
80
|
+
return transaction.serialize();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.Web3LedgerServiceSolana = Web3LedgerServiceSolana;
|
|
85
|
+
_Web3LedgerServiceSolana_blockchainService = new WeakMap();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GetNftParam, GetNftsByAddressParams, HasTokenParam, Network, NftDataService, NftResponse, NftsResponse } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { BSSolanaNetworkId } from '../../constants/BSSolanaConstants';
|
|
3
|
+
export declare class TatumRpcNDSSolana implements NftDataService {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(network: Network<BSSolanaNetworkId>, mainnetApiKey: string, testnetApiKey: string);
|
|
6
|
+
getNft(params: GetNftParam): Promise<NftResponse>;
|
|
7
|
+
getNftsByAddress({ address }: GetNftsByAddressParams): Promise<NftsResponse>;
|
|
8
|
+
hasToken({ address, collectionHash }: HasTokenParam): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
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 _TatumRpcNDSSolana_network, _TatumRpcNDSSolana_connection, _TatumRpcNDSSolana_metaplex;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.TatumRpcNDSSolana = void 0;
|
|
25
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
26
|
+
const js_1 = require("@metaplex-foundation/js");
|
|
27
|
+
const BSSolanaCachedMethodsHelper_1 = require("../../helpers/BSSolanaCachedMethodsHelper");
|
|
28
|
+
const TatumRpcBDSSolana_1 = require("../blockchain-data/TatumRpcBDSSolana");
|
|
29
|
+
const BSSolanaHelper_1 = require("../../helpers/BSSolanaHelper");
|
|
30
|
+
class TatumRpcNDSSolana {
|
|
31
|
+
constructor(network, mainnetApiKey, testnetApiKey) {
|
|
32
|
+
_TatumRpcNDSSolana_network.set(this, void 0);
|
|
33
|
+
_TatumRpcNDSSolana_connection.set(this, void 0);
|
|
34
|
+
_TatumRpcNDSSolana_metaplex.set(this, void 0);
|
|
35
|
+
__classPrivateFieldSet(this, _TatumRpcNDSSolana_network, network, "f");
|
|
36
|
+
__classPrivateFieldSet(this, _TatumRpcNDSSolana_connection, TatumRpcBDSSolana_1.TatumRpcBDSSolana.getTatumConnection(__classPrivateFieldGet(this, _TatumRpcNDSSolana_network, "f"), BSSolanaHelper_1.BSSolanaHelper.isMainnet(network) ? mainnetApiKey : testnetApiKey), "f");
|
|
37
|
+
__classPrivateFieldSet(this, _TatumRpcNDSSolana_metaplex, js_1.Metaplex.make(__classPrivateFieldGet(this, _TatumRpcNDSSolana_connection, "f")), "f");
|
|
38
|
+
}
|
|
39
|
+
getNft(params) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
42
|
+
try {
|
|
43
|
+
const nftFromMetaplex = yield BSSolanaCachedMethodsHelper_1.BSSolanaCachedMethodsHelper.getMetaplexMetadata(params.tokenHash, __classPrivateFieldGet(this, _TatumRpcNDSSolana_connection, "f"));
|
|
44
|
+
if (!nftFromMetaplex || nftFromMetaplex.model !== 'nft') {
|
|
45
|
+
throw new Error('NFT not found');
|
|
46
|
+
}
|
|
47
|
+
let collectionName;
|
|
48
|
+
let collectionImage;
|
|
49
|
+
const collectionHash = (_b = (_a = nftFromMetaplex.collection) === null || _a === void 0 ? void 0 : _a.address.toBase58()) !== null && _b !== void 0 ? _b : params.collectionHash;
|
|
50
|
+
try {
|
|
51
|
+
const collectionMetaplex = yield BSSolanaCachedMethodsHelper_1.BSSolanaCachedMethodsHelper.getMetaplexMetadata(collectionHash, __classPrivateFieldGet(this, _TatumRpcNDSSolana_connection, "f"));
|
|
52
|
+
if ((collectionMetaplex === null || collectionMetaplex === void 0 ? void 0 : collectionMetaplex.model) === 'nft') {
|
|
53
|
+
collectionName = collectionMetaplex === null || collectionMetaplex === void 0 ? void 0 : collectionMetaplex.name;
|
|
54
|
+
collectionImage = (_c = collectionMetaplex === null || collectionMetaplex === void 0 ? void 0 : collectionMetaplex.json) === null || _c === void 0 ? void 0 : _c.image;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (_h) {
|
|
58
|
+
/* empty */
|
|
59
|
+
}
|
|
60
|
+
const nft = {
|
|
61
|
+
hash: params.tokenHash,
|
|
62
|
+
collection: {
|
|
63
|
+
hash: collectionHash,
|
|
64
|
+
name: collectionName,
|
|
65
|
+
image: collectionImage,
|
|
66
|
+
},
|
|
67
|
+
creator: {
|
|
68
|
+
address: (_f = (_e = (_d = nftFromMetaplex.creators) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.address.toBase58()) !== null && _f !== void 0 ? _f : '',
|
|
69
|
+
},
|
|
70
|
+
symbol: nftFromMetaplex.symbol,
|
|
71
|
+
image: (_g = nftFromMetaplex.json) === null || _g === void 0 ? void 0 : _g.image,
|
|
72
|
+
name: nftFromMetaplex.name,
|
|
73
|
+
};
|
|
74
|
+
return nft;
|
|
75
|
+
}
|
|
76
|
+
catch (_j) {
|
|
77
|
+
throw new Error('NFT not found');
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
getNftsByAddress(_a) {
|
|
82
|
+
return __awaiter(this, arguments, void 0, function* ({ address }) {
|
|
83
|
+
const nftsFromMetaplex = yield __classPrivateFieldGet(this, _TatumRpcNDSSolana_metaplex, "f").nfts().findAllByOwner({
|
|
84
|
+
owner: new web3_js_1.PublicKey(address),
|
|
85
|
+
});
|
|
86
|
+
const items = [];
|
|
87
|
+
const promises = nftsFromMetaplex.map((nftFromMetaplex) => __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
var _a, _b, _c, _d;
|
|
89
|
+
if (nftFromMetaplex.model === 'sft')
|
|
90
|
+
return;
|
|
91
|
+
let tokenHash;
|
|
92
|
+
let collectionHash;
|
|
93
|
+
if (nftFromMetaplex.model === 'nft') {
|
|
94
|
+
tokenHash = nftFromMetaplex.mint.address.toBase58();
|
|
95
|
+
collectionHash = (_b = (_a = nftFromMetaplex.collection) === null || _a === void 0 ? void 0 : _a.address.toBase58()) !== null && _b !== void 0 ? _b : '';
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
tokenHash = nftFromMetaplex.mintAddress.toBase58();
|
|
99
|
+
collectionHash = (_d = (_c = nftFromMetaplex.collection) === null || _c === void 0 ? void 0 : _c.address.toBase58()) !== null && _d !== void 0 ? _d : '';
|
|
100
|
+
}
|
|
101
|
+
const nft = yield this.getNft({
|
|
102
|
+
tokenHash,
|
|
103
|
+
collectionHash,
|
|
104
|
+
});
|
|
105
|
+
items.push(nft);
|
|
106
|
+
}));
|
|
107
|
+
yield Promise.allSettled(promises);
|
|
108
|
+
return {
|
|
109
|
+
items,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
hasToken(_a) {
|
|
114
|
+
return __awaiter(this, arguments, void 0, function* ({ address, collectionHash }) {
|
|
115
|
+
var _b;
|
|
116
|
+
const nftsFromMetaplex = yield __classPrivateFieldGet(this, _TatumRpcNDSSolana_metaplex, "f").nfts().findAllByOwner({
|
|
117
|
+
owner: new web3_js_1.PublicKey(address),
|
|
118
|
+
});
|
|
119
|
+
for (const nftFromMetaplex of nftsFromMetaplex) {
|
|
120
|
+
if (((_b = nftFromMetaplex.collection) === null || _b === void 0 ? void 0 : _b.address.toBase58()) === collectionHash) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.TatumRpcNDSSolana = TatumRpcNDSSolana;
|
|
129
|
+
_TatumRpcNDSSolana_network = new WeakMap(), _TatumRpcNDSSolana_connection = new WeakMap(), _TatumRpcNDSSolana_metaplex = new WeakMap();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenServiceSolana = void 0;
|
|
4
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
5
|
+
class TokenServiceSolana extends blockchain_service_1.TokenService {
|
|
6
|
+
normalizeHash(hash) {
|
|
7
|
+
return hash.startsWith('0x') ? hash.slice(2) : hash;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.TokenServiceSolana = TokenServiceSolana;
|
package/package.json
CHANGED
|
@@ -1,14 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-solana",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
7
|
+
"author": "Coz",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"files": [
|
|
10
|
+
"/dist"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@solana/web3.js": "~1.98.0",
|
|
14
|
+
"axios": "~1.11.0",
|
|
15
|
+
"bip39": "~3.1.0",
|
|
16
|
+
"micro-key-producer": "~0.7.5",
|
|
17
|
+
"bs58": "~6.0.0",
|
|
18
|
+
"@solana/spl-token": "~0.4.12",
|
|
19
|
+
"@bonfida/spl-name-service": "~3.0.9",
|
|
20
|
+
"@ledgerhq/hw-app-solana": "~7.2.4",
|
|
21
|
+
"@ledgerhq/hw-transport": "~6.30.5",
|
|
22
|
+
"@metaplex-foundation/js": "~0.20.1",
|
|
23
|
+
"dayjs": "~1.11.13",
|
|
24
|
+
"@cityofzion/blockchain-service": "1.21.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@ledgerhq/hw-transport-node-hid": "~6.28.5",
|
|
28
|
+
"@types/jest": "29.5.3",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
|
30
|
+
"@typescript-eslint/parser": "^6.5.0",
|
|
31
|
+
"eslint": "^8.48.0",
|
|
32
|
+
"jest": "29.6.2",
|
|
33
|
+
"ts-jest": "29.1.1",
|
|
34
|
+
"ts-node": "~10.9.2",
|
|
35
|
+
"typescript": "5.7.3"
|
|
9
36
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc --project tsconfig.build.json",
|
|
39
|
+
"test": "jest --config jest.config.ts",
|
|
40
|
+
"lint": "eslint .",
|
|
41
|
+
"format": "eslint --fix"
|
|
42
|
+
}
|
|
43
|
+
}
|