Socket
Socket
Sign inDemoInstall

@arcblock/mcrypto

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcblock/mcrypto - npm Package Compare versions

Comparing version 0.21.0 to 0.22.0

158

lib/index.js

@@ -18,35 +18,2 @@ /**

// FIXME: enum definition of forge-abi and abt-did-elixir are not exactly the same
const types = {
KeyType: {
ED25519: 0,
SECP256K1: 1,
},
HashType: {
KECCAK: 0,
SHA3: 1,
KECCAK_384: 2,
SHA3_384: 3,
KECCAK_512: 4,
SHA3_512: 5,
},
RoleType: {
ROLE_ACCOUNT: 0,
ROLE_NODE: 1,
ROLE_DEVICE: 2,
ROLE_APPLICATION: 3,
ROLE_SMART_CONTRACT: 4,
ROLE_BOT: 5,
ROLE_ASSET: 6,
ROLE_STAKE: 7,
ROLE_VALIDATOR: 8,
ROLE_GROUP: 9,
ROLE_ANY: 63,
},
EncodingType: {
BASE16: 0,
BASE58: 1,
},
};
const Mcrypto = (module.exports = {

@@ -60,2 +27,11 @@ /**

* @static
* @example
* const { Signer } = require('@arcblock/mcrypto');
* const message = 'some message to sign';
*
* // Use Signer directly
* const keyPair = Signer.Ed25519.genKeyPair();
* const signature = Signer.Ed25519.sign(message, keyPair.secretKey);
* const result = Signer.Ed25519.verify(message, signature, keyPair.publicKey);
* assert.ok(result);
*/

@@ -74,2 +50,7 @@ Signer: {

* @static
* @example
* const { Hasher } = require('@arcblock/mcrypto');
*
* const message = 'message to hash';
* const hash = Hasher.SHA2.hash256(message);
*/

@@ -94,6 +75,4 @@ Hasher: {

* Contains type constants that represent can be used to compose different crypto method, each crypto method consist one of:
* FIXME: enum definition of forge-abi and abt-did-elixir are not exactly the same
*
* - Signer
* - Hahser
*
* @readonly

@@ -103,4 +82,77 @@ * @type {object}

* @static
* @example
* const { types } = require('@arcblock/mcrypto');
*
* // types.RoleType.ROLE_ACCOUNT
* // types.KeyType.ED25519
* // types.HashType.SHA3
* // types.EncodingType.BASE58
*/
types,
types: {
/**
* Key-pair derivation algorithms
*
* @readonly
* @enum {number}
* @name types.KeyType
* @memberof types
* @static
*/
KeyType: {
ED25519: 0,
SECP256K1: 1,
},
/**
* Hashing algorithms
*
* @readonly
* @enum {number}
* @name types.HashType
* @memberof types
* @static
*/
HashType: {
KECCAK: 0,
SHA3: 1,
KECCAK_384: 2,
SHA3_384: 3,
KECCAK_512: 4,
SHA3_512: 5,
},
/**
* DID wallet role type
*
* @readonly
* @enum {number}
* @name types.RoleType
* @memberof types
* @static
*/
RoleType: {
ROLE_ACCOUNT: 0,
ROLE_NODE: 1,
ROLE_DEVICE: 2,
ROLE_APPLICATION: 3,
ROLE_SMART_CONTRACT: 4,
ROLE_BOT: 5,
ROLE_ASSET: 6,
ROLE_STAKE: 7,
ROLE_VALIDATOR: 8,
ROLE_GROUP: 9,
ROLE_ANY: 63,
},
/**
* Address encoding algorithm, defaults to `base58btc`
*
* @readonly
* @enum {number}
* @name types.RoleType
* @memberof types
* @static
*/
EncodingType: {
BASE16: 0,
BASE58: 1,
},
},

@@ -116,12 +168,5 @@ /**

* @example
* const { Signer, getSigner, types } = require('@arcblock/mcrypto');
* const { getSigner, types } = require('@arcblock/mcrypto');
* const message = 'some message to sign';
*
* // Use Signer directly
* const keyPair = Signer.Ed25519.genKeyPair();
* const signature = Signer.Ed25519.sign(message, keyPair.secretKey);
* const result = Signer.Ed25519.verify(message, signature, keyPair.publicKey);
* assert.ok(result);
*
* // Get signer on fly
* const signer = getSigner(types.KeyType.ED25519);

@@ -154,9 +199,4 @@ * const keyPair1 = signer.genKeyPair();

* @example
* const { Hasher, getHasher, types } = require('@arcblock/mcrypto');
* const { getHasher, types } = require('@arcblock/mcrypto');
*
* // Choose from Hasher
* const message = 'message to hash';
* const hash = Hasher.SHA2.hash256(message);
*
* // user getHasher
* const hashFn = getHasher(types.HashType.SHA3);

@@ -175,13 +215,13 @@ * const hash2 = hashFn(message);

const Signers = Object.freeze({
[types.KeyType.ED25519]: Mcrypto.Signer.Ed25519,
[types.KeyType.SECP256K1]: Mcrypto.Signer.Secp256k1,
[Mcrypto.types.KeyType.ED25519]: Mcrypto.Signer.Ed25519,
[Mcrypto.types.KeyType.SECP256K1]: Mcrypto.Signer.Secp256k1,
});
const Hashers = Object.freeze({
[types.HashType.KECCAK]: Mcrypto.Hasher.Keccak.hash256,
[types.HashType.KECCAK_384]: Mcrypto.Hasher.Keccak.hash384,
[types.HashType.KECCAK_512]: Mcrypto.Hasher.Keccak.hash512,
[types.HashType.SHA3]: Mcrypto.Hasher.SHA3.hash256,
[types.HashType.SHA3_384]: Mcrypto.Hasher.SHA3.hash384,
[types.HashType.SHA3_512]: Mcrypto.Hasher.SHA3.hash512,
[Mcrypto.types.HashType.KECCAK]: Mcrypto.Hasher.Keccak.hash256,
[Mcrypto.types.HashType.KECCAK_384]: Mcrypto.Hasher.Keccak.hash384,
[Mcrypto.types.HashType.KECCAK_512]: Mcrypto.Hasher.Keccak.hash512,
[Mcrypto.types.HashType.SHA3]: Mcrypto.Hasher.SHA3.hash256,
[Mcrypto.types.HashType.SHA3_384]: Mcrypto.Hasher.SHA3.hash384,
[Mcrypto.types.HashType.SHA3_512]: Mcrypto.Hasher.SHA3.hash512,
});
{
"name": "@arcblock/mcrypto",
"version": "0.21.0",
"version": "0.22.0",
"description": "Crypto lib that provides signer,crypter,hasher interface",

@@ -23,3 +23,4 @@ "keywords": [

"devDependencies": {
"jest": "^23.5.0"
"jest": "^23.5.0",
"jsdoc-to-markdown": "^4.0.1"
},

@@ -35,2 +36,4 @@ "repository": {

"test": "npm run lint && node tools/jest.js",
"format-docs": "remark . -o",
"generate-docs": "jsdoc2md lib/index.js > docs/README.md",
"coverage": "npm run lint && npm run test -- --coverage"

@@ -42,3 +45,3 @@ },

"dependencies": {
"@arcblock/forge-util": "^0.21.0",
"@arcblock/forge-util": "^0.22.0",
"crypto-js": "^3.1.9-1",

@@ -51,3 +54,3 @@ "elliptic": "^6.4.1",

},
"gitHead": "70d1b0561d18f4a2082d379d836ef44ef7ac5317"
"gitHead": "1e2bc71da51158cd827b3b5e544d91a73fdfadf4"
}

@@ -5,5 +5,8 @@ # `@arcblock/mcrypto`

## Usage
```shell
npm i @arcblock/mcrypto -S
# OR
yarn add @arcblock/mcrypto

@@ -35,2 +38,6 @@ ```

## Documentation
For full documentation, checkout [README.md](./docs/README.md).
## Implementation

@@ -40,13 +47,13 @@

- keccakf1600: crypto-js
- sha2: crypto-js
- sha3: jssha3
* keccakf1600: crypto-js
* sha2: crypto-js
* sha3: jssha3
### Signer
- ed25519: tweetnacl
- secp256k1: elliptic
* [`ed25519`](https://github.com/ArcBlock/forge-js/commit/ed25519): tweetnacl
* secp256k1: elliptic
### Crypter
- aes-cbc-256: crypto-js
* aes-cbc-256: crypto-js
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