Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@multiversx/sdk-wallet

Package Overview
Dependencies
Maintainers
9
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@multiversx/sdk-wallet - npm Package Compare versions

Comparing version 3.0.0-alpha.1 to 3.0.0-alpha.2

1

out/crypto/constants.d.ts

@@ -1,2 +0,1 @@

export declare const Version = 4;
export declare const CipherAlgorithm = "aes-128-ctr";

@@ -3,0 +2,0 @@ export declare const DigestAlgorithm = "sha256";

4

out/crypto/constants.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PubKeyEncCipher = exports.PubKeyEncNonceLength = exports.PubKeyEncVersion = exports.KeyDerivationFunction = exports.DigestAlgorithm = exports.CipherAlgorithm = exports.Version = void 0;
// In a future PR, improve versioning infrastructure for key-file objects.
exports.Version = 4;
exports.PubKeyEncCipher = exports.PubKeyEncNonceLength = exports.PubKeyEncVersion = exports.KeyDerivationFunction = exports.DigestAlgorithm = exports.CipherAlgorithm = void 0;
exports.CipherAlgorithm = "aes-128-ctr";

@@ -7,0 +5,0 @@ exports.DigestAlgorithm = "sha256";

/// <reference types="node" />
import { EncryptedData } from "./encryptedData";
import { Randomness } from "./randomness";
import { EncryptedData } from "./encryptedData";
export declare enum EncryptorVersion {
V4 = 4
}
export declare class Encryptor {
static encrypt(data: Buffer, password: string, randomness?: Randomness): EncryptedData;
static encrypt(version: EncryptorVersion, data: Buffer, password: string, randomness?: Randomness): EncryptedData;
}

@@ -6,10 +6,14 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Encryptor = void 0;
exports.Encryptor = exports.EncryptorVersion = void 0;
const crypto_1 = __importDefault(require("crypto"));
const randomness_1 = require("./randomness");
const constants_1 = require("./constants");
const derivationParams_1 = require("./derivationParams");
const constants_1 = require("./constants");
const encryptedData_1 = require("./encryptedData");
const randomness_1 = require("./randomness");
var EncryptorVersion;
(function (EncryptorVersion) {
EncryptorVersion[EncryptorVersion["V4"] = 4] = "V4";
})(EncryptorVersion = exports.EncryptorVersion || (exports.EncryptorVersion = {}));
class Encryptor {
static encrypt(data, password, randomness = new randomness_1.Randomness()) {
static encrypt(version, data, password, randomness = new randomness_1.Randomness()) {
const kdParams = new derivationParams_1.ScryptKeyDerivationParams();

@@ -23,3 +27,3 @@ const derivedKey = kdParams.generateDerivedKey(Buffer.from(password), randomness.salt);

return new encryptedData_1.EncryptedData({
version: constants_1.Version,
version: version,
id: randomness.id,

@@ -26,0 +30,0 @@ ciphertext: ciphertext.toString('hex'),

@@ -7,4 +7,3 @@ export * from "./mnemonic";

export * from "./userSigner";
export * from "./guardianSigner";
export * from "./userVerifier";
export * from "./validatorSigner";

@@ -19,5 +19,4 @@ "use strict";

__exportStar(require("./userSigner"), exports);
__exportStar(require("./guardianSigner"), exports);
__exportStar(require("./userVerifier"), exports);
__exportStar(require("./validatorSigner"), exports);
//# sourceMappingURL=index.js.map

@@ -23,15 +23,2 @@ /// <reference types="node" />

}
/**
* An interface that defines a signing-capable object.
*/
export interface IGuardianSigner {
/**
* Gets the {@link Address} of the signer.
*/
getAddress(): IAddress;
/**
* Signs a message (e.g. a transaction).
*/
guard(signable: ISignable): Promise<void>;
}
export interface IVerifier {

@@ -47,19 +34,10 @@ verify(message: IVerifiable): boolean;

*/
serializeForSigning(): Buffer;
serializeForSigning(signedBy: IAddress): Buffer;
/**
* Returns the signature of the sender.
*/
getSignature(): ISignature;
/**
* Applies the computed signature on the object itself.
*
* @param signature The computed signature
*/
applySignature(signature: ISignature): void;
/**
* Applies the guardian signature on the transaction.
*
* @param guardianSignature The signature, as computed by a guardian.
*/
applyGuardianSignature(guardianSignature: ISignature): void;
* @param signedBy The address of the {@link ISignature}
*/
applySignature(signature: ISignature, signedBy: IAddress): void;
}

@@ -66,0 +44,0 @@ /**

@@ -7,3 +7,3 @@ import { IAddress, ISignable, ISigner } from "./interface";

export declare class UserSigner implements ISigner {
protected readonly secretKey: UserSecretKey;
private readonly secretKey;
constructor(secretKey: UserSecretKey);

@@ -10,0 +10,0 @@ static fromWallet(keyFileObject: any, password: string): ISigner;

@@ -47,6 +47,7 @@ "use strict";

trySign(signable) {
let bufferToSign = signable.serializeForSigning();
let signedBy = this.getAddress();
let bufferToSign = signable.serializeForSigning(signedBy);
let signatureBuffer = this.secretKey.sign(bufferToSign);
let signature = new signature_1.Signature(signatureBuffer);
signable.applySignature(signature);
signable.applySignature(signature, signedBy);
}

@@ -53,0 +54,0 @@ /**

@@ -1,19 +0,41 @@

import { EncryptedData, Randomness } from "./crypto";
/// <reference types="node" />
import { EncryptedData, EncryptorVersion, Randomness } from "./crypto";
import { UserSecretKey } from "./userKeys";
export declare enum EnvelopeVersion {
V4 = 4,
V5 = 5
}
export declare enum UserWalletKind {
SecretKey = "secretKey",
Mnemonic = "mnemonic",
Arbitrary = "arbitrary"
}
export declare class UserWallet {
private readonly publicKey;
private readonly envelopeVersion;
private readonly kind;
private readonly encryptedData;
private readonly publicKeyWhenKindIsSecretKey?;
private constructor();
static fromSecretKey({ envelopeVersion, encryptorVersion, secretKey, password, randomness, }: {
envelopeVersion?: EnvelopeVersion;
encryptorVersion?: EncryptorVersion;
secretKey: UserSecretKey;
password: string;
randomness?: Randomness;
}): UserWallet;
static fromMnemonic({ envelopeVersion, encryptorVersion, mnemonic, password, randomness, }: {
envelopeVersion?: EnvelopeVersion;
encryptorVersion?: EncryptorVersion;
mnemonic: string;
password: string;
randomness?: Randomness;
}): UserWallet;
static fromArbitrary({ envelopeVersion, encryptorVersion, arbitraryData, password, randomness, }: {
envelopeVersion?: EnvelopeVersion;
encryptorVersion?: EncryptorVersion;
arbitraryData: Buffer;
password: string;
randomness?: Randomness;
}): UserWallet;
/**
* Copied from: https://github.com/multiversx/mx-deprecated-core-js/blob/v1.28.0/src/account.js#L76
* Notes: adjustements (code refactoring, no change in logic), in terms of:
* - typing (since this is the TypeScript version)
* - error handling (in line with sdk-core's error system)
* - references to crypto functions
* - references to object members
*
* Given a password, generates the contents for a file containing the account's secret key,
* passed through a password-based key derivation function (kdf).
*/
constructor(secretKey: UserSecretKey, password: string, randomness?: Randomness);
/**
* Copied from: https://github.com/multiversx/mx-deprecated-core-js/blob/v1.28.0/src/account.js#L42

@@ -29,2 +51,4 @@ * Notes: adjustements (code refactoring, no change in logic), in terms of:

static decryptSecretKey(keyFileObject: any, password: string): UserSecretKey;
static decryptMnemonic(keyFileObject: any, password: string): string;
static decryptArbitrary(keyFileObject: any, password: string): Buffer;
static edFromJSON(keyfileObject: any): EncryptedData;

@@ -35,2 +59,7 @@ /**

toJSON(): any;
getEnvelopeWhenKindIsSecretKey(): any;
getCryptoSectionAsJSON(): any;
getEnvelopeWhenKindIsMnemonicOrArbitrary(): any;
private static requireKind;
private static requireV5OrHigher;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserWallet = void 0;
exports.UserWallet = exports.UserWalletKind = exports.EnvelopeVersion = void 0;
const crypto_1 = require("./crypto");
const derivationParams_1 = require("./crypto/derivationParams");
const errors_1 = require("./errors");
const userKeys_1 = require("./userKeys");
var EnvelopeVersion;
(function (EnvelopeVersion) {
// Does not have the "kind" field, and is meant to hold the **secret key**.
// The "crypto" section is not versioned.
EnvelopeVersion[EnvelopeVersion["V4"] = 4] = "V4";
// Has the "kind" field, and is meant to hold the **secret key** or **the mnemonic** (or any other secret payload).
// Furthermore, the "crypto" section is versioned separately.
EnvelopeVersion[EnvelopeVersion["V5"] = 5] = "V5";
})(EnvelopeVersion = exports.EnvelopeVersion || (exports.EnvelopeVersion = {}));
var UserWalletKind;
(function (UserWalletKind) {
UserWalletKind["SecretKey"] = "secretKey";
UserWalletKind["Mnemonic"] = "mnemonic";
UserWalletKind["Arbitrary"] = "arbitrary";
})(UserWalletKind = exports.UserWalletKind || (exports.UserWalletKind = {}));
class UserWallet {
/**
* Copied from: https://github.com/multiversx/mx-deprecated-core-js/blob/v1.28.0/src/account.js#L76
* Notes: adjustements (code refactoring, no change in logic), in terms of:
* - typing (since this is the TypeScript version)
* - error handling (in line with sdk-core's error system)
* - references to crypto functions
* - references to object members
*
* Given a password, generates the contents for a file containing the account's secret key,
* passed through a password-based key derivation function (kdf).
*/
constructor(secretKey, password, randomness = new crypto_1.Randomness()) {
const text = Buffer.concat([secretKey.valueOf(), secretKey.generatePublicKey().valueOf()]);
this.encryptedData = crypto_1.Encryptor.encrypt(text, password, randomness);
this.publicKey = secretKey.generatePublicKey();
constructor({ envelopeVersion: envelopeVersion, kind, encryptedData, publicKeyWhenKindIsSecretKey }) {
this.envelopeVersion = envelopeVersion;
this.kind = kind;
this.encryptedData = encryptedData;
this.publicKeyWhenKindIsSecretKey = publicKeyWhenKindIsSecretKey;
}
static fromSecretKey({ envelopeVersion, encryptorVersion, secretKey, password, randomness, }) {
envelopeVersion = envelopeVersion || EnvelopeVersion.V4;
encryptorVersion = encryptorVersion || crypto_1.EncryptorVersion.V4;
randomness = randomness || new crypto_1.Randomness();
const publicKey = secretKey.generatePublicKey();
const text = Buffer.concat([secretKey.valueOf(), publicKey.valueOf()]);
const encryptedData = crypto_1.Encryptor.encrypt(encryptorVersion, text, password, randomness);
return new UserWallet({
envelopeVersion: envelopeVersion,
kind: UserWalletKind.SecretKey,
encryptedData,
publicKeyWhenKindIsSecretKey: publicKey
});
}
static fromMnemonic({ envelopeVersion, encryptorVersion, mnemonic, password, randomness, }) {
envelopeVersion = envelopeVersion || EnvelopeVersion.V5;
encryptorVersion = encryptorVersion || crypto_1.EncryptorVersion.V4;
randomness = randomness || new crypto_1.Randomness();
const encryptedData = crypto_1.Encryptor.encrypt(encryptorVersion, Buffer.from(mnemonic), password, randomness);
return new UserWallet({
envelopeVersion: envelopeVersion,
kind: UserWalletKind.Mnemonic,
encryptedData
});
}
static fromArbitrary({ envelopeVersion, encryptorVersion, arbitraryData, password, randomness, }) {
envelopeVersion = envelopeVersion || EnvelopeVersion.V5;
encryptorVersion = encryptorVersion || crypto_1.EncryptorVersion.V4;
randomness = randomness || new crypto_1.Randomness();
const encryptedData = crypto_1.Encryptor.encrypt(encryptorVersion, arbitraryData, password, randomness);
return new UserWallet({
envelopeVersion: envelopeVersion,
kind: UserWalletKind.Arbitrary,
encryptedData
});
}
/**

@@ -35,2 +77,5 @@ * Copied from: https://github.com/multiversx/mx-deprecated-core-js/blob/v1.28.0/src/account.js#L42

static decryptSecretKey(keyFileObject, password) {
if (keyFileObject.version >= EnvelopeVersion.V5) {
this.requireKind(keyFileObject.kind, UserWalletKind.SecretKey, "decryptSecretKey");
}
const encryptedData = UserWallet.edFromJSON(keyFileObject);

@@ -42,8 +87,27 @@ let text = crypto_1.Decryptor.decrypt(encryptedData, password);

}
let seed = text.slice(0, 32);
const seed = text.slice(0, 32);
return new userKeys_1.UserSecretKey(seed);
}
static decryptMnemonic(keyFileObject, password) {
this.requireV5OrHigher(keyFileObject.version, "decryptMnemonic");
this.requireKind(keyFileObject.kind, UserWalletKind.Mnemonic, "decryptMnemonic");
const encryptedData = UserWallet.edFromJSON(keyFileObject);
const text = crypto_1.Decryptor.decrypt(encryptedData, password);
return text.toString();
}
static decryptArbitrary(keyFileObject, password) {
this.requireV5OrHigher(keyFileObject.version, "decryptArbitrary");
this.requireKind(keyFileObject.kind, UserWalletKind.Arbitrary, "decryptArbitrary");
const encryptedData = UserWallet.edFromJSON(keyFileObject);
const data = crypto_1.Decryptor.decrypt(encryptedData, password);
return data;
}
static edFromJSON(keyfileObject) {
const encryptorVersion = (keyfileObject.version == EnvelopeVersion.V4) ?
// In V4, the "crypto" section inherits the version from the envelope.
crypto_1.EncryptorVersion.V4 :
// In V5, the "crypto" section has its own version.
keyfileObject.crypto.version;
return new crypto_1.EncryptedData({
version: crypto_1.Version,
version: encryptorVersion,
id: keyfileObject.id,

@@ -63,25 +127,46 @@ cipher: keyfileObject.crypto.cipher,

toJSON() {
if (this.kind == UserWalletKind.SecretKey) {
return this.getEnvelopeWhenKindIsSecretKey();
}
return this.getEnvelopeWhenKindIsMnemonicOrArbitrary();
}
getEnvelopeWhenKindIsSecretKey() {
if (!this.publicKeyWhenKindIsSecretKey) {
throw new errors_1.Err("Public key isn't available");
}
const cryptoSection = this.getCryptoSectionAsJSON();
const envelope = Object.assign(Object.assign({ version: this.envelopeVersion }, (this.envelopeVersion >= 5 ? { kind: UserWalletKind.SecretKey } : {})), { id: this.encryptedData.id, address: this.publicKeyWhenKindIsSecretKey.hex(), bech32: this.publicKeyWhenKindIsSecretKey.toAddress().toString(), crypto: cryptoSection });
return envelope;
}
getCryptoSectionAsJSON() {
const cryptoSection = Object.assign(Object.assign({}, (this.envelopeVersion >= 5 ? { version: this.encryptedData.version } : {})), { ciphertext: this.encryptedData.ciphertext, cipherparams: { iv: this.encryptedData.iv }, cipher: crypto_1.CipherAlgorithm, kdf: crypto_1.KeyDerivationFunction, kdfparams: {
dklen: this.encryptedData.kdfparams.dklen,
salt: this.encryptedData.salt,
n: this.encryptedData.kdfparams.n,
r: this.encryptedData.kdfparams.r,
p: this.encryptedData.kdfparams.p
}, mac: this.encryptedData.mac });
return cryptoSection;
}
getEnvelopeWhenKindIsMnemonicOrArbitrary() {
const cryptoSection = this.getCryptoSectionAsJSON();
return {
version: crypto_1.Version,
version: this.envelopeVersion,
id: this.encryptedData.id,
address: this.publicKey.hex(),
bech32: this.publicKey.toAddress().toString(),
crypto: {
ciphertext: this.encryptedData.ciphertext,
cipherparams: { iv: this.encryptedData.iv },
cipher: crypto_1.CipherAlgorithm,
kdf: crypto_1.KeyDerivationFunction,
kdfparams: {
dklen: this.encryptedData.kdfparams.dklen,
salt: this.encryptedData.salt,
n: this.encryptedData.kdfparams.n,
r: this.encryptedData.kdfparams.r,
p: this.encryptedData.kdfparams.p
},
mac: this.encryptedData.mac,
}
kind: this.kind,
crypto: cryptoSection
};
}
static requireKind(kind, expectedKind, context) {
if (kind != expectedKind) {
throw new errors_1.Err(`Expected kind to be ${expectedKind}, but it was ${kind}. Context: ${context}`);
}
}
static requireV5OrHigher(version, context) {
if (version < EnvelopeVersion.V5) {
throw new errors_1.Err(`Unsupported version: ${version}. Context: ${context}`);
}
}
}
exports.UserWallet = UserWallet;
//# sourceMappingURL=userWallet.js.map
{
"name": "@multiversx/sdk-wallet",
"version": "3.0.0-alpha.1",
"version": "v3.0.0-alpha.2",
"description": "Wallet components for MultiversX",

@@ -5,0 +5,0 @@ "main": "out/index.js",

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc