@multiversx/sdk-wallet
Advanced tools
Comparing version 4.0.0-beta.1 to 4.0.0-beta.3
@@ -14,3 +14,3 @@ "use strict"; | ||
static encrypt(data, recipientPubKey, authSecretKey) { | ||
// create a new x225519 keypair that will be used for EDH | ||
// create a new x25519 keypair that will be used for EDH | ||
const edhPair = tweetnacl_1.default.sign.keyPair(); | ||
@@ -17,0 +17,0 @@ const recipientDHPubKey = ed2curve_1.default.convertPublicKey(recipientPubKey.valueOf()); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Randomness = void 0; | ||
const tweetnacl_1 = __importDefault(require("tweetnacl")); | ||
const ed25519_1 = require("@noble/ed25519"); | ||
const uuid_1 = require("uuid"); | ||
@@ -12,4 +9,4 @@ const crypto = require("crypto"); | ||
constructor(init) { | ||
this.salt = (init === null || init === void 0 ? void 0 : init.salt) || Buffer.from(tweetnacl_1.default.randomBytes(32)); | ||
this.iv = (init === null || init === void 0 ? void 0 : init.iv) || Buffer.from(tweetnacl_1.default.randomBytes(16)); | ||
this.salt = (init === null || init === void 0 ? void 0 : init.salt) || Buffer.from(ed25519_1.utils.randomBytes(32)); | ||
this.iv = (init === null || init === void 0 ? void 0 : init.iv) || Buffer.from(ed25519_1.utils.randomBytes(16)); | ||
this.id = (init === null || init === void 0 ? void 0 : init.id) || uuid_1.v4({ random: crypto.randomBytes(16) }); | ||
@@ -16,0 +13,0 @@ } |
@@ -17,3 +17,3 @@ /// <reference types="node" /> | ||
private readonly buffer; | ||
constructor(buffer: Buffer); | ||
constructor(buffer: Uint8Array); | ||
verify(data: Buffer, signature: Buffer): boolean; | ||
@@ -20,0 +20,0 @@ hex(): string; |
@@ -23,3 +23,4 @@ "use strict"; | ||
exports.UserPublicKey = exports.UserSecretKey = exports.USER_PUBKEY_LENGTH = exports.USER_SEED_LENGTH = void 0; | ||
const tweetnacl = __importStar(require("tweetnacl")); | ||
const ed = __importStar(require("@noble/ed25519")); | ||
const sha512_1 = require("@noble/hashes/sha512"); | ||
const assertions_1 = require("./assertions"); | ||
@@ -30,2 +31,5 @@ const pem_1 = require("./pem"); | ||
exports.USER_PUBKEY_LENGTH = 32; | ||
// See: https://github.com/paulmillr/noble-ed25519 | ||
// In a future version of sdk-wallet, we'll switch to using the async functions of noble-ed25519. | ||
ed.utils.sha512Sync = (...m) => sha512_1.sha512(ed.utils.concatBytes(...m)); | ||
class UserSecretKey { | ||
@@ -45,12 +49,7 @@ constructor(buffer) { | ||
generatePublicKey() { | ||
let keyPair = tweetnacl.sign.keyPair.fromSeed(new Uint8Array(this.buffer)); | ||
let buffer = Buffer.from(keyPair.publicKey); | ||
const buffer = ed.sync.getPublicKey(this.buffer); | ||
return new UserPublicKey(buffer); | ||
} | ||
sign(message) { | ||
let pair = tweetnacl.sign.keyPair.fromSeed(new Uint8Array(this.buffer)); | ||
let signingKey = pair.secretKey; | ||
let signature = tweetnacl.sign(new Uint8Array(message), signingKey); | ||
// "tweetnacl.sign()" returns the concatenated [signature, message], therfore we remove the appended message: | ||
signature = signature.slice(0, signature.length - message.length); | ||
const signature = ed.sync.sign(message, this.buffer); | ||
return Buffer.from(signature); | ||
@@ -69,9 +68,8 @@ } | ||
assertions_1.guardLength(buffer, exports.USER_PUBKEY_LENGTH); | ||
this.buffer = buffer; | ||
this.buffer = Buffer.from(buffer); | ||
} | ||
verify(data, signature) { | ||
try { | ||
const unopenedMessage = Buffer.concat([signature, data]); | ||
const unsignedMessage = tweetnacl.sign.open(unopenedMessage, this.buffer); | ||
return unsignedMessage != null; | ||
const ok = ed.sync.verify(signature, data, this.buffer); | ||
return ok; | ||
} | ||
@@ -78,0 +76,0 @@ catch (err) { |
/// <reference types="node" /> | ||
import { UserAddress } from "./userAddress"; | ||
import { UserSecretKey } from "./userKeys"; | ||
interface IUserSecretKey { | ||
sign(message: Buffer): Buffer; | ||
generatePublicKey(): IUserPublicKey; | ||
} | ||
interface IUserPublicKey { | ||
toAddress(): { | ||
bech32(): string; | ||
}; | ||
} | ||
/** | ||
@@ -8,4 +16,4 @@ * ed25519 signer | ||
export declare class UserSigner { | ||
protected readonly secretKey: UserSecretKey; | ||
constructor(secretKey: UserSecretKey); | ||
protected readonly secretKey: IUserSecretKey; | ||
constructor(secretKey: IUserSecretKey); | ||
static fromWallet(keyFileObject: any, password: string): UserSigner; | ||
@@ -19,1 +27,2 @@ static fromPem(text: string, index?: number): UserSigner; | ||
} | ||
export {}; |
@@ -14,2 +14,3 @@ "use strict"; | ||
const errors_1 = require("./errors"); | ||
const userAddress_1 = require("./userAddress"); | ||
const userKeys_1 = require("./userKeys"); | ||
@@ -47,3 +48,4 @@ const userWallet_1 = require("./userWallet"); | ||
getAddress() { | ||
return this.secretKey.generatePublicKey().toAddress(); | ||
const bech32 = this.secretKey.generatePublicKey().toAddress().bech32(); | ||
return userAddress_1.UserAddress.fromBech32(bech32); | ||
} | ||
@@ -50,0 +52,0 @@ } |
{ | ||
"name": "@multiversx/sdk-wallet", | ||
"version": "4.0.0-beta.1", | ||
"version": "4.0.0-beta.3", | ||
"description": "Wallet components for MultiversX", | ||
@@ -31,2 +31,4 @@ "main": "out/index.js", | ||
"tweetnacl": "1.0.3", | ||
"@noble/ed25519": "1.7.3", | ||
"@noble/hashes": "1.3.0", | ||
"uuid": "8.3.2" | ||
@@ -33,0 +35,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1376
81893
12
+ Added@noble/ed25519@1.7.3
+ Added@noble/hashes@1.3.0
+ Added@noble/ed25519@1.7.3(transitive)
+ Added@noble/hashes@1.3.0(transitive)