@weblock-wallet/sdk 0.1.71 → 0.1.73
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/index.cjs +46 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +46 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -29,7 +29,9 @@ declare enum SDKErrorCode {
|
|
|
29
29
|
NOT_LOGGED_IN = "NOT_LOGGED_IN",
|
|
30
30
|
NETWORK_SWITCH_FAILED = "NETWORK_SWITCH_FAILED",
|
|
31
31
|
TRANSACTION_FAILED = "TRANSACTION_FAILED",
|
|
32
|
-
INVALID_PIN = "INVALID_PIN"
|
|
32
|
+
INVALID_PIN = "INVALID_PIN",
|
|
33
|
+
RECOVERY_FAILED = "RECOVERY_FAILED",
|
|
34
|
+
UNKNOWN = "UNKNOWN"
|
|
33
35
|
}
|
|
34
36
|
declare class SDKError extends Error {
|
|
35
37
|
readonly code: SDKErrorCode;
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,9 @@ declare enum SDKErrorCode {
|
|
|
29
29
|
NOT_LOGGED_IN = "NOT_LOGGED_IN",
|
|
30
30
|
NETWORK_SWITCH_FAILED = "NETWORK_SWITCH_FAILED",
|
|
31
31
|
TRANSACTION_FAILED = "TRANSACTION_FAILED",
|
|
32
|
-
INVALID_PIN = "INVALID_PIN"
|
|
32
|
+
INVALID_PIN = "INVALID_PIN",
|
|
33
|
+
RECOVERY_FAILED = "RECOVERY_FAILED",
|
|
34
|
+
UNKNOWN = "UNKNOWN"
|
|
33
35
|
}
|
|
34
36
|
declare class SDKError extends Error {
|
|
35
37
|
readonly code: SDKErrorCode;
|
package/dist/index.js
CHANGED
|
@@ -103944,28 +103944,47 @@ var Crypto = {
|
|
|
103944
103944
|
encryptShare(share, password, salt) {
|
|
103945
103945
|
try {
|
|
103946
103946
|
const key = pbkdf2Sync(password, salt, 1e5, 32, "sha512");
|
|
103947
|
-
const iv = randomBytes(
|
|
103948
|
-
const cipher = createCipheriv("aes-256-
|
|
103947
|
+
const iv = randomBytes(12);
|
|
103948
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
103949
103949
|
let encrypted = cipher.update(share, "utf8", "hex");
|
|
103950
103950
|
encrypted += cipher.final("hex");
|
|
103951
|
-
|
|
103951
|
+
const tag = cipher.getAuthTag();
|
|
103952
|
+
return `gcm:${iv.toString("hex")}:${tag.toString("hex")}:${encrypted}`;
|
|
103952
103953
|
} catch (e7) {
|
|
103953
103954
|
console.error("Error during encrypting share:", e7);
|
|
103954
103955
|
throw e7;
|
|
103955
103956
|
}
|
|
103956
103957
|
},
|
|
103957
103958
|
decryptShare(encryptedShare, password, salt) {
|
|
103959
|
+
const key = pbkdf2Sync(password, salt, 1e5, 32, "sha512");
|
|
103958
103960
|
try {
|
|
103959
|
-
|
|
103961
|
+
if (encryptedShare.startsWith("gcm:")) {
|
|
103962
|
+
const parts2 = encryptedShare.split(":");
|
|
103963
|
+
if (parts2.length !== 4) throw new Error("Invalid ciphertext format");
|
|
103964
|
+
const [, ivHex2, tagHex, cipherHex] = parts2;
|
|
103965
|
+
const iv2 = Buffer.from(ivHex2, "hex");
|
|
103966
|
+
const tag = Buffer.from(tagHex, "hex");
|
|
103967
|
+
const decipher2 = createDecipheriv("aes-256-gcm", key, iv2);
|
|
103968
|
+
decipher2.setAuthTag(tag);
|
|
103969
|
+
let decrypted2 = decipher2.update(cipherHex, "hex", "utf8");
|
|
103970
|
+
decrypted2 += decipher2.final("utf8");
|
|
103971
|
+
return decrypted2;
|
|
103972
|
+
}
|
|
103973
|
+
const parts = encryptedShare.split(":");
|
|
103974
|
+
if (parts.length !== 2) throw new Error("Invalid ciphertext format");
|
|
103975
|
+
const [ivHex, encrypted] = parts;
|
|
103960
103976
|
const iv = Buffer.from(ivHex, "hex");
|
|
103961
|
-
const key = pbkdf2Sync(password, salt, 1e5, 32, "sha512");
|
|
103962
103977
|
const decipher = createDecipheriv("aes-256-cbc", key, iv);
|
|
103963
103978
|
let decrypted = decipher.update(encrypted, "hex", "utf8");
|
|
103964
103979
|
decrypted += decipher.final("utf8");
|
|
103980
|
+
if (!/^[0-9a-fA-F]+$/.test(decrypted) || decrypted.length % 2 !== 0) {
|
|
103981
|
+
throw new Error("Wrong password");
|
|
103982
|
+
}
|
|
103965
103983
|
return decrypted;
|
|
103966
103984
|
} catch (e7) {
|
|
103967
103985
|
console.error("Error during decrypting share:", e7);
|
|
103968
|
-
|
|
103986
|
+
const msg = String(e7?.message || "").toLowerCase();
|
|
103987
|
+
if (msg.includes("unable to decrypt data") || msg.includes("wrong password") || msg.includes("bad decrypt") || msg.includes("auth") || msg.includes("unsupported state") || msg.includes("invalid tag")) {
|
|
103969
103988
|
throw new Error("Wrong password");
|
|
103970
103989
|
}
|
|
103971
103990
|
throw e7;
|
|
@@ -104065,6 +104084,8 @@ var SDKErrorCode = /* @__PURE__ */ ((SDKErrorCode2) => {
|
|
|
104065
104084
|
SDKErrorCode2["NETWORK_SWITCH_FAILED"] = "NETWORK_SWITCH_FAILED";
|
|
104066
104085
|
SDKErrorCode2["TRANSACTION_FAILED"] = "TRANSACTION_FAILED";
|
|
104067
104086
|
SDKErrorCode2["INVALID_PIN"] = "INVALID_PIN";
|
|
104087
|
+
SDKErrorCode2["RECOVERY_FAILED"] = "RECOVERY_FAILED";
|
|
104088
|
+
SDKErrorCode2["UNKNOWN"] = "UNKNOWN";
|
|
104068
104089
|
return SDKErrorCode2;
|
|
104069
104090
|
})(SDKErrorCode || {});
|
|
104070
104091
|
var SDKError = class extends Error {
|
|
@@ -104328,10 +104349,25 @@ var WalletService = class {
|
|
|
104328
104349
|
"INVALID_PARAMS" /* INVALID_PARAMS */
|
|
104329
104350
|
);
|
|
104330
104351
|
}
|
|
104352
|
+
const walletInfo = await this.walletClient.getWallet();
|
|
104353
|
+
const serverAddr = this.normalizeAddr(walletInfo?.address);
|
|
104354
|
+
const expectedShareLen = String(walletInfo?.share1 ?? "").length;
|
|
104331
104355
|
const decryptShareOrThrow = (encryptedShare) => {
|
|
104332
104356
|
try {
|
|
104333
|
-
|
|
104357
|
+
const share = Crypto.decryptShare(
|
|
104358
|
+
encryptedShare,
|
|
104359
|
+
password,
|
|
104360
|
+
firebaseId
|
|
104361
|
+
);
|
|
104362
|
+
if (expectedShareLen > 0 && share.length !== expectedShareLen) {
|
|
104363
|
+
throw new SDKError(
|
|
104364
|
+
"Incorrect PIN code",
|
|
104365
|
+
"INVALID_PASSWORD" /* INVALID_PASSWORD */
|
|
104366
|
+
);
|
|
104367
|
+
}
|
|
104368
|
+
return share;
|
|
104334
104369
|
} catch (e7) {
|
|
104370
|
+
if (e7 instanceof SDKError) throw e7;
|
|
104335
104371
|
if (this.isInvalidPasswordError(e7)) {
|
|
104336
104372
|
throw new SDKError(
|
|
104337
104373
|
"Incorrect PIN code",
|
|
@@ -104342,8 +104378,6 @@ var WalletService = class {
|
|
|
104342
104378
|
throw e7;
|
|
104343
104379
|
}
|
|
104344
104380
|
};
|
|
104345
|
-
const walletInfo = await this.walletClient.getWallet();
|
|
104346
|
-
const serverAddr = this.normalizeAddr(walletInfo?.address);
|
|
104347
104381
|
let share2 = await LocalForage.get(
|
|
104348
104382
|
STORAGE_KEYS.share2(this.orgHost)
|
|
104349
104383
|
);
|
|
@@ -104366,8 +104400,8 @@ var WalletService = class {
|
|
|
104366
104400
|
const derivedAddr2 = this.normalizeAddr(wallet2.address);
|
|
104367
104401
|
if (this.addressesMismatch(serverAddr, derivedAddr2)) {
|
|
104368
104402
|
throw new SDKError(
|
|
104369
|
-
|
|
104370
|
-
"
|
|
104403
|
+
"Incorrect PIN code",
|
|
104404
|
+
"INVALID_PASSWORD" /* INVALID_PASSWORD */
|
|
104371
104405
|
);
|
|
104372
104406
|
}
|
|
104373
104407
|
const newShares = await Secrets.split(wallet2.privateKey, 3, 2);
|
|
@@ -104402,10 +104436,7 @@ var WalletService = class {
|
|
|
104402
104436
|
const wallet = new Wallet(privateKey);
|
|
104403
104437
|
const derivedAddr = this.normalizeAddr(wallet.address);
|
|
104404
104438
|
if (this.addressesMismatch(serverAddr, derivedAddr)) {
|
|
104405
|
-
throw new SDKError(
|
|
104406
|
-
`Recovered wallet address mismatch. server=${serverAddr} derived=${derivedAddr}`,
|
|
104407
|
-
"WALLET_RECOVERY_FAILED" /* WALLET_RECOVERY_FAILED */
|
|
104408
|
-
);
|
|
104439
|
+
throw new SDKError("Incorrect PIN code", "INVALID_PASSWORD" /* INVALID_PASSWORD */);
|
|
104409
104440
|
}
|
|
104410
104441
|
await this.ensureDeviceEncryptedShare2(share2, firebaseId);
|
|
104411
104442
|
this.walletAddress = wallet.address;
|