@airgap/wallet 0.13.45-beta.2 → 0.13.45-beta.3
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.js +5 -5
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/utils/address.js +2 -3
- package/utils/address.js.map +1 -1
- package/utils/protocol.js +8 -60
- package/utils/protocol.js.map +1 -1
- package/wallet/AirGapWallet.js +60 -133
- package/wallet/AirGapWallet.js.map +1 -1
- package/wallet/offline/AirGapOfflineWallet.js +5 -25
- package/wallet/offline/AirGapOfflineWallet.js.map +1 -1
- package/wallet/online/AirGapCoinWallet.js +72 -186
- package/wallet/online/AirGapCoinWallet.js.map +1 -1
- package/wallet/online/AirGapNFTWallet.js +56 -168
- package/wallet/online/AirGapNFTWallet.js.map +1 -1
- package/wallet/online/AirGapOnlineWallet.js +110 -237
- package/wallet/online/AirGapOnlineWallet.js.map +1 -1
package/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TimeInterval = exports.AirGapNFTWallet = exports.AirGapWalletStatus = exports.AirGapCoinWallet = exports.AirGapOnlineWallet = exports.AirGapOfflineWallet = exports.AirGapWallet = void 0;
|
|
4
|
-
|
|
4
|
+
const AirGapWallet_1 = require("./wallet/AirGapWallet");
|
|
5
5
|
Object.defineProperty(exports, "AirGapWallet", { enumerable: true, get: function () { return AirGapWallet_1.AirGapWallet; } });
|
|
6
6
|
Object.defineProperty(exports, "AirGapWalletStatus", { enumerable: true, get: function () { return AirGapWallet_1.AirGapWalletStatus; } });
|
|
7
|
-
|
|
7
|
+
const AirGapOfflineWallet_1 = require("./wallet/offline/AirGapOfflineWallet");
|
|
8
8
|
Object.defineProperty(exports, "AirGapOfflineWallet", { enumerable: true, get: function () { return AirGapOfflineWallet_1.AirGapOfflineWallet; } });
|
|
9
|
-
|
|
9
|
+
const AirGapCoinWallet_1 = require("./wallet/online/AirGapCoinWallet");
|
|
10
10
|
Object.defineProperty(exports, "AirGapCoinWallet", { enumerable: true, get: function () { return AirGapCoinWallet_1.AirGapCoinWallet; } });
|
|
11
11
|
Object.defineProperty(exports, "TimeInterval", { enumerable: true, get: function () { return AirGapCoinWallet_1.TimeInterval; } });
|
|
12
|
-
|
|
12
|
+
const AirGapNFTWallet_1 = require("./wallet/online/AirGapNFTWallet");
|
|
13
13
|
Object.defineProperty(exports, "AirGapNFTWallet", { enumerable: true, get: function () { return AirGapNFTWallet_1.AirGapNFTWallet; } });
|
|
14
|
-
|
|
14
|
+
const AirGapOnlineWallet_1 = require("./wallet/online/AirGapOnlineWallet");
|
|
15
15
|
Object.defineProperty(exports, "AirGapOnlineWallet", { enumerable: true, get: function () { return AirGapOnlineWallet_1.AirGapOnlineWallet; } });
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wDAAgG;AAMvF,6FANA,2BAAY,OAMA;AAA6D,mGAN3D,iCAAkB,OAM2D;AALpG,8EAA0E;AAKnD,oGALd,yCAAmB,OAKc;AAJ1C,uEAAiF;AAIjB,iGAJvD,mCAAgB,OAIuD;AAMvE,6FAVkB,+BAAY,OAUlB;AATrB,qEAAiE;AAGqC,gGAH7F,iCAAe,OAG6F;AAFrH,2EAAiG;AAErD,mGAFnC,uCAAkB,OAEmC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airgap/wallet",
|
|
3
|
-
"version": "0.13.45-beta.
|
|
3
|
+
"version": "0.13.45-beta.3",
|
|
4
4
|
"description": "The @airgap/wallet package provides interfaces for offline/online wallet functionalities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"airgap"
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"author": "Papers AG <contact@papers.ch> (https://papers.ch)",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@airgap/coinlib-core": "^0.13.45-beta.
|
|
31
|
-
"@airgap/module-kit": "^0.13.45-beta.
|
|
30
|
+
"@airgap/coinlib-core": "^0.13.45-beta.3",
|
|
31
|
+
"@airgap/module-kit": "^0.13.45-beta.3"
|
|
32
32
|
},
|
|
33
33
|
"nyc": {
|
|
34
34
|
"include": [
|
package/utils/address.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeAddress =
|
|
3
|
+
exports.normalizeAddress = normalizeAddress;
|
|
4
4
|
function normalizeAddress(address) {
|
|
5
5
|
return typeof address === 'string'
|
|
6
6
|
? {
|
|
7
|
-
address
|
|
7
|
+
address,
|
|
8
8
|
cursor: { hasNext: false }
|
|
9
9
|
}
|
|
10
10
|
: address;
|
|
11
11
|
}
|
|
12
|
-
exports.normalizeAddress = normalizeAddress;
|
|
13
12
|
//# sourceMappingURL=address.js.map
|
package/utils/address.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/utils/address.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/utils/address.ts"],"names":[],"mappings":";;AAEA,4CAOC;AAPD,SAAgB,gBAAgB,CAAC,OAAmC;IAClE,OAAO,OAAO,OAAO,KAAK,QAAQ;QAChC,CAAC,CAAC;YACE,OAAO;YACP,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;SAC3B;QACH,CAAC,CAAC,OAAO,CAAA;AACb,CAAC"}
|
package/utils/protocol.js
CHANGED
|
@@ -1,64 +1,12 @@
|
|
|
1
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
2
|
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
3
|
exports.deriveAddresses = deriveAddresses;
|
|
4
|
+
const address_1 = require("./address");
|
|
5
|
+
async function deriveAddresses(protocol, publicKey, visibilityIndex, amount, offset) {
|
|
6
|
+
const generatorArray = Array.from(new Array(amount), (_, i) => i + offset);
|
|
7
|
+
return Promise.all(generatorArray.map(async (x) => {
|
|
8
|
+
const derivedKey = await protocol.deriveFromExtendedPublicKey(publicKey, visibilityIndex, x);
|
|
9
|
+
return (0, address_1.normalizeAddress)(await protocol.getAddressFromPublicKey(derivedKey));
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
64
12
|
//# sourceMappingURL=protocol.js.map
|
package/utils/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/utils/protocol.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/utils/protocol.ts"],"names":[],"mappings":";;AAIA,0CAgBC;AAlBD,uCAA4C;AAErC,KAAK,UAAU,eAAe,CACnC,QAAoD,EACpD,SAA4B,EAC5B,eAAuB,EACvB,MAAc,EACd,MAAc;IAEd,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,CAAA;IAE1E,OAAO,OAAO,CAAC,GAAG,CAChB,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QAC7B,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,2BAA2B,CAAC,SAAS,EAAE,eAAe,EAAE,CAAC,CAAC,CAAA;QAE5F,OAAO,IAAA,0BAAgB,EAAC,MAAM,QAAQ,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC,CAAA;IAC7E,CAAC,CAAC,CACH,CAAA;AACH,CAAC"}
|
package/wallet/AirGapWallet.js
CHANGED
|
@@ -1,56 +1,20 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.AirGapWallet = exports.AirGapWalletStatus = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
4
|
+
const errors_1 = require("@airgap/coinlib-core/errors");
|
|
5
|
+
const coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
|
|
6
|
+
const module_kit_1 = require("@airgap/module-kit");
|
|
7
|
+
const address_1 = require("../utils/address");
|
|
8
|
+
const protocol_1 = require("../utils/protocol");
|
|
45
9
|
var AirGapWalletStatus;
|
|
46
10
|
(function (AirGapWalletStatus) {
|
|
47
11
|
AirGapWalletStatus["ACTIVE"] = "active";
|
|
48
12
|
AirGapWalletStatus["HIDDEN"] = "hidden";
|
|
49
13
|
AirGapWalletStatus["DELETED"] = "deleted";
|
|
50
14
|
AirGapWalletStatus["TRANSIENT"] = "transient";
|
|
51
|
-
})(AirGapWalletStatus
|
|
52
|
-
|
|
53
|
-
|
|
15
|
+
})(AirGapWalletStatus || (exports.AirGapWalletStatus = AirGapWalletStatus = {}));
|
|
16
|
+
class AirGapWallet {
|
|
17
|
+
constructor(protocol, publicKey, derivationPath, masterFingerprint, status, addressIndex) {
|
|
54
18
|
this.protocol = protocol;
|
|
55
19
|
this.publicKey = publicKey;
|
|
56
20
|
this.derivationPath = derivationPath;
|
|
@@ -59,95 +23,58 @@ var AirGapWallet = /** @class */ (function () {
|
|
|
59
23
|
this.addressIndex = addressIndex;
|
|
60
24
|
this.addresses = []; // used for cache
|
|
61
25
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
case 1:
|
|
113
|
-
addresses = (_b.sent()).reduce(function (flatten, next) { return flatten.concat(next); }, []);
|
|
114
|
-
return [3 /*break*/, 4];
|
|
115
|
-
case 2:
|
|
116
|
-
_a = address_1.normalizeAddress;
|
|
117
|
-
return [4 /*yield*/, this.protocol.getAddressFromPublicKey(this.publicKey)];
|
|
118
|
-
case 3:
|
|
119
|
-
addresses = [_a.apply(void 0, [_b.sent()])];
|
|
120
|
-
_b.label = 4;
|
|
121
|
-
case 4: return [2 /*return*/, addresses.map(function (address) { return address.address; })];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
AirGapWallet.prototype.toJSON = function () {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
var protocolIdentifier;
|
|
129
|
-
return __generator(this, function (_a) {
|
|
130
|
-
switch (_a.label) {
|
|
131
|
-
case 0: return [4 /*yield*/, this.protocol.getMetadata()];
|
|
132
|
-
case 1:
|
|
133
|
-
protocolIdentifier = (_a.sent()).identifier;
|
|
134
|
-
return [2 /*return*/, {
|
|
135
|
-
protocolIdentifier: protocolIdentifier,
|
|
136
|
-
publicKey: this.publicKey,
|
|
137
|
-
derivationPath: this.derivationPath,
|
|
138
|
-
addresses: this.addresses,
|
|
139
|
-
masterFingerprint: this.masterFingerprint,
|
|
140
|
-
status: this.status,
|
|
141
|
-
addressIndex: this.addressIndex
|
|
142
|
-
}];
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
AirGapWallet.prototype.xpubRequiresExtendedProtocolError = function () {
|
|
26
|
+
get receivingPublicAddress() {
|
|
27
|
+
return this.addresses[this.addressIndex !== undefined ? this.addressIndex : 0];
|
|
28
|
+
}
|
|
29
|
+
async setProtocol(protocol) {
|
|
30
|
+
const [currentProtocolIdentifier, nextProtocolIdentifier] = await Promise.all([
|
|
31
|
+
this.protocol.getMetadata().then((metadata) => metadata.identifier),
|
|
32
|
+
protocol.getMetadata().then((metadata) => metadata.identifier)
|
|
33
|
+
]);
|
|
34
|
+
if (nextProtocolIdentifier !== currentProtocolIdentifier) {
|
|
35
|
+
throw new errors_1.ConditionViolationError(coinlib_error_1.Domain.WALLET, 'Can only set same protocol with a different network');
|
|
36
|
+
}
|
|
37
|
+
this.protocol = protocol;
|
|
38
|
+
}
|
|
39
|
+
async deriveAddresses(amount = 50) {
|
|
40
|
+
let addresses;
|
|
41
|
+
if (this.publicKey.type === 'xpub') {
|
|
42
|
+
if (!(0, module_kit_1.isBip32Protocol)(this.protocol)) {
|
|
43
|
+
// This *should* never happen because of how the constructor is typed, but the compiler doesn't know it.
|
|
44
|
+
// TODO: check if there's a way to tell the compiler here that `publicKey: ExtendedPublicKey => protocol: AirGapAnyExtendedProtocol`
|
|
45
|
+
throw this.xpubRequiresExtendedProtocolError();
|
|
46
|
+
}
|
|
47
|
+
const parts = this.derivationPath.split('/');
|
|
48
|
+
let offset = 0;
|
|
49
|
+
if (!parts[parts.length - 1].endsWith("'")) {
|
|
50
|
+
offset = Number.parseInt(parts[parts.length - 1], 10);
|
|
51
|
+
}
|
|
52
|
+
addresses = (await Promise.all([
|
|
53
|
+
// TODO: this is not a desired behavior for ETH, maybe add UTXO protocol extension that BTC can implement and use it here?
|
|
54
|
+
(0, protocol_1.deriveAddresses)(this.protocol, this.publicKey, 0, amount, offset),
|
|
55
|
+
(0, protocol_1.deriveAddresses)(this.protocol, this.publicKey, 1, amount, offset)
|
|
56
|
+
])).reduce((flatten, next) => flatten.concat(next), []);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
addresses = [(0, address_1.normalizeAddress)(await this.protocol.getAddressFromPublicKey(this.publicKey))];
|
|
60
|
+
}
|
|
61
|
+
return addresses.map((address) => address.address);
|
|
62
|
+
}
|
|
63
|
+
async toJSON() {
|
|
64
|
+
const protocolIdentifier = (await this.protocol.getMetadata()).identifier;
|
|
65
|
+
return {
|
|
66
|
+
protocolIdentifier,
|
|
67
|
+
publicKey: this.publicKey,
|
|
68
|
+
derivationPath: this.derivationPath,
|
|
69
|
+
addresses: this.addresses,
|
|
70
|
+
masterFingerprint: this.masterFingerprint,
|
|
71
|
+
status: this.status,
|
|
72
|
+
addressIndex: this.addressIndex
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
xpubRequiresExtendedProtocolError() {
|
|
148
76
|
return new errors_1.ConditionViolationError(coinlib_error_1.Domain.WALLET, 'Extended public keys are supported only when paired with an extended protocol');
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
}());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
152
79
|
exports.AirGapWallet = AirGapWallet;
|
|
153
80
|
//# sourceMappingURL=AirGapWallet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AirGapWallet.js","sourceRoot":"","sources":["../../src/wallet/AirGapWallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AirGapWallet.js","sourceRoot":"","sources":["../../src/wallet/AirGapWallet.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,31 +1,11 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.AirGapOfflineWallet = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
4
|
+
const AirGapWallet_1 = require("../AirGapWallet");
|
|
5
|
+
class AirGapOfflineWallet extends AirGapWallet_1.AirGapWallet {
|
|
6
|
+
toJSON() {
|
|
7
|
+
return super.toJSON();
|
|
24
8
|
}
|
|
25
|
-
|
|
26
|
-
return _super.prototype.toJSON.call(this);
|
|
27
|
-
};
|
|
28
|
-
return AirGapOfflineWallet;
|
|
29
|
-
}(AirGapWallet_1.AirGapWallet));
|
|
9
|
+
}
|
|
30
10
|
exports.AirGapOfflineWallet = AirGapOfflineWallet;
|
|
31
11
|
//# sourceMappingURL=AirGapOfflineWallet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AirGapOfflineWallet.js","sourceRoot":"","sources":["../../../src/wallet/offline/AirGapOfflineWallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AirGapOfflineWallet.js","sourceRoot":"","sources":["../../../src/wallet/offline/AirGapOfflineWallet.ts"],"names":[],"mappings":";;;AAEA,kDAAsE;AAItE,MAAa,mBAEX,SAAQ,2BAAsC;IACvC,MAAM;QACX,OAAO,KAAK,CAAC,MAAM,EAAE,CAAA;IACvB,CAAC;CACF;AAND,kDAMC"}
|