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

@arcblock/forge-wallet

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcblock/forge-wallet - npm Package Compare versions

Comparing version 0.20.1 to 0.20.5

119

lib/index.js

@@ -0,1 +1,7 @@

/**
* @fileOverview This module wraps common utility functions to help developers manipulate crypto wallets
* @module @arcblock/forge-wallet
* @requires @arcblock/mcrypto
* @requires @arcblock/abt-did
*/
const upperFirst = require('lodash/upperFirst');

@@ -10,2 +16,31 @@ const { types, getSigner, getHasher } = require('@arcblock/mcrypto');

/**
* The structure of a forge wallet type
*
* @public
* @static
* @typedef {Object} walletType
* @prop {number} role - Enum field to identify wallet role type
* @prop {number} pk - Crypto algorithm to derive publicKey from the secretKey
* @prop {number} hash - Hash algorithm used to hash data before sign them
*/
/**
* Create an wallet type object that be used as param to create a new wallet
*
* @public
* @static
* @param {...walletType} type
* @returns {object}
* @example
* const assert = require('assert');
* const { WalletType } = require('@arcblock/forge-wallet');
* const { types } = require('@arcblock/mcrypto');
*
* const type = WalletType({
* role: types.RoleType.ROLE_APPLICATION,
* pk: types.KeyType.ED25519,
* hash: types.HashType.SHA3,
* });
*/
function WalletType(type) {

@@ -43,2 +78,13 @@ const { role, pk, hash } = type;

/**
* Generate an wallet instance that can be used to sign a message or verify a signature
*
* @public
* @static
* @param {object} keyPair - the key pair
* @param {string} keyPair.sk - the secretKey
* @param {string} keyPair.pk - the wallet publicKey
* @param {...walletType} type - wallet type
* @returns {object} generated wallet instance
*/
function Wallet(keyPair, type) {

@@ -83,2 +129,25 @@ const signer = getSigner(type.pk);

/**
* Generate a wallet from secretKey
*
* @public
* @static
* @param {string} sk - the secret key, `hex encoded string`
* @param {...walletType} type - wallet type
* @returns {object} wallet instance
* @example
* const assert = require('assert');
* const { fromSecretKey } = require('@arcblock/forge-wallet');
*
* const sk =
* '0xD67C071B6F51D2B61180B9B1AA9BE0DD0704619F0E30453AB4A592B036EDE644E4852B7091317E3622068E62A5127D1FB0D4AE2FC50213295E10652D2F0ABFC7';
* const sig =
* '0x08a102851c38c072e42756c1cc70938b5499c8e9358dfe5f383823f56cdb282ffda60fcd581a02c6c673069e5afc0bf09abbe3639b61b84d64fd58ef9f083003';
*
* const wallet = fromSecretKey(sk, type);
* const message = 'data to sign';
* const signature = wallet.sign(message);
* assert.equal(signature, sig, "signature should match");
* assert.ok(wallet.verify(message, signature), "signature should be verified");
*/
function fromSecretKey(sk, _type) {

@@ -90,2 +159,11 @@ const type = WalletType(_type);

/**
* Generate a wallet from publicKey
*
* @public
* @static
* @param {string} pk - the public key, `hex encoded string`
* @param {...walletType} type - wallet type
* @returns {object} wallet instance
*/
function fromPublicKey(pk, _type) {

@@ -95,2 +173,19 @@ return Wallet({ pk }, WalletType(_type));

/**
* Generate a wallet from address (did)
*
* Since we do not know the publicKey and secretKey, this kind of wallet cannot be used for signing and verifying
*
* @public
* @static
* @param {string} address - the wallet address
* @returns wallet instance
* @example
* const assert = require('assert');
* const { fromAddress } = require('@arcblock/forge-wallet');
*
* const address = 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr';
* const wallet = fromAddress(address);
* console.log(wallet.toJSON());
*/
function fromAddress(address) {

@@ -100,2 +195,14 @@ return Wallet({ address: toAddress(address) }, WalletType(toTypeInfo(address)));

/**
* Generate a wallet by generating a random secretKey
*
* @public
* @static
* @param {...walletType} type - wallet type
* @returns {object} wallet instance
* @example
* const { fromRandom } = require('@arcblock/forge-wallet');
* const wallet = fromRandom(type);
* // Do something with wallet
*/
function fromRandom(_type) {

@@ -108,2 +215,14 @@ const type = WalletType(_type);

/**
* Generating a wallet from a serialized json presentation of another wallet
*
* @public
* @static
* @param {object} json
* @returns wallet instance
* @example
* const { fromJSON } = require('@arcblock/forge-wallet');
* const wallet2 = fromJSON(wallet.toJSON());
* // wallet2 is identical to wallet
*/
function fromJSON(json) {

@@ -110,0 +229,0 @@ const type = WalletType.fromJSON(json.type);

6

package.json
{
"name": "@arcblock/forge-wallet",
"version": "0.20.1",
"version": "0.20.5",
"description": "Utility function to create and use an forge compatible crypto wallet",

@@ -40,5 +40,5 @@ "keywords": [

"@arcblock/abt-did": "^0.19.0",
"@arcblock/mcrypto": "^0.20.0"
"@arcblock/mcrypto": "^0.20.5"
},
"gitHead": "081809219385c09c6198bde48f9200eac107412b"
"gitHead": "b8526f942e8a04bcbeb47b0d6e1bd77570a29dd2"
}

@@ -16,3 +16,3 @@ # `@arcblock/forge-wallet`

const assert = require('assert');
const { fromSecretKey, fromJSON } = require('@arcblock/forge-wallet');
const { fromSecretKey, WalletType, fromJSON } = require('@arcblock/forge-wallet');
const { types } = require('@arcblock/mcrypto');

@@ -26,7 +26,7 @@

const type = {
const type = WalletType({
role: types.RoleType.ROLE_APPLICATION,
pk: types.KeyType.ED25519,
hash: types.HashType.SHA3,
};
});

@@ -33,0 +33,0 @@ const wallet = fromSecretKey(sk, type);

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