@airgap/wallet 0.13.11-beta.1 → 0.13.11-beta.2
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/index.d.ts +8 -0
- package/index.js +16 -0
- package/index.js.map +1 -0
- package/package.json +1 -5
- package/utils/address.d.ts +2 -0
- package/utils/address.js +13 -0
- package/utils/address.js.map +1 -0
- package/utils/protocol.d.ts +2 -0
- package/utils/protocol.js +64 -0
- package/utils/protocol.js.map +1 -0
- package/wallet/AirGapWallet.d.ts +32 -0
- package/wallet/AirGapWallet.js +152 -0
- package/wallet/AirGapWallet.js.map +1 -0
- package/wallet/offline/AirGapOfflineWallet.d.ts +7 -0
- package/wallet/offline/AirGapOfflineWallet.js +31 -0
- package/wallet/offline/AirGapOfflineWallet.js.map +1 -0
- package/wallet/online/AirGapCoinWallet.d.ts +20 -0
- package/wallet/online/AirGapCoinWallet.js +203 -0
- package/wallet/online/AirGapCoinWallet.js.map +1 -0
- package/wallet/online/AirGapNFTWallet.d.ts +16 -0
- package/wallet/online/AirGapNFTWallet.js +182 -0
- package/wallet/online/AirGapNFTWallet.js.map +1 -0
- package/wallet/online/AirGapOnlineWallet.d.ts +36 -0
- package/wallet/online/AirGapOnlineWallet.js +258 -0
- package/wallet/online/AirGapOnlineWallet.js.map +1 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AirGapWallet, AirGapWalletStatus, SerializedAirGapWallet } from './wallet/AirGapWallet';
|
|
2
|
+
import { AirGapOfflineWallet } from './wallet/offline/AirGapOfflineWallet';
|
|
3
|
+
import { AirGapCoinWallet, TimeInterval } from './wallet/online/AirGapCoinWallet';
|
|
4
|
+
import { AirGapNFTWallet } from './wallet/online/AirGapNFTWallet';
|
|
5
|
+
import { AirGapOnlineWallet, AirGapWalletPriceService } from './wallet/online/AirGapOnlineWallet';
|
|
6
|
+
export { AirGapWallet, AirGapOfflineWallet, AirGapOnlineWallet, AirGapCoinWallet, AirGapWalletStatus, AirGapNFTWallet };
|
|
7
|
+
export { SerializedAirGapWallet };
|
|
8
|
+
export { TimeInterval, AirGapWalletPriceService };
|
package/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimeInterval = exports.AirGapNFTWallet = exports.AirGapWalletStatus = exports.AirGapCoinWallet = exports.AirGapOnlineWallet = exports.AirGapOfflineWallet = exports.AirGapWallet = void 0;
|
|
4
|
+
var AirGapWallet_1 = require("./wallet/AirGapWallet");
|
|
5
|
+
Object.defineProperty(exports, "AirGapWallet", { enumerable: true, get: function () { return AirGapWallet_1.AirGapWallet; } });
|
|
6
|
+
Object.defineProperty(exports, "AirGapWalletStatus", { enumerable: true, get: function () { return AirGapWallet_1.AirGapWalletStatus; } });
|
|
7
|
+
var AirGapOfflineWallet_1 = require("./wallet/offline/AirGapOfflineWallet");
|
|
8
|
+
Object.defineProperty(exports, "AirGapOfflineWallet", { enumerable: true, get: function () { return AirGapOfflineWallet_1.AirGapOfflineWallet; } });
|
|
9
|
+
var AirGapCoinWallet_1 = require("./wallet/online/AirGapCoinWallet");
|
|
10
|
+
Object.defineProperty(exports, "AirGapCoinWallet", { enumerable: true, get: function () { return AirGapCoinWallet_1.AirGapCoinWallet; } });
|
|
11
|
+
Object.defineProperty(exports, "TimeInterval", { enumerable: true, get: function () { return AirGapCoinWallet_1.TimeInterval; } });
|
|
12
|
+
var AirGapNFTWallet_1 = require("./wallet/online/AirGapNFTWallet");
|
|
13
|
+
Object.defineProperty(exports, "AirGapNFTWallet", { enumerable: true, get: function () { return AirGapNFTWallet_1.AirGapNFTWallet; } });
|
|
14
|
+
var AirGapOnlineWallet_1 = require("./wallet/online/AirGapOnlineWallet");
|
|
15
|
+
Object.defineProperty(exports, "AirGapOnlineWallet", { enumerable: true, get: function () { return AirGapOnlineWallet_1.AirGapOnlineWallet; } });
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,sDAAgG;AAMvF,6FANA,2BAAY,OAMA;AAA6D,mGAN3D,iCAAkB,OAM2D;AALpG,4EAA0E;AAKnD,oGALd,yCAAmB,OAKc;AAJ1C,qEAAiF;AAIjB,iGAJvD,mCAAgB,OAIuD;AAMvE,6FAVkB,+BAAY,OAUlB;AATrB,mEAAiE;AAGqC,gGAH7F,iCAAe,OAG6F;AAFrH,yEAAiG;AAErD,mGAFnC,uCAAkB,OAEmC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airgap/wallet",
|
|
3
|
-
"version": "0.13.11-beta.
|
|
3
|
+
"version": "0.13.11-beta.2",
|
|
4
4
|
"description": "TODO",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"airgap"
|
|
@@ -14,10 +14,6 @@
|
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
|
-
"main": "dist/index.js",
|
|
18
|
-
"files": [
|
|
19
|
-
"dist"
|
|
20
|
-
],
|
|
21
17
|
"scripts": {
|
|
22
18
|
"build": "rm -rf ./dist && tsc && node scripts/copy-files-after-build.js && node scripts/make-ts-declaration-files-backwards-compatible.js",
|
|
23
19
|
"build-scripts": "tsc scripts/*.ts",
|
package/utils/address.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeAddress = void 0;
|
|
4
|
+
function normalizeAddress(address) {
|
|
5
|
+
return typeof address === 'string'
|
|
6
|
+
? {
|
|
7
|
+
address: address,
|
|
8
|
+
cursor: { hasNext: false }
|
|
9
|
+
}
|
|
10
|
+
: address;
|
|
11
|
+
}
|
|
12
|
+
exports.normalizeAddress = normalizeAddress;
|
|
13
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/utils/address.ts"],"names":[],"mappings":";;;AAEA,SAAgB,gBAAgB,CAAC,OAAmC;IAClE,OAAO,OAAO,OAAO,KAAK,QAAQ;QAChC,CAAC,CAAC;YACE,OAAO,SAAA;YACP,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;SAC3B;QACH,CAAC,CAAC,OAAO,CAAA;AACb,CAAC;AAPD,4CAOC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AddressWithCursor, ExtendedPublicKey, OfflineBip32Protocol, OnlineBip32Protocol } from '@airgap/module-kit';
|
|
2
|
+
export declare function deriveAddresses(protocol: OfflineBip32Protocol | OnlineBip32Protocol, publicKey: ExtendedPublicKey, visibilityIndex: number, amount: number, offset: number): Promise<AddressWithCursor[]>;
|
|
@@ -0,0 +1,64 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.deriveAddresses = void 0;
|
|
40
|
+
var address_1 = require("./address");
|
|
41
|
+
function deriveAddresses(protocol, publicKey, visibilityIndex, amount, offset) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
+
var generatorArray;
|
|
44
|
+
var _this = this;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
generatorArray = Array.from(new Array(amount), function (_, i) { return i + offset; });
|
|
47
|
+
return [2 /*return*/, Promise.all(generatorArray.map(function (x) { return __awaiter(_this, void 0, void 0, function () {
|
|
48
|
+
var derivedKey, _a;
|
|
49
|
+
return __generator(this, function (_b) {
|
|
50
|
+
switch (_b.label) {
|
|
51
|
+
case 0: return [4 /*yield*/, protocol.deriveFromExtendedPublicKey(publicKey, visibilityIndex, x)];
|
|
52
|
+
case 1:
|
|
53
|
+
derivedKey = _b.sent();
|
|
54
|
+
_a = address_1.normalizeAddress;
|
|
55
|
+
return [4 /*yield*/, protocol.getAddressFromPublicKey(derivedKey)];
|
|
56
|
+
case 2: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}); }))];
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.deriveAddresses = deriveAddresses;
|
|
64
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/utils/protocol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,qCAA4C;AAE5C,SAAsB,eAAe,CACnC,QAAoD,EACpD,SAA4B,EAC5B,eAAuB,EACvB,MAAc,EACd,MAAc;;;;;YAER,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,GAAG,MAAM,EAAV,CAAU,CAAC,CAAA;YAE1E,sBAAO,OAAO,CAAC,GAAG,CAChB,cAAc,CAAC,GAAG,CAAC,UAAO,CAAC;;;;oCACN,qBAAM,QAAQ,CAAC,2BAA2B,CAAC,SAAS,EAAE,eAAe,EAAE,CAAC,CAAC,EAAA;;gCAAtF,UAAU,GAAG,SAAyE;gCAErF,KAAA,0BAAgB,CAAA;gCAAC,qBAAM,QAAQ,CAAC,uBAAuB,CAAC,UAAU,CAAC,EAAA;oCAA1E,sBAAO,kBAAiB,SAAkD,EAAC,EAAA;;;qBAC5E,CAAC,CACH,EAAA;;;CACF;AAhBD,0CAgBC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ConditionViolationError } from '@airgap/coinlib-core/errors';
|
|
2
|
+
import { AirGapAnyProtocol, Bip32Extension, ExtendedPublicKey, PublicKey } from '@airgap/module-kit';
|
|
3
|
+
export declare enum AirGapWalletStatus {
|
|
4
|
+
ACTIVE = "active",
|
|
5
|
+
HIDDEN = "hidden",
|
|
6
|
+
DELETED = "deleted",
|
|
7
|
+
TRANSIENT = "transient"
|
|
8
|
+
}
|
|
9
|
+
export interface SerializedAirGapWallet {
|
|
10
|
+
protocolIdentifier: string;
|
|
11
|
+
publicKey: PublicKey | ExtendedPublicKey;
|
|
12
|
+
derivationPath: string;
|
|
13
|
+
addresses: string[];
|
|
14
|
+
masterFingerprint?: string;
|
|
15
|
+
status?: AirGapWalletStatus;
|
|
16
|
+
addressIndex?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare abstract class AirGapWallet<Protocol extends AirGapAnyProtocol = AirGapAnyProtocol, T extends Protocol | Bip32Extension<Protocol> = Protocol | Bip32Extension<Protocol>> {
|
|
19
|
+
protocol: T;
|
|
20
|
+
readonly publicKey: T extends Bip32Extension<Protocol> ? PublicKey | ExtendedPublicKey : T extends Protocol ? PublicKey : never;
|
|
21
|
+
readonly derivationPath: string;
|
|
22
|
+
readonly masterFingerprint: string;
|
|
23
|
+
status: AirGapWalletStatus;
|
|
24
|
+
addressIndex?: number | undefined;
|
|
25
|
+
addresses: string[];
|
|
26
|
+
constructor(protocol: T, publicKey: T extends Bip32Extension<Protocol> ? PublicKey | ExtendedPublicKey : T extends Protocol ? PublicKey : never, derivationPath: string, masterFingerprint: string, status: AirGapWalletStatus, addressIndex?: number | undefined);
|
|
27
|
+
readonly receivingPublicAddress: string;
|
|
28
|
+
setProtocol(protocol: T): Promise<void>;
|
|
29
|
+
deriveAddresses(amount?: number): Promise<string[]>;
|
|
30
|
+
toJSON(): Promise<SerializedAirGapWallet>;
|
|
31
|
+
protected xpubRequiresExtendedProtocolError(): ConditionViolationError;
|
|
32
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.AirGapWallet = exports.AirGapWalletStatus = void 0;
|
|
40
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
41
|
+
var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
|
|
42
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
43
|
+
var address_1 = require("../utils/address");
|
|
44
|
+
var protocol_1 = require("../utils/protocol");
|
|
45
|
+
var AirGapWalletStatus;
|
|
46
|
+
(function (AirGapWalletStatus) {
|
|
47
|
+
AirGapWalletStatus["ACTIVE"] = "active";
|
|
48
|
+
AirGapWalletStatus["HIDDEN"] = "hidden";
|
|
49
|
+
AirGapWalletStatus["DELETED"] = "deleted";
|
|
50
|
+
AirGapWalletStatus["TRANSIENT"] = "transient";
|
|
51
|
+
})(AirGapWalletStatus = exports.AirGapWalletStatus || (exports.AirGapWalletStatus = {}));
|
|
52
|
+
var AirGapWallet = /** @class */ (function () {
|
|
53
|
+
function AirGapWallet(protocol, publicKey, derivationPath, masterFingerprint, status, addressIndex) {
|
|
54
|
+
this.protocol = protocol;
|
|
55
|
+
this.publicKey = publicKey;
|
|
56
|
+
this.derivationPath = derivationPath;
|
|
57
|
+
this.masterFingerprint = masterFingerprint;
|
|
58
|
+
this.status = status;
|
|
59
|
+
this.addressIndex = addressIndex;
|
|
60
|
+
this.addresses = []; // used for cache
|
|
61
|
+
}
|
|
62
|
+
Object.defineProperty(AirGapWallet.prototype, "receivingPublicAddress", {
|
|
63
|
+
get: function () {
|
|
64
|
+
return this.addresses[this.addressIndex !== undefined ? this.addressIndex : 0];
|
|
65
|
+
},
|
|
66
|
+
enumerable: false,
|
|
67
|
+
configurable: true
|
|
68
|
+
});
|
|
69
|
+
AirGapWallet.prototype.setProtocol = function (protocol) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
var _a, currentProtocolIdentifier, nextProtocolIdentifier;
|
|
72
|
+
return __generator(this, function (_b) {
|
|
73
|
+
switch (_b.label) {
|
|
74
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
75
|
+
this.protocol.getMetadata().then(function (metadata) { return metadata.identifier; }),
|
|
76
|
+
protocol.getMetadata().then(function (metadata) { return metadata.identifier; })
|
|
77
|
+
])];
|
|
78
|
+
case 1:
|
|
79
|
+
_a = _b.sent(), currentProtocolIdentifier = _a[0], nextProtocolIdentifier = _a[1];
|
|
80
|
+
if (nextProtocolIdentifier !== currentProtocolIdentifier) {
|
|
81
|
+
throw new errors_1.ConditionViolationError(coinlib_error_1.Domain.WALLET, 'Can only set same protocol with a different network');
|
|
82
|
+
}
|
|
83
|
+
this.protocol = protocol;
|
|
84
|
+
return [2 /*return*/];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
AirGapWallet.prototype.deriveAddresses = function (amount) {
|
|
90
|
+
if (amount === void 0) { amount = 50; }
|
|
91
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
+
var addresses, parts, offset, _a;
|
|
93
|
+
return __generator(this, function (_b) {
|
|
94
|
+
switch (_b.label) {
|
|
95
|
+
case 0:
|
|
96
|
+
if (!(this.publicKey.type === 'xpub')) return [3 /*break*/, 2];
|
|
97
|
+
if (!(0, module_kit_1.isBip32Protocol)(this.protocol)) {
|
|
98
|
+
// This *should* never happen because of how the constructor is typed, but the compiler doesn't know it.
|
|
99
|
+
// TODO: check if there's a way to tell the compiler here that `publicKey: ExtendedPublicKey => protocol: AirGapAnyExtendedProtocol`
|
|
100
|
+
throw this.xpubRequiresExtendedProtocolError();
|
|
101
|
+
}
|
|
102
|
+
parts = this.derivationPath.split('/');
|
|
103
|
+
offset = 0;
|
|
104
|
+
if (!parts[parts.length - 1].endsWith("'")) {
|
|
105
|
+
offset = Number.parseInt(parts[parts.length - 1], 10);
|
|
106
|
+
}
|
|
107
|
+
return [4 /*yield*/, Promise.all([
|
|
108
|
+
(0, protocol_1.deriveAddresses)(this.protocol, this.publicKey, 0, amount, offset),
|
|
109
|
+
(0, protocol_1.deriveAddresses)(this.protocol, this.publicKey, 1, amount, offset)
|
|
110
|
+
])];
|
|
111
|
+
case 1:
|
|
112
|
+
addresses = (_b.sent()).reduce(function (flatten, next) { return flatten.concat(next); }, []);
|
|
113
|
+
return [3 /*break*/, 4];
|
|
114
|
+
case 2:
|
|
115
|
+
_a = address_1.normalizeAddress;
|
|
116
|
+
return [4 /*yield*/, this.protocol.getAddressFromPublicKey(this.publicKey)];
|
|
117
|
+
case 3:
|
|
118
|
+
addresses = [_a.apply(void 0, [_b.sent()])];
|
|
119
|
+
_b.label = 4;
|
|
120
|
+
case 4: return [2 /*return*/, addresses.map(function (address) { return address.address; })];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
AirGapWallet.prototype.toJSON = function () {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
+
var protocolIdentifier;
|
|
128
|
+
return __generator(this, function (_a) {
|
|
129
|
+
switch (_a.label) {
|
|
130
|
+
case 0: return [4 /*yield*/, this.protocol.getMetadata()];
|
|
131
|
+
case 1:
|
|
132
|
+
protocolIdentifier = (_a.sent()).identifier;
|
|
133
|
+
return [2 /*return*/, {
|
|
134
|
+
protocolIdentifier: protocolIdentifier,
|
|
135
|
+
publicKey: this.publicKey,
|
|
136
|
+
derivationPath: this.derivationPath,
|
|
137
|
+
addresses: this.addresses,
|
|
138
|
+
masterFingerprint: this.masterFingerprint,
|
|
139
|
+
status: this.status,
|
|
140
|
+
addressIndex: this.addressIndex
|
|
141
|
+
}];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
AirGapWallet.prototype.xpubRequiresExtendedProtocolError = function () {
|
|
147
|
+
return new errors_1.ConditionViolationError(coinlib_error_1.Domain.WALLET, 'Extended public keys are supported only when paired with an extended protocol');
|
|
148
|
+
};
|
|
149
|
+
return AirGapWallet;
|
|
150
|
+
}());
|
|
151
|
+
exports.AirGapWallet = AirGapWallet;
|
|
152
|
+
//# sourceMappingURL=AirGapWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AirGapWallet.js","sourceRoot":"","sources":["../../src/wallet/AirGapWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAqE;AACrE,2EAAkE;AAClE,iDAAwI;AAExI,4CAAmD;AACnD,8CAAmD;AAEnD,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;IACjB,yCAAmB,CAAA;IACnB,6CAAuB,CAAA;AACzB,CAAC,EALW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QA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AO,EAAf,CAAe,CAAC,EAAA;;;;KACtE;IAEY,6BAAM,GAAnB;;;;;4BAC8B,qBAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAA;;wBAAvD,kBAAkB,GAAG,CAAC,SAAiC,CAAC,CAAC,UAAU;wBAEzE,sBAAO;gCACL,kBAAkB,oBAAA;gCAClB,SAAS,EAAE,IAAI,CAAC,SAAS;gCACzB,cAAc,EAAE,IAAI,CAAC,cAAc;gCACnC,SAAS,EAAE,IAAI,CAAC,SAAS;gCACzB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;gCACzC,MAAM,EAAE,IAAI,CAAC,MAAM;gCACnB,YAAY,EAAE,IAAI,CAAC,YAAY;6BAChC,EAAA;;;;KACF;IAES,wDAAiC,GAA3C;QACE,OAAO,IAAI,gCAAuB,CAAC,sBAAM,CAAC,MAAM,EAAE,+EAA+E,CAAC,CAAA;IACpI,CAAC;IACH,mBAAC;AAAD,CAAC,AA9ED,IA8EC;AA9EqB,oCAAY"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AirGapOfflineProtocol, Bip32Extension } from '@airgap/module-kit';
|
|
2
|
+
import { AirGapWallet, SerializedAirGapWallet } from '../AirGapWallet';
|
|
3
|
+
export interface SerializedAirGapOfflineWallet extends SerializedAirGapWallet {
|
|
4
|
+
}
|
|
5
|
+
export declare class AirGapOfflineWallet<T extends AirGapOfflineProtocol | Bip32Extension<AirGapOfflineProtocol> = AirGapOfflineProtocol | Bip32Extension<AirGapOfflineProtocol>> extends AirGapWallet<AirGapOfflineProtocol, T> {
|
|
6
|
+
toJSON(): Promise<SerializedAirGapOfflineWallet>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AirGapOfflineWallet = void 0;
|
|
19
|
+
var AirGapWallet_1 = require("../AirGapWallet");
|
|
20
|
+
var AirGapOfflineWallet = /** @class */ (function (_super) {
|
|
21
|
+
__extends(AirGapOfflineWallet, _super);
|
|
22
|
+
function AirGapOfflineWallet() {
|
|
23
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24
|
+
}
|
|
25
|
+
AirGapOfflineWallet.prototype.toJSON = function () {
|
|
26
|
+
return _super.prototype.toJSON.call(this);
|
|
27
|
+
};
|
|
28
|
+
return AirGapOfflineWallet;
|
|
29
|
+
}(AirGapWallet_1.AirGapWallet));
|
|
30
|
+
exports.AirGapOfflineWallet = AirGapOfflineWallet;
|
|
31
|
+
//# sourceMappingURL=AirGapOfflineWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AirGapOfflineWallet.js","sourceRoot":"","sources":["../../../src/wallet/offline/AirGapOfflineWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA,gDAAsE;AAItE;IAEU,uCAAsC;IAFhD;;IAMA,CAAC;IAHQ,oCAAM,GAAb;QACE,OAAO,iBAAM,MAAM,WAAE,CAAA;IACvB,CAAC;IACH,0BAAC;AAAD,CAAC,AAND,CAEU,2BAAY,GAIrB;AANY,kDAAmB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import BigNumber from '@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber';
|
|
2
|
+
import { AirGapOnlineProtocol, Bip32Extension } from '@airgap/module-kit';
|
|
3
|
+
import { AirGapOnlineWallet } from './AirGapOnlineWallet';
|
|
4
|
+
export declare enum TimeInterval {
|
|
5
|
+
HOURS = "24h",
|
|
6
|
+
DAYS = "7d",
|
|
7
|
+
MONTH = "30d"
|
|
8
|
+
}
|
|
9
|
+
export declare class AirGapCoinWallet<T extends AirGapOnlineProtocol | Bip32Extension<AirGapOnlineProtocol> = AirGapOnlineProtocol | Bip32Extension<AirGapOnlineProtocol>> extends AirGapOnlineWallet<T> {
|
|
10
|
+
private currentBalance;
|
|
11
|
+
getCurrentBalance(): BigNumber | undefined;
|
|
12
|
+
setCurrentBalance(balance: BigNumber | undefined): void;
|
|
13
|
+
currentMarketPrice: BigNumber | undefined;
|
|
14
|
+
getCurrentMarketPrice(): BigNumber | undefined;
|
|
15
|
+
setCurrentMarketPrice(marketPrice: BigNumber | undefined): Promise<void>;
|
|
16
|
+
protected _synchronize(): Promise<void>;
|
|
17
|
+
protected reset(): void;
|
|
18
|
+
fetchCurrentMarketPrice(baseSymbol?: string): Promise<BigNumber>;
|
|
19
|
+
balanceOf(): Promise<BigNumber>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.AirGapCoinWallet = exports.TimeInterval = void 0;
|
|
58
|
+
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
59
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
60
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
61
|
+
var protocol_1 = require("@airgap/module-kit/utils/protocol");
|
|
62
|
+
var AirGapOnlineWallet_1 = require("./AirGapOnlineWallet");
|
|
63
|
+
var TimeInterval;
|
|
64
|
+
(function (TimeInterval) {
|
|
65
|
+
TimeInterval["HOURS"] = "24h";
|
|
66
|
+
TimeInterval["DAYS"] = "7d";
|
|
67
|
+
TimeInterval["MONTH"] = "30d";
|
|
68
|
+
})(TimeInterval = exports.TimeInterval || (exports.TimeInterval = {}));
|
|
69
|
+
var AirGapCoinWallet = /** @class */ (function (_super) {
|
|
70
|
+
__extends(AirGapCoinWallet, _super);
|
|
71
|
+
function AirGapCoinWallet() {
|
|
72
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
73
|
+
}
|
|
74
|
+
AirGapCoinWallet.prototype.getCurrentBalance = function () {
|
|
75
|
+
return this.currentBalance;
|
|
76
|
+
};
|
|
77
|
+
AirGapCoinWallet.prototype.setCurrentBalance = function (balance) {
|
|
78
|
+
this.currentBalance = balance;
|
|
79
|
+
};
|
|
80
|
+
AirGapCoinWallet.prototype.getCurrentMarketPrice = function () {
|
|
81
|
+
return this.currentMarketPrice;
|
|
82
|
+
};
|
|
83
|
+
AirGapCoinWallet.prototype.setCurrentMarketPrice = function (marketPrice) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
var networkType;
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
switch (_a.label) {
|
|
88
|
+
case 0: return [4 /*yield*/, this.protocol.getNetwork()];
|
|
89
|
+
case 1:
|
|
90
|
+
networkType = (_a.sent()).type;
|
|
91
|
+
this.currentMarketPrice = networkType === 'mainnet' ? marketPrice : new bignumber_1.default(0);
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
AirGapCoinWallet.prototype._synchronize = function () {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
+
var _a, balance, marketPrice;
|
|
100
|
+
return __generator(this, function (_b) {
|
|
101
|
+
switch (_b.label) {
|
|
102
|
+
case 0: return [4 /*yield*/, Promise.all([this.balanceOf(), this.fetchCurrentMarketPrice()])];
|
|
103
|
+
case 1:
|
|
104
|
+
_a = _b.sent(), balance = _a[0], marketPrice = _a[1];
|
|
105
|
+
this.setCurrentBalance(balance);
|
|
106
|
+
return [4 /*yield*/, this.setCurrentMarketPrice(marketPrice)];
|
|
107
|
+
case 2:
|
|
108
|
+
_b.sent();
|
|
109
|
+
return [2 /*return*/];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
AirGapCoinWallet.prototype.reset = function () {
|
|
115
|
+
this.currentBalance = undefined;
|
|
116
|
+
this.currentMarketPrice = undefined;
|
|
117
|
+
};
|
|
118
|
+
AirGapCoinWallet.prototype.fetchCurrentMarketPrice = function (baseSymbol) {
|
|
119
|
+
if (baseSymbol === void 0) { baseSymbol = 'USD'; }
|
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
+
var marketPrice;
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
switch (_a.label) {
|
|
124
|
+
case 0: return [4 /*yield*/, this.priceService.getCurrentMarketPrice(this.protocol, baseSymbol)];
|
|
125
|
+
case 1:
|
|
126
|
+
marketPrice = _a.sent();
|
|
127
|
+
return [4 /*yield*/, this.setCurrentMarketPrice(marketPrice)];
|
|
128
|
+
case 2:
|
|
129
|
+
_a.sent();
|
|
130
|
+
return [2 /*return*/, marketPrice];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
AirGapCoinWallet.prototype.balanceOf = function () {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
137
|
+
var protocolMetadata, protocolIdentifier, balance, _a, result;
|
|
138
|
+
return __generator(this, function (_b) {
|
|
139
|
+
switch (_b.label) {
|
|
140
|
+
case 0: return [4 /*yield*/, this.protocol.getMetadata()];
|
|
141
|
+
case 1:
|
|
142
|
+
protocolMetadata = _b.sent();
|
|
143
|
+
protocolIdentifier = protocolMetadata.identifier;
|
|
144
|
+
if (!((protocolIdentifier === coinlib_core_1.MainProtocolSymbols.BTC ||
|
|
145
|
+
protocolIdentifier === coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT ||
|
|
146
|
+
protocolIdentifier === coinlib_core_1.MainProtocolSymbols.GRS) &&
|
|
147
|
+
this.publicKey.type === 'xpub' &&
|
|
148
|
+
(0, module_kit_1.isBip32Protocol)(this.protocol))) return [3 /*break*/, 3];
|
|
149
|
+
return [4 /*yield*/, this.protocol.getBalanceOfPublicKey(this.publicKey)];
|
|
150
|
+
case 2:
|
|
151
|
+
// TODO: Remove and test
|
|
152
|
+
/*
|
|
153
|
+
We should remove this if BTC also uses blockbook. (And change the order of the if/else below)
|
|
154
|
+
|
|
155
|
+
The problem is that we have addresses cached for all protocols. But blockbook (grs) doesn't allow
|
|
156
|
+
multiple addresses to be checked at once, so we need to xPub key there (or we would do 100s of requests).
|
|
157
|
+
|
|
158
|
+
We can also not simply change the order of the following if/else, because then it would use the xPub method for
|
|
159
|
+
BTC as well, which results in the addresses being derived again, which causes massive lags in the apps.
|
|
160
|
+
*/
|
|
161
|
+
balance = _b.sent();
|
|
162
|
+
return [3 /*break*/, 12];
|
|
163
|
+
case 3:
|
|
164
|
+
if (!((this.addresses.length > 0 && (0, protocol_1.canFetchDataForAddress)(this.protocol)) || (0, protocol_1.canFetchDataForMultipleAddresses)(this.protocol))) return [3 /*break*/, 8];
|
|
165
|
+
if (!(0, protocol_1.canFetchDataForMultipleAddresses)(this.protocol)) return [3 /*break*/, 5];
|
|
166
|
+
return [4 /*yield*/, this.protocol.getBalanceOfAddresses(this.addressesToCheck())];
|
|
167
|
+
case 4:
|
|
168
|
+
_a = _b.sent();
|
|
169
|
+
return [3 /*break*/, 7];
|
|
170
|
+
case 5: return [4 /*yield*/, this.protocol.getBalanceOfAddress(this.addressesToCheck()[0])];
|
|
171
|
+
case 6:
|
|
172
|
+
_a = _b.sent();
|
|
173
|
+
_b.label = 7;
|
|
174
|
+
case 7:
|
|
175
|
+
balance = _a;
|
|
176
|
+
return [3 /*break*/, 12];
|
|
177
|
+
case 8:
|
|
178
|
+
if (!(this.publicKey.type === 'xpub')) return [3 /*break*/, 10];
|
|
179
|
+
if (!(0, module_kit_1.isBip32Protocol)(this.protocol)) {
|
|
180
|
+
// This *should* never happen because of how the constructor is typed, but the compiler doesn't know it.
|
|
181
|
+
// TODO: check if there's a way to tell the compiler here that `publicKey: ExtendedPublicKey => protocol: AirGapOnlineExtendedProtocol`
|
|
182
|
+
throw this.xpubRequiresExtendedProtocolError();
|
|
183
|
+
}
|
|
184
|
+
return [4 /*yield*/, this.protocol.getBalanceOfPublicKey(this.publicKey)];
|
|
185
|
+
case 9:
|
|
186
|
+
balance = _b.sent();
|
|
187
|
+
return [3 /*break*/, 12];
|
|
188
|
+
case 10: return [4 /*yield*/, this.protocol.getBalanceOfPublicKey(this.publicKey)];
|
|
189
|
+
case 11:
|
|
190
|
+
balance = _b.sent();
|
|
191
|
+
_b.label = 12;
|
|
192
|
+
case 12:
|
|
193
|
+
result = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).blockchain(protocolMetadata.units).value);
|
|
194
|
+
this.setCurrentBalance(result);
|
|
195
|
+
return [2 /*return*/, result];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
return AirGapCoinWallet;
|
|
201
|
+
}(AirGapOnlineWallet_1.AirGapOnlineWallet));
|
|
202
|
+
exports.AirGapCoinWallet = AirGapCoinWallet;
|
|
203
|
+
//# sourceMappingURL=AirGapCoinWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AirGapCoinWallet.js","sourceRoot":"","sources":["../../../src/wallet/online/AirGapCoinWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA0D;AAC1D,iHAA0F;AAC1F,iDAA8G;AAC9G,8DAA4G;AAE5G,2DAAyD;AAEzD,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,6BAAa,CAAA;IACb,2BAAW,CAAA;IACX,6BAAa,CAAA;AACf,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAED;IAEU,oCAAqB;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E,OAAO,KAEgE,CAAA;;;6BAC9D,CAAA,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,MAAM,CAAA,EAA9B,yBAA8B;wBACvC,IAAI,CAAC,IAAA,4BAAe,EAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;4BACnC,wGAAwG;4BACxG,uIAAuI;4BACvI,MAAM,IAAI,CAAC,iCAAiC,EAAE,CAAA;yBAC/C;wBAES,qBAAM,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAA;;wBAAnE,OAAO,GAAG,SAAyD,CAAA;;6BAEzD,qBAAM,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAA;;wBAAnE,OAAO,GAAG,SAAyD,CAAA;;;wBAG/D,MAAM,GAAc,IAAI,mBAAS,CAAC,IAAA,sBAAS,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAA;wBAE1G,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA;wBAE9B,sBAAO,MAAM,EAAA;;;;KACd;IACH,uBAAC;AAAD,CAAC,AAvFD,CAEU,uCAAkB,GAqF3B;AAvFY,4CAAgB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import BigNumber from '@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber';
|
|
2
|
+
import { AirGapOnlineProtocol, Bip32Extension } from '@airgap/module-kit';
|
|
3
|
+
import { AirGapOnlineWallet } from './AirGapOnlineWallet';
|
|
4
|
+
export declare class AirGapNFTWallet<T extends AirGapOnlineProtocol | Bip32Extension<AirGapOnlineProtocol> = AirGapOnlineProtocol | Bip32Extension<AirGapOnlineProtocol>> extends AirGapOnlineWallet<T> {
|
|
5
|
+
private currentBalance;
|
|
6
|
+
getCurrentBalance(assetID: string): BigNumber | undefined;
|
|
7
|
+
setCurrentBalance(balance: BigNumber | undefined, assetID: string): void;
|
|
8
|
+
private currentMarketPrice;
|
|
9
|
+
getCurrentMarketPrice(assetID: string): BigNumber | undefined;
|
|
10
|
+
setCurrentMarketPrice(marketPrice: BigNumber | undefined, assetID: string): Promise<void>;
|
|
11
|
+
synchronize(assetsID?: string[]): Promise<void>;
|
|
12
|
+
protected _synchronize(assetIDs?: string[]): Promise<void>;
|
|
13
|
+
protected reset(): void;
|
|
14
|
+
fetchCurrentMarketPrice(assetID: string, _baseSymbol?: string): Promise<BigNumber>;
|
|
15
|
+
balanceOf(assetID: string): Promise<BigNumber>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.AirGapNFTWallet = void 0;
|
|
58
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
59
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
60
|
+
var AirGapOnlineWallet_1 = require("./AirGapOnlineWallet");
|
|
61
|
+
var AirGapNFTWallet = /** @class */ (function (_super) {
|
|
62
|
+
__extends(AirGapNFTWallet, _super);
|
|
63
|
+
function AirGapNFTWallet() {
|
|
64
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
65
|
+
_this.currentBalance = {};
|
|
66
|
+
_this.currentMarketPrice = {};
|
|
67
|
+
return _this;
|
|
68
|
+
}
|
|
69
|
+
AirGapNFTWallet.prototype.getCurrentBalance = function (assetID) {
|
|
70
|
+
return this.currentBalance[assetID];
|
|
71
|
+
};
|
|
72
|
+
AirGapNFTWallet.prototype.setCurrentBalance = function (balance, assetID) {
|
|
73
|
+
this.currentBalance[assetID] = balance;
|
|
74
|
+
};
|
|
75
|
+
AirGapNFTWallet.prototype.getCurrentMarketPrice = function (assetID) {
|
|
76
|
+
return this.currentMarketPrice[assetID];
|
|
77
|
+
};
|
|
78
|
+
AirGapNFTWallet.prototype.setCurrentMarketPrice = function (marketPrice, assetID) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
+
var networkType;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
83
|
+
case 0: return [4 /*yield*/, this.protocol.getNetwork()];
|
|
84
|
+
case 1:
|
|
85
|
+
networkType = (_a.sent()).type;
|
|
86
|
+
this.currentMarketPrice[assetID] = networkType === 'mainnet' ? marketPrice : new bignumber_1.default(0);
|
|
87
|
+
return [2 /*return*/];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
AirGapNFTWallet.prototype.synchronize = function (assetsID) {
|
|
93
|
+
if (assetsID === void 0) { assetsID = []; }
|
|
94
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
return [2 /*return*/, _super.prototype.synchronize.call(this, assetsID)];
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
AirGapNFTWallet.prototype._synchronize = function (assetIDs) {
|
|
101
|
+
if (assetIDs === void 0) { assetIDs = []; }
|
|
102
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
+
var _this = this;
|
|
104
|
+
return __generator(this, function (_a) {
|
|
105
|
+
switch (_a.label) {
|
|
106
|
+
case 0: return [4 /*yield*/, Promise.all(assetIDs.map(function (assetID) { return __awaiter(_this, void 0, void 0, function () {
|
|
107
|
+
var _a, balance, marketPrice;
|
|
108
|
+
return __generator(this, function (_b) {
|
|
109
|
+
switch (_b.label) {
|
|
110
|
+
case 0: return [4 /*yield*/, Promise.all([this.balanceOf(assetID), this.fetchCurrentMarketPrice(assetID)])];
|
|
111
|
+
case 1:
|
|
112
|
+
_a = _b.sent(), balance = _a[0], marketPrice = _a[1];
|
|
113
|
+
this.setCurrentBalance(balance, assetID);
|
|
114
|
+
return [4 /*yield*/, this.setCurrentMarketPrice(marketPrice, assetID)];
|
|
115
|
+
case 2:
|
|
116
|
+
_b.sent();
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}); }))];
|
|
121
|
+
case 1:
|
|
122
|
+
_a.sent();
|
|
123
|
+
return [2 /*return*/];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
AirGapNFTWallet.prototype.reset = function () {
|
|
129
|
+
this.currentBalance = {};
|
|
130
|
+
this.currentMarketPrice = {};
|
|
131
|
+
};
|
|
132
|
+
AirGapNFTWallet.prototype.fetchCurrentMarketPrice = function (assetID, _baseSymbol) {
|
|
133
|
+
if (_baseSymbol === void 0) { _baseSymbol = 'USD'; }
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
var result;
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
result = new bignumber_1.default(0);
|
|
140
|
+
return [4 /*yield*/, this.setCurrentMarketPrice(result, assetID)];
|
|
141
|
+
case 1:
|
|
142
|
+
_a.sent();
|
|
143
|
+
return [2 /*return*/, result];
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
AirGapNFTWallet.prototype.balanceOf = function (assetID) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
+
var protocolMetadata, balance, result;
|
|
151
|
+
return __generator(this, function (_a) {
|
|
152
|
+
switch (_a.label) {
|
|
153
|
+
case 0: return [4 /*yield*/, this.protocol.getMetadata()];
|
|
154
|
+
case 1:
|
|
155
|
+
protocolMetadata = _a.sent();
|
|
156
|
+
if (!(this.publicKey.type === 'xpub')) return [3 /*break*/, 3];
|
|
157
|
+
if (!(0, module_kit_1.isBip32Protocol)(this.protocol)) {
|
|
158
|
+
// This *should* never happen because of how the constructor is typed, but the compiler doesn't know it.
|
|
159
|
+
// TODO: check if there's a way to tell the compiler here that `publicKey: ExtendedPublicKey => protocol: AirGapOnlineExtendedProtocol`
|
|
160
|
+
throw this.xpubRequiresExtendedProtocolError();
|
|
161
|
+
}
|
|
162
|
+
return [4 /*yield*/, this.protocol.getBalanceOfPublicKey(this.publicKey /* { assetID } */)];
|
|
163
|
+
case 2:
|
|
164
|
+
// TODO: handle assetID
|
|
165
|
+
balance = _a.sent();
|
|
166
|
+
return [3 /*break*/, 5];
|
|
167
|
+
case 3: return [4 /*yield*/, this.protocol.getBalanceOfPublicKey(this.publicKey /* { addressIndex: this.addressIndex, assetID } */)];
|
|
168
|
+
case 4:
|
|
169
|
+
balance = _a.sent();
|
|
170
|
+
_a.label = 5;
|
|
171
|
+
case 5:
|
|
172
|
+
result = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).blockchain(protocolMetadata.units).value);
|
|
173
|
+
this.setCurrentBalance(result, assetID);
|
|
174
|
+
return [2 /*return*/, result];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
return AirGapNFTWallet;
|
|
180
|
+
}(AirGapOnlineWallet_1.AirGapOnlineWallet));
|
|
181
|
+
exports.AirGapNFTWallet = AirGapNFTWallet;
|
|
182
|
+
//# sourceMappingURL=AirGapNFTWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AirGapNFTWallet.js","sourceRoot":"","sources":["../../../src/wallet/online/AirGapNFTWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iHAA0F;AAC1F,iDAA8G;AAE9G,2DAAyD;AAEzD;IAEU,mCAAqB;IAF/B;QAAA,qEA0EC;QAvES,oBAAc,GAA0C,EAAE,CAAA;QAU1D,wBAAkB,GAA0C,EAAE,CAAA;;IA6DxE,CAAC;IArEQ,2CAAiB,GAAxB,UAAyB,OAAe;QACtC,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IACrC,CAAC;IAEM,2CAAiB,GAAxB,UAAyB,OAA8B,EAAE,OAAe;QACtE,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA;IACxC,CAAC;IAIM,+CAAqB,GAA5B,UAA6B,OAAe;QAC1C,OAAO,I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|
+
import BigNumber from '@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber';
|
|
2
|
+
import { AirGapOnlineProtocol, AirGapTransactionsWithCursor, Amount, Bip32Extension, ExtendedPublicKey, FeeEstimation, PublicKey, TransactionCursor, TransactionDetails, UnsignedTransaction } from '@airgap/module-kit';
|
|
3
|
+
import { AirGapWallet, AirGapWalletStatus, SerializedAirGapWallet } from '../AirGapWallet';
|
|
4
|
+
export interface SerializedAirGapOnlineWallet extends SerializedAirGapWallet {
|
|
5
|
+
networkIdentifier: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AirGapWalletPriceService {
|
|
8
|
+
getCurrentMarketPrice(protocol: AirGapOnlineProtocol, baseSymbol: string): Promise<BigNumber>;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class AirGapOnlineWallet<T extends AirGapOnlineProtocol | Bip32Extension<AirGapOnlineProtocol> = AirGapOnlineProtocol | Bip32Extension<AirGapOnlineProtocol>> extends AirGapWallet<AirGapOnlineProtocol, T> {
|
|
11
|
+
readonly priceService: AirGapWalletPriceService;
|
|
12
|
+
private synchronizePromise?;
|
|
13
|
+
constructor(protocol: T, publicKey: T extends Bip32Extension<AirGapOnlineProtocol> ? PublicKey | ExtendedPublicKey : T extends AirGapOnlineProtocol ? PublicKey : never, derivationPath: string, masterFingerprint: string, status: AirGapWalletStatus, priceService: AirGapWalletPriceService, addressIndex?: number);
|
|
14
|
+
abstract getCurrentBalance(...args: any): BigNumber | undefined;
|
|
15
|
+
abstract setCurrentBalance(balance: BigNumber | undefined, ...args: any): void;
|
|
16
|
+
abstract getCurrentMarketPrice(...args: any): BigNumber | undefined;
|
|
17
|
+
abstract setCurrentMarketPrice(balance: BigNumber | undefined, ...args: any): void;
|
|
18
|
+
abstract fetchCurrentMarketPrice(...args: any): Promise<BigNumber>;
|
|
19
|
+
abstract balanceOf(...args: any): Promise<BigNumber>;
|
|
20
|
+
protected abstract _synchronize(...args: any): Promise<void>;
|
|
21
|
+
protected abstract reset(): void;
|
|
22
|
+
protected addressesToCheck(): string[];
|
|
23
|
+
setProtocol(protocol: T): Promise<void>;
|
|
24
|
+
synchronize(...args: any): Promise<void>;
|
|
25
|
+
fetchTransactions(limit: number, cursor?: TransactionCursor): Promise<AirGapTransactionsWithCursor>;
|
|
26
|
+
prepareTransaction(details: TransactionDetails[], fee?: Amount, data?: {
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}): Promise<UnsignedTransaction>;
|
|
29
|
+
getMaxTransferValue(recipients: string[], fee?: Amount, data?: {
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}): Promise<Amount>;
|
|
32
|
+
estimateFees(details: TransactionDetails[], data?: {
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}): Promise<FeeEstimation | undefined>;
|
|
35
|
+
toJSON(): Promise<SerializedAirGapOnlineWallet>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
+
function step(op) {
|
|
42
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
+
while (_) try {
|
|
44
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
+
switch (op[0]) {
|
|
47
|
+
case 0: case 1: t = op; break;
|
|
48
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
+
default:
|
|
52
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
+
if (t[2]) _.ops.pop();
|
|
57
|
+
_.trys.pop(); continue;
|
|
58
|
+
}
|
|
59
|
+
op = body.call(thisArg, _);
|
|
60
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.AirGapOnlineWallet = void 0;
|
|
66
|
+
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
67
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
68
|
+
var protocol_1 = require("@airgap/module-kit/utils/protocol");
|
|
69
|
+
var AirGapWallet_1 = require("../AirGapWallet");
|
|
70
|
+
var AirGapOnlineWallet = /** @class */ (function (_super) {
|
|
71
|
+
__extends(AirGapOnlineWallet, _super);
|
|
72
|
+
function AirGapOnlineWallet(protocol, publicKey, derivationPath, masterFingerprint, status, priceService, addressIndex) {
|
|
73
|
+
var _this = _super.call(this, protocol, publicKey, derivationPath, masterFingerprint, status, addressIndex) || this;
|
|
74
|
+
_this.priceService = priceService;
|
|
75
|
+
return _this;
|
|
76
|
+
}
|
|
77
|
+
AirGapOnlineWallet.prototype.addressesToCheck = function () {
|
|
78
|
+
var addressesToReceive = this.addressIndex !== undefined ? [this.addresses[this.addressIndex]] : this.addresses;
|
|
79
|
+
return addressesToReceive;
|
|
80
|
+
};
|
|
81
|
+
AirGapOnlineWallet.prototype.setProtocol = function (protocol) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
switch (_a.label) {
|
|
85
|
+
case 0: return [4 /*yield*/, _super.prototype.setProtocol.call(this, protocol)];
|
|
86
|
+
case 1:
|
|
87
|
+
_a.sent();
|
|
88
|
+
this.reset();
|
|
89
|
+
return [4 /*yield*/, this.synchronize()];
|
|
90
|
+
case 2:
|
|
91
|
+
_a.sent();
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
AirGapOnlineWallet.prototype.synchronize = function () {
|
|
98
|
+
var args = [];
|
|
99
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
100
|
+
args[_i] = arguments[_i];
|
|
101
|
+
}
|
|
102
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
+
var _this = this;
|
|
104
|
+
return __generator(this, function (_a) {
|
|
105
|
+
if (this.synchronizePromise === undefined) {
|
|
106
|
+
this.synchronizePromise = this._synchronize.apply(this, args).finally(function () {
|
|
107
|
+
_this.synchronizePromise = undefined;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return [2 /*return*/, this.synchronizePromise];
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
AirGapOnlineWallet.prototype.fetchTransactions = function (limit, cursor) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
var protocolIdentifier, transactions, _a;
|
|
117
|
+
return __generator(this, function (_b) {
|
|
118
|
+
switch (_b.label) {
|
|
119
|
+
case 0: return [4 /*yield*/, this.protocol.getMetadata()];
|
|
120
|
+
case 1:
|
|
121
|
+
protocolIdentifier = (_b.sent()).identifier;
|
|
122
|
+
if (!((protocolIdentifier === coinlib_core_1.MainProtocolSymbols.BTC ||
|
|
123
|
+
protocolIdentifier === coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT ||
|
|
124
|
+
protocolIdentifier === coinlib_core_1.MainProtocolSymbols.GRS) &&
|
|
125
|
+
this.publicKey.type === 'xpub' &&
|
|
126
|
+
(0, module_kit_1.isBip32Protocol)(this.protocol))) return [3 /*break*/, 3];
|
|
127
|
+
return [4 /*yield*/, this.protocol.getTransactionsForPublicKey(this.publicKey, limit, cursor)];
|
|
128
|
+
case 2:
|
|
129
|
+
// TODO: Remove and test
|
|
130
|
+
/*
|
|
131
|
+
We should remove this if BTC also uses blockbook. (And change the order of the if/else below)
|
|
132
|
+
|
|
133
|
+
The problem is that we have addresses cached for all protocols. But blockbook (grs) doesn't allow
|
|
134
|
+
multiple addresses to be checked at once, so we need to xPub key there (or we would do 100s of requests).
|
|
135
|
+
|
|
136
|
+
We can also not simply change the order of the following if/else, because then it would use the xPub method for
|
|
137
|
+
BTC as well, which results in the addresses being derived again, which causes massive lags in the apps.
|
|
138
|
+
*/
|
|
139
|
+
transactions = _b.sent();
|
|
140
|
+
return [3 /*break*/, 12];
|
|
141
|
+
case 3:
|
|
142
|
+
if (!((this.addresses.length > 0 && (0, protocol_1.canFetchDataForAddress)(this.protocol)) || (0, protocol_1.canFetchDataForMultipleAddresses)(this.protocol))) return [3 /*break*/, 8];
|
|
143
|
+
if (!(0, protocol_1.canFetchDataForMultipleAddresses)(this.protocol)) return [3 /*break*/, 5];
|
|
144
|
+
return [4 /*yield*/, this.protocol.getTransactionsForAddresses(this.addressesToCheck(), limit, cursor)];
|
|
145
|
+
case 4:
|
|
146
|
+
_a = _b.sent();
|
|
147
|
+
return [3 /*break*/, 7];
|
|
148
|
+
case 5: return [4 /*yield*/, this.protocol.getTransactionsForAddress(this.addressesToCheck()[0], limit, cursor)];
|
|
149
|
+
case 6:
|
|
150
|
+
_a = _b.sent();
|
|
151
|
+
_b.label = 7;
|
|
152
|
+
case 7:
|
|
153
|
+
transactions = _a;
|
|
154
|
+
return [3 /*break*/, 12];
|
|
155
|
+
case 8:
|
|
156
|
+
if (!(this.publicKey.type === 'xpub')) return [3 /*break*/, 10];
|
|
157
|
+
if (!(0, module_kit_1.isBip32Protocol)(this.protocol)) {
|
|
158
|
+
// This *should* never happen because of how the constructor is typed, but the compiler doesn't know it.
|
|
159
|
+
// TODO: check if there's a way to tell the compiler here that `publicKey: ExtendedPublicKey => protocol: AirGapOnlineExtendedProtocol`
|
|
160
|
+
throw this.xpubRequiresExtendedProtocolError();
|
|
161
|
+
}
|
|
162
|
+
return [4 /*yield*/, this.protocol.getTransactionsForPublicKey(this.publicKey, limit, cursor)];
|
|
163
|
+
case 9:
|
|
164
|
+
transactions = _b.sent();
|
|
165
|
+
return [3 /*break*/, 12];
|
|
166
|
+
case 10: return [4 /*yield*/, this.protocol.getTransactionsForPublicKey(this.publicKey, limit, cursor)];
|
|
167
|
+
case 11:
|
|
168
|
+
transactions = _b.sent();
|
|
169
|
+
_b.label = 12;
|
|
170
|
+
case 12: return [2 /*return*/, transactions];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
AirGapOnlineWallet.prototype.prepareTransaction = function (details, fee, data) {
|
|
176
|
+
if (data === void 0) { data = {}; }
|
|
177
|
+
if (this.publicKey.type === 'xpub') {
|
|
178
|
+
if (!(0, module_kit_1.isBip32Protocol)(this.protocol)) {
|
|
179
|
+
// This *should* never happen because of how the constructor is typed, but the compiler doesn't know it.
|
|
180
|
+
// TODO: check if there's a way to tell the compiler here that `publicKey: ExtendedPublicKey => protocol: AirGapOnlineExtendedProtocol`
|
|
181
|
+
throw this.xpubRequiresExtendedProtocolError();
|
|
182
|
+
}
|
|
183
|
+
return this.protocol.prepareTransactionWithPublicKey(this.publicKey, details, { fee: fee });
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
if (this.addressIndex) {
|
|
187
|
+
// TODO: what should we do with addressIndex?
|
|
188
|
+
data = Object.assign(data, { addressIndex: this.addressIndex });
|
|
189
|
+
}
|
|
190
|
+
return this.protocol.prepareTransactionWithPublicKey(this.publicKey, details, { fee: fee });
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
AirGapOnlineWallet.prototype.getMaxTransferValue = function (recipients, fee, data) {
|
|
194
|
+
if (data === void 0) { data = {}; }
|
|
195
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
196
|
+
return __generator(this, function (_a) {
|
|
197
|
+
if (this.publicKey.type === 'xpub') {
|
|
198
|
+
if (!(0, module_kit_1.isBip32Protocol)(this.protocol)) {
|
|
199
|
+
// This *should* never happen because of how the constructor is typed, but the compiler doesn't know it.
|
|
200
|
+
// TODO: check if there's a way to tell the compiler here that `publicKey: ExtendedPublicKey => protocol: AirGapOnlineExtendedProtocol`
|
|
201
|
+
throw this.xpubRequiresExtendedProtocolError();
|
|
202
|
+
}
|
|
203
|
+
return [2 /*return*/, this.protocol.getTransactionMaxAmountWithPublicKey(this.publicKey, recipients, { fee: fee })];
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
if (this.addressIndex) {
|
|
207
|
+
// TODO: what should we do with addressIndex?
|
|
208
|
+
data = Object.assign(data, { addressIndex: this.addressIndex });
|
|
209
|
+
}
|
|
210
|
+
return [2 /*return*/, this.protocol.getTransactionMaxAmountWithPublicKey(this.publicKey, recipients, { fee: fee })];
|
|
211
|
+
}
|
|
212
|
+
return [2 /*return*/];
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
AirGapOnlineWallet.prototype.estimateFees = function (details, data) {
|
|
217
|
+
if (data === void 0) { data = {}; }
|
|
218
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
if (this.publicKey.type === 'xpub') {
|
|
221
|
+
if (!(0, module_kit_1.isBip32Protocol)(this.protocol)) {
|
|
222
|
+
// This *should* never happen because of how the constructor is typed, but the compiler doesn't know it.
|
|
223
|
+
// TODO: check if there's a way to tell the compiler here that `publicKey: ExtendedPublicKey => protocol: AirGapOnlineExtendedProtocol`
|
|
224
|
+
throw this.xpubRequiresExtendedProtocolError();
|
|
225
|
+
}
|
|
226
|
+
return [2 /*return*/, this.protocol.getTransactionFeeWithPublicKey(this.publicKey, details)];
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
if (this.addressIndex) {
|
|
230
|
+
// TODO: what should we do with addressIndex?
|
|
231
|
+
data = Object.assign(data, { addressIndex: this.addressIndex });
|
|
232
|
+
}
|
|
233
|
+
return [2 /*return*/, this.protocol.getTransactionFeeWithPublicKey(this.publicKey, details)];
|
|
234
|
+
}
|
|
235
|
+
return [2 /*return*/];
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
AirGapOnlineWallet.prototype.toJSON = function () {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
241
|
+
var _a, base, networkIdentifier;
|
|
242
|
+
return __generator(this, function (_b) {
|
|
243
|
+
switch (_b.label) {
|
|
244
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
245
|
+
_super.prototype.toJSON.call(this),
|
|
246
|
+
this.protocol.getNetwork().then(function (network) { return (0, module_kit_1.protocolNetworkIdentifier)(network); })
|
|
247
|
+
])];
|
|
248
|
+
case 1:
|
|
249
|
+
_a = _b.sent(), base = _a[0], networkIdentifier = _a[1];
|
|
250
|
+
return [2 /*return*/, __assign(__assign({}, base), { networkIdentifier: networkIdentifier })];
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
return AirGapOnlineWallet;
|
|
256
|
+
}(AirGapWallet_1.AirGapWallet));
|
|
257
|
+
exports.AirGapOnlineWallet = AirGapOnlineWallet;
|
|
258
|
+
//# sourceMappingURL=AirGapOnlineWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AirGapOnlineWallet.js","sourceRoot":"","sources":["../../../src/wallet/online/AirGapOnlineW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