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

crypto-addr-codec

Package Overview
Dependencies
Maintainers
5
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crypto-addr-codec - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

dist/index.js

17

lib/bs58/bs58.js

@@ -27,10 +27,10 @@ /*!

'use strict'
import Sha256 from '../sha256';
import base58 from 'bs58';
const createHash = require('../sha256/index')
var base58 = require('bs58')
function sha256x2 (buffer) {
var tmp = createHash('sha256').update(buffer).digest()
return createHash('sha256').update(tmp).digest()
var tmp = new Sha256().update(buffer).digest()
return new Sha256().update(tmp).digest()
}
const bs58Check = function (checksumFn) {

@@ -73,2 +73,7 @@ // Encode a buffer as a base58-check encoded string

};
module.exports = bs58Check(sha256x2);
const bs58 = bs58Check(sha256x2);
export const { bs58Decode, bs58Encode, decodeUnsafe } = bs58;
export default bs58;

@@ -36,11 +36,7 @@ /*!

'use strict';
import { validate } from './validation';
var validation = require('./validation');
var validate = validation.validate;
/**
* U64
*/
/* tslint:disable:no-bitwise curly object-literal-sort-keys variable-name*/
class U64 {

@@ -447,3 +443,3 @@ constructor(hi, lo) {

function encode(prefix, type, hash) {
export function cashaddrEncode(prefix, type, hash) {
validate(typeof prefix === 'string');

@@ -475,3 +471,3 @@ // There are 4 bits available for the version (2 ^ 4 = 16)

function decode(str, defaultPrefix = 'bitcoincash') {
export function cashaddrDecode(str, defaultPrefix = 'bitcoincash') {
validate(typeof str === 'string');

@@ -520,5 +516,5 @@ validate(typeof defaultPrefix === 'string');

function test(str, defaultPrefix = 'bitcoincash') {
export function cashaddrTest(str, defaultPrefix = 'bitcoincash') {
try {
decode(str, defaultPrefix);
cashaddrDecode(str, defaultPrefix);
} catch (e) {

@@ -529,14 +525,1 @@ return false;

}
/*
* Expose
*/
module.exports = {
cashaddrEncode: encode,
cashaddrDecode: decode,
cashaddrTest: test,
};
/* tslint:enable:no-bitwise curly object-literal-sort-keys variable-name*/

@@ -9,4 +9,2 @@ /**

'use strict';
/**

@@ -24,3 +22,3 @@ * Validation utility.

*/
function ValidationError(message) {
export function ValidationError(message) {
var error = new Error();

@@ -42,3 +40,3 @@ this.name = error.name = 'ValidationError';

*/
function validate(condition, message) {
export function validate(condition, message) {
if (message == null) {

@@ -51,6 +49,1 @@ message = "Assertion failed.";

}
module.exports = {
ValidationError: ValidationError,
validate: validate,
};

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

var assert = require('assert')
var { ZERO, ONE } = require('bigi/lib/bigi')
import bigInt from 'big-integer';
import Point from './point';
import { assert } from './../helper';
var Point = require('./point')
const ZERO = bigInt.zero;
const ONE = bigInt.one;
function Curve (p, a, b, Gx, Gy, n, h) {
export default function Curve (p, a, b, Gx, Gy, n, h) {
this.p = p

@@ -38,3 +40,3 @@ this.a = a

return Q.z.signum() === 0 && Q.y.signum() !== 0
return Q.z.compare(ZERO) === 0 && Q.y.compare(ZERO) !== 0
}

@@ -52,4 +54,4 @@

// Check that xQ and yQ are integers in the interval [0, p - 1]
if (x.signum() < 0 || x.compareTo(p) >= 0) return false
if (y.signum() < 0 || y.compareTo(p) >= 0) return false
if (x.compare(ZERO) < 0 || x.compareTo(p) >= 0) return false
if (y.compare(ZERO) < 0 || y.compareTo(p) >= 0) return false

@@ -78,3 +80,1 @@ // and check that y^2 = x^3 + ax + b (mod p)

}
module.exports = Curve

@@ -1,10 +0,3 @@

var Point = require('./point')
var Curve = require('./curve')
var getCurveByName = require('./names')
module.exports = {
Curve: Curve,
Point: Point,
getCurveByName: getCurveByName
}
export { default as Point } from './point';
export { default as Curve } from './curve';
export { default as getCurveByName } from './names';

@@ -1,21 +0,21 @@

var BigInteger = require('bigi')
import bigInt from 'big-integer';
import curves from './curves.json';
import Curve from './curve';
var curves = require('./curves.json')
var Curve = require('./curve')
export default function getCurveByName (name) {
const curve = curves[name];
function getCurveByName (name) {
var curve = curves[name]
if (!curve) return null
if (!curve) {
return null;
}
var p = new BigInteger(curve.p, 16)
var a = new BigInteger(curve.a, 16)
var b = new BigInteger(curve.b, 16)
var n = new BigInteger(curve.n, 16)
var h = new BigInteger(curve.h, 16)
var Gx = new BigInteger(curve.Gx, 16)
var Gy = new BigInteger(curve.Gy, 16)
const p = bigInt(curve.p, 16);
const a = bigInt(curve.a, 16);
const b = bigInt(curve.b, 16);
const n = bigInt(curve.n, 16);
const h = bigInt(curve.h, 16);
const Gx = bigInt(curve.Gx, 16);
const Gy = bigInt(curve.Gy, 16);
return new Curve(p, a, b, Gx, Gy, n, h)
return new Curve(p, a, b, Gx, Gy, n, h);
}
module.exports = getCurveByName

@@ -1,9 +0,26 @@

var assert = require('assert')
var BigInteger = require('bigi/lib/bigi')
import bigInt from 'big-integer';
import { assert } from './../helper';
var THREE = BigInteger.valueOf(3)
const ONE = bigInt.one;
const ZERO = bigInt.zero;
const THREE = bigInt(3);
function Point (curve, x, y, z) {
assert.notStrictEqual(z, undefined, 'Missing Z coordinate')
function testBit(bigIntVal, n) {
return bigIntVal.and(ONE.shiftLeft(n)).notEquals(ZERO);
}
function bufferToBigInt(buffer) {
return bigInt.fromArray(Array.prototype.slice.call(buffer, 0), 256);
}
function bigIntToBuffer(bigIntVal, size) {
const { value } = bigIntVal.toArray(256);
const zeroBytesLength = size ? Math.max(size - value.length, 0) : 0;
return Buffer.from([...Array(zeroBytesLength).fill(0), ...value]);
}
export default function Point (curve, x, y, z) {
assert(z !== undefined, 'Missing Z coordinate')
this.curve = curve

@@ -21,3 +38,3 @@ this.x = x

if (this._zInv === null) {
this._zInv = this.z.modInverse(this.curve.p)
this._zInv = this.z.modInv(this.curve.p)
}

@@ -42,3 +59,3 @@

Point.fromAffine = function (curve, x, y) {
return new Point(curve, x, y, BigInteger.ONE)
return new Point(curve, x, y, ONE)
}

@@ -54,3 +71,3 @@

if (u.signum() !== 0) return false
if (u.compare(ZERO) !== 0) return false

@@ -60,3 +77,3 @@ // v = X2 * Z1 - X1 * Z2

return v.signum() === 0
return v.compare(ZERO) === 0
}

@@ -84,4 +101,4 @@

if (v.signum() === 0) {
if (u.signum() === 0) {
if (v.compare(ZERO) === 0) {
if (u.compare(ZERO) === 0) {
return this.twice() // this == b, so double

@@ -110,3 +127,3 @@ }

if (this.curve.isInfinity(this)) return this
if (this.y.signum() === 0) return this.curve.infinity
if (this.y.compare(ZERO) === 0) return this.curve.infinity

@@ -123,3 +140,3 @@ var x1 = this.x

if (a.signum() !== 0) {
if (a.compare(ZERO) !== 0) {
w = w.add(this.z.square().multiply(a))

@@ -143,3 +160,3 @@ }

if (this.curve.isInfinity(this)) return this
if (k.signum() === 0) return this.curve.infinity
if (k.compare(ZERO) === 0) return this.curve.infinity

@@ -153,4 +170,4 @@ var e = k

for (var i = h.bitLength() - 2; i > 0; --i) {
var hBit = h.testBit(i)
var eBit = e.testBit(i)
var hBit = testBit(h, i);
var eBit = testBit(e, i);

@@ -174,4 +191,4 @@ R = R.twice()

while (i >= 0) {
var jBit = j.testBit(i)
var kBit = k.testBit(i)
var jBit = testBit(j, i);
var kBit = testBit(k, i);

@@ -214,6 +231,6 @@ R = R.twice()

y.toBuffer(byteLength).copy(buffer, 1 + byteLength)
bigIntToBuffer(y, byteLength).copy(buffer, 1 + byteLength)
}
x.toBuffer(byteLength).copy(buffer, 1)
bigIntToBuffer(x, byteLength).copy(buffer, 1)

@@ -228,7 +245,7 @@ return buffer

var byteLength = Math.floor((curve.p.bitLength() + 7) / 8)
var x = BigInteger.fromBuffer(buffer.slice(1, 1 + byteLength))
var x = bufferToBigInt(buffer.slice(1, 1 + byteLength));
var Q
if (compressed) {
assert.equal(buffer.length, byteLength + 1, 'Invalid sequence length')
assert(buffer.length === byteLength + 1, 'Invalid sequence length')
assert(type === 0x02 || type === 0x03, 'Invalid sequence tag')

@@ -239,5 +256,5 @@

} else {
assert.equal(buffer.length, 1 + byteLength + byteLength, 'Invalid sequence length')
assert(buffer.length === 1 + byteLength + byteLength, 'Invalid sequence length')
var y = BigInteger.fromBuffer(buffer.slice(1 + byteLength))
var y = bufferToBigInt(buffer.slice(1 + byteLength));
Q = Point.fromAffine(curve, x, y)

@@ -255,3 +272,1 @@ }

}
module.exports = Point

@@ -1,16 +0,10 @@

"use strict";
import { SHA3 } from 'sha3';
import { RIPEMD160 } from 'ripemd160-min';
var { SHA3 } = require('sha3');
var RIPEMD160 = require('ripemd160-min').RIPEMD160;
function sha256(data, resultEncoding) {
export function sha256(data, resultEncoding) {
return new SHA3(256).update(data).digest(resultEncoding);
}
function ripemd160(data) {
return Buffer.from(new RIPEMD160().update(data).digest())
export function ripemd160(data) {
return Buffer.from(new RIPEMD160().update(data).digest());
}
module.exports = {
sha256: sha256,
ripemd160: ripemd160 // hash160: hash160,
};

@@ -27,29 +27,15 @@ /*!

"use strict";
import { getCurveByName, Point } from './ecc';
import { checkEncode, checkDecode } from './key_utils';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
const secp256k1 = getCurveByName('secp256k1');
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
export default function PublicKey(Q) {
const pubkey_prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'EOS';
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var ecurve = require('./ecc');
var secp256k1 = ecurve.getCurveByName('secp256k1');
var getCurveByName = require('./ecc/names');
var keyUtils = require('./key_utils');
module.exports = PublicKey;
function PublicKey(Q) {
var pubkey_prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'EOS';
if (typeof Q === 'string') {
var publicKey = PublicKey.fromString(Q, pubkey_prefix);
return publicKey;
return PublicKey.fromString(Q, pubkey_prefix);
} else if (Buffer.isBuffer(Q)) {
return PublicKey.fromBuffer(Q);
} else if ((0, _typeof2["default"])(Q) === 'object' && Q.Q) {
} else if (typeof Q === 'object' && Q.Q) {
return PublicKey(Q.Q);

@@ -59,3 +45,3 @@ }

function toBuffer() {
var compressed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Q.compressed;
const compressed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Q.compressed;
return Q.getEncoded(compressed);

@@ -65,4 +51,4 @@ }

function toString() {
var pubkey_prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'EOS';
return pubkey_prefix + keyUtils.checkEncode(toBuffer());
const pubkey_prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'EOS';
return pubkey_prefix + checkEncode(toBuffer());
}

@@ -75,6 +61,6 @@

return {
Q: Q,
toString: toString,
toBuffer: toBuffer,
toHex: toHex
Q,
toString,
toBuffer,
toHex
};

@@ -84,3 +70,3 @@ }

PublicKey.isValid = function (pubkey) {
var pubkey_prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'EOS';
const pubkey_prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'EOS';

@@ -96,7 +82,7 @@ try {

PublicKey.fromBuffer = function (buffer) {
return PublicKey(ecurve.Point.decodeFrom(secp256k1, buffer));
return PublicKey(Point.decodeFrom(secp256k1, buffer));
};
PublicKey.fromString = function (public_key) {
var pubkey_prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'EOS';
const pubkey_prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'EOS';

@@ -111,8 +97,8 @@ try {

PublicKey.fromStringOrThrow = function (public_key) {
var pubkey_prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'EOS';
var match = public_key.match(/^PUB_([A-Za-z0-9]+)_([A-Za-z0-9]+)$/);
const pubkey_prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'EOS';
const match = public_key.match(/^PUB_([A-Za-z0-9]+)_([A-Za-z0-9]+)$/);
if (match === null) {
// legacy
var prefix_match = new RegExp("^" + pubkey_prefix);
const prefix_match = new RegExp("^" + pubkey_prefix);

@@ -123,10 +109,8 @@ if (prefix_match.test(public_key)) {

return PublicKey.fromBuffer(keyUtils.checkDecode(public_key));
return PublicKey.fromBuffer(checkDecode(public_key));
}
var _match = (0, _slicedToArray2["default"])(match, 3),
keyType = _match[1],
keyString = _match[2];
const [, keyType, keyString] = match;
return PublicKey.fromBuffer(keyUtils.checkDecode(keyString, keyType));
return PublicKey.fromBuffer(checkDecode(keyString, keyType));
};

@@ -140,2 +124,2 @@

return PublicKey.fromString(new Buffer(hex, 'hex'));
};
};

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

"use strict";
import base58 from 'bs58';
import { assert, assertBuffer } from './helper';
import { sha256, ripemd160 } from './hash';
var base58 = require('bs58');
var hash = require('./hash');
module.exports = {
checkDecode: checkDecode,
checkEncode: checkEncode
};
function checkEncode(keyBuffer) {
var keyType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
export function checkEncode(keyBuffer) {
const keyType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
assertBuffer(keyBuffer, 'expecting keyBuffer<Buffer>');

@@ -18,6 +11,6 @@

// legacy
var checksum = hash.sha256(hash.sha256(keyBuffer)).slice(0, 4);
const checksum = sha256(sha256(keyBuffer)).slice(0, 4);
return base58.encode(Buffer.concat([keyBuffer, checksum]));
} else {
var check = [keyBuffer];
const check = [keyBuffer];

@@ -28,3 +21,3 @@ if (keyType) {

var _checksum = hash.ripemd160(Buffer.concat(check)).slice(0, 4);
const _checksum = ripemd160(Buffer.concat(check)).slice(0, 4);

@@ -35,15 +28,15 @@ return base58.encode(Buffer.concat([keyBuffer, _checksum]));

function checkDecode(keyString) {
var keyType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
export function checkDecode(keyString) {
const keyType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
assert(keyString, 'private key expected');
var buffer = new Buffer(base58.decode(keyString));
var checksum = buffer.slice(-4);
var key = buffer.slice(0, -4);
var newCheck;
const buffer = new Buffer(base58.decode(keyString));
const checksum = buffer.slice(-4);
const key = buffer.slice(0, -4);
let newCheck;
if (keyType === 'sha256x2') {
// legacy
newCheck = hash.sha256(hash.sha256(key)).slice(0, 4); // WIF (legacy)
newCheck = sha256(sha256(key)).slice(0, 4); // WIF (legacy)
} else {
var check = [key];
const check = [key];

@@ -54,3 +47,3 @@ if (keyType) {

newCheck = hash.ripemd160(Buffer.concat(check)).slice(0, 4); //PVT
newCheck = ripemd160(Buffer.concat(check)).slice(0, 4); //PVT
}

@@ -64,13 +57,1 @@

}
const assert = (value, errMsg) => {
if (!value) {
throw errMsg
}
};
const assertBuffer = (keyBuffer, errMsg) => {
if (!Buffer.isBuffer(keyBuffer)) {
throw errMsg
}
};

@@ -1,32 +0,8 @@

'use strict';
const { b32decode, b32encode, hex2a, ua2hex, isValid } = require('./nem-sdk/convert');
const { bs58Decode, bs58Encode } = require('./bs58/bs58');
const { cashaddrDecode, cashaddrEncode } = require('./cashaddr/cashaddr');
const { codec } = require('./ripple/xrp-codec');
const { isValidChecksumAddress, stripHexPrefix, toChecksumAddress } = require('./rskjs/rsk');
const eosPublicKey = require('./eos/key_public');
const { encodeCheck, decodeCheck, calculateChecksum } = require('./str/publicKey');
const { ss58Encode, ss58Decode } = require('./ss58');
module.exports = {
b32decode,
b32encode,
bs58Decode,
bs58Encode,
cashaddrEncode,
cashaddrDecode,
hex2a,
ua2hex,
isValid,
isValidChecksumAddress,
stripHexPrefix,
toChecksumAddress,
codec,
eosPublicKey,
encodeCheck,
decodeCheck,
calculateChecksum,
ss58Encode,
ss58Decode,
};
export { b32decode, b32encode, hex2a, ua2hex, isValid } from './nem-sdk/convert';
export { codec } from './ripple/xrp-codec';
export { isValidChecksumAddress, stripHexPrefix, toChecksumAddress } from './rskjs/rsk';
export { default as eosPublicKey } from './eos/key_public';
export { encodeCheck, decodeCheck, calculateChecksum } from './str/publicKey';
export { ss58Encode, ss58Decode } from './ss58';
export { cashaddrDecode, cashaddrEncode } from'./cashaddr/cashaddr';
export { bs58Decode, bs58Encode } from './bs58/bs58';

@@ -27,5 +27,7 @@ /*!

const { Keccak } = require('sha3')
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
const hex2a = (hexx) => {
import { Keccak } from 'sha3';
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
export const hex2a = (hexx) => {
var hex = hexx.toString();

@@ -40,3 +42,3 @@ var str = '';

const ua2hex = (ua) => {
export const ua2hex = (ua) => {
var s = '';

@@ -51,3 +53,3 @@ for (var i = 0; i < ua.length; i++) {

const b32decode = function b32decode(s) {
export const b32decode = function b32decode(s) {
var r = new ArrayBuffer(s.length * 5 / 8);

@@ -70,3 +72,3 @@ var b = new Uint8Array(r);

const b32encode = function b32encode(s) {
export const b32encode = function b32encode(s) {
var parts = [];

@@ -104,3 +106,3 @@ var quanta = Math.floor(s.length / 5);

const isValid = addr => {
export const isValid = addr => {
let address = addr.toString().toUpperCase().replace(/-/g, '');

@@ -133,3 +135,1 @@ if (!address || address.length !== 40) {

};
module.exports = { hex2a, ua2hex: ua2hex, b32decode: b32decode, b32encode: b32encode, isValid: isValid};

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

function seqEqual(arr1, arr2) {
export function seqEqual(arr1, arr2) {
if (arr1.length !== arr2.length) {

@@ -15,3 +15,3 @@ return false;

}
function concatArgs(...args) {
export function concatArgs(...args) {
const ret = [];

@@ -30,2 +30,1 @@ args.forEach(function (arg) {

}
module.exports = { seqEqual, concatArgs };

@@ -12,3 +12,3 @@ /*!

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL

@@ -21,7 +21,6 @@ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN

"use strict";
import baseCodec from 'base-x';
import Sha256 from '../sha256';
import { seqEqual, concatArgs } from './utils';
Object.defineProperty(exports, "__esModule", { value: true });
const baseCodec = require("base-x");
const utils_1 = require("./utils");
class Codec {

@@ -36,3 +35,3 @@ constructor(options) {

const check = this.sha256(this.sha256(buffer)).slice(0, 4);
return this.encodeRaw(Buffer.from(utils_1.concatArgs(buffer, check)));
return this.encodeRaw(Buffer.from(concatArgs(buffer, check)));
}

@@ -58,14 +57,13 @@ encodeRaw(bytes) {

const checksum = bytes.slice(-4);
return utils_1.seqEqual(computed, checksum);
return seqEqual(computed, checksum);
}
}
const checkHash = require('../sha256/index');
const codecOptions = {
sha256: function (bytes) {
return checkHash('sha256').update(Buffer.from(bytes)).digest();
return new Sha256().update(Buffer.from(bytes)).digest();
},
alphabet: 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz'
};
const codecWithXrpAlphabet = new Codec(codecOptions);
exports.codec = codecWithXrpAlphabet;
export const codec = new Codec(codecOptions);

@@ -11,13 +11,13 @@ /*!

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN T

@@ -28,8 +28,8 @@ HE SOFTWARE.

const { Keccak } = require('sha3')
import { Keccak } from 'sha3';
const stripHexPrefix = (str) => {
export const stripHexPrefix = (str) => {
return str.slice(0, 2) === '0x' ? str.slice(2) : str
};
const toChecksumAddress = (address, chainId = null) => {
export const toChecksumAddress = (address, chainId = null) => {
if (typeof address !== 'string') {

@@ -49,3 +49,3 @@ throw new Error("stripHexPrefix param must be type 'string', is currently type " + (typeof address) + ".");

};
function isValidChecksumAddress(address, chainId) {
export function isValidChecksumAddress(address, chainId) {
return isValidAddress(address) && (toChecksumAddress(address, chainId) === address)

@@ -59,2 +59,1 @@ }

}
module.exports = { isValidChecksumAddress, stripHexPrefix, toChecksumAddress };

@@ -10,6 +10,6 @@ /**

*/
var Buffer = require('safe-buffer').Buffer
import { Buffer } from 'safe-buffer';
// prototype class for hash functions
function Hash (blockSize, finalSize) {
export default function Hash (blockSize, finalSize) {
this._block = Buffer.alloc(blockSize)

@@ -90,3 +90,1 @@ this._finalSize = finalSize

}
module.exports = Hash

@@ -1,10 +0,1 @@

var exports = module.exports = function SHA (algorithm) {
algorithm = algorithm.toLowerCase()
var Algorithm = exports[algorithm]
if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
return new Algorithm()
}
exports.sha256 = require('./sha256')
export { default } from './sha256';

@@ -11,6 +11,19 @@ /**

var inherits = require('inherits')
var Hash = require('./hash')
var Buffer = require('safe-buffer').Buffer
import { Buffer } from 'safe-buffer';
import Hash from './hash';
function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
}
}
var K = [

@@ -37,3 +50,3 @@ 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,

function Sha256 () {
export default function Sha256 () {
this.init()

@@ -138,3 +151,1 @@

}
module.exports = Sha256

@@ -20,4 +20,4 @@ /*! Copyright (c) 2019 Parity Tech

//
const bs58 = require('bs58');
const { blake2b } = require('blakejs');
import bs58 from 'bs58';
import { blake2b } from 'blakejs/blake2b';

@@ -69,3 +69,19 @@ let defaultType = 42

function ss58Encode(a, type = defaultType, checksumLength = null, length = null, accountId) {
function mergeUint8Arrays(a, b) {
if (!a.length) {
a = [a];
}
if (!b.length) {
b = [b];
}
const c = new Uint8Array(a.length + b.length);
c.set(a);
c.set(b, a.length);
return c;
}
export function ss58Encode(a, type = defaultType, checksumLength = null, length = null, accountId) {
let payload

@@ -99,4 +115,4 @@ if (KNOWN_TYPES.indexOf(type) === -1) {

}
let hash = blake2b(new Uint8Array([...PREFIX, ...((type & 1) ? accountId : new Uint8Array([type, ...payload]))]))
let complete = new Uint8Array([type, ...payload, ...hash.slice(0, checksumLength)])
let hash = blake2b(mergeUint8Arrays(PREFIX, ((type & 1) ? accountId : mergeUint8Arrays(type, payload))));
let complete = mergeUint8Arrays(mergeUint8Arrays(type, payload), hash.slice(0, checksumLength));
return bs58.encode(Buffer.from(complete))

@@ -106,3 +122,3 @@ }

function ss58Decode(ss58, lookupIndex=0) {
export function ss58Decode(ss58, lookupIndex=0) {
let a

@@ -151,3 +167,3 @@ try {

}
let hash = blake2b(new Uint8Array([...PREFIX , ... (a[0] % 1 ? (accountId || lookupIndex(result)) : a.slice(0, 1 + length))]))
let hash = blake2b(mergeUint8Arrays(PREFIX, (a[0] % 1 ? (accountId || lookupIndex(result)) : a.slice(0, 1 + length))))

@@ -163,3 +179,1 @@ for (var i = 0; i < checksumLength; ++i) {

}
module.exports = { ss58Decode, ss58Encode };

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

const crc16xmodem = (buf, previous) => {
export const crc16xmodem = (buf, previous) => {
if (!Buffer.isBuffer(buf)) {

@@ -24,3 +24,1 @@ buf = new Buffer()

};
module.exports = { crc16xmodem };

@@ -43,16 +43,12 @@ /*!

*/
import baseCodec from 'base-x';
import { crc16xmodem } from './crc16xmodem';
var _isString = require('lodash/isString');
var _base = require('base32.js');
var _base2 = _interopRequireDefault(_base);
var { crc16xmodem } = require('./crc16xmodem');
var _isNull = require('lodash/isNull');
var _isNull2 = _interopRequireDefault(_isNull);
var _isString2 = _interopRequireDefault(_isString);
var _isUndefined = require('lodash/isUndefined');
var _isUndefined2 = _interopRequireDefault(_isUndefined);
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
const { encode, decode } = baseCodec(ALPHABET);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const isString = value => typeof value == 'string';
const isNull = value => value === null;
const isUndefined = value => value === undefined;
var versionBytes = {

@@ -65,8 +61,8 @@ ed25519PublicKey: 6 << 3, // G

const decodeCheck = (versionByteName, encoded) => {
if (!(0, _isString2.default)(encoded)) {
export const decodeCheck = (versionByteName, encoded) => {
if (!isString(encoded)) {
throw new TypeError('encoded argument must be of type String');
}
var decoded = _base2.default.decode(encoded);
var decoded = decode(encoded);
var versionByte = decoded[0];

@@ -76,6 +72,4 @@ var payload = decoded.slice(0, -2);

var checksum = decoded.slice(-2);
var _isUndefined = require('lodash/isUndefined');
var _isUndefined2 = _interopRequireDefault(_isUndefined);
if (encoded !== _base2.default.encode(decoded)) {
if (encoded !== encode(decoded)) {
throw new Error('invalid encoded string');

@@ -86,3 +80,3 @@ }

if ((0, _isUndefined2.default)(expectedVersion)) {
if (isUndefined(expectedVersion)) {
throw new Error(versionByteName + ' is not a valid version byte name. expected one of "accountId" or "seed"');

@@ -97,3 +91,3 @@ }

if (!(0, verifyChecksum)(expectedChecksum, checksum)) {
if (!verifyChecksum(expectedChecksum, checksum)) {
throw new Error('invalid checksum');

@@ -105,4 +99,4 @@ }

const encodeCheck = (versionByteName, data) => {
if ((0, _isNull2.default)(data) || (0, _isUndefined2.default)(data)) {
export const encodeCheck = (versionByteName, data) => {
if (isNull(data) || isUndefined(data)) {
throw new Error('cannot encode null data');

@@ -113,3 +107,3 @@ }

if ((0, _isUndefined2.default)(versionByte)) {
if (isUndefined(versionByte)) {
throw new Error(versionByteName + ' is not a valid version byte name. expected one of "ed25519PublicKey", "ed25519SecretSeed", "preAuthTx", "sha256Hash"');

@@ -124,6 +118,6 @@ }

return _base2.default.encode(unencoded);
return encode(unencoded);
}
const calculateChecksum = (payload) => {
export const calculateChecksum = (payload) => {
// This code calculates CRC16-XModem checksum of payload

@@ -152,3 +146,1 @@ // and returns it as Buffer in little-endian order.

};
module.exports = { calculateChecksum, decodeCheck, encodeCheck };
{
"name": "crypto-addr-codec",
"version": "0.1.5",
"version": "0.1.6",
"description": "Light weight package for serializing different crypto addresses",
"main": "./lib/index.js",
"source": "lib/index.js",
"main": "dist/index.js",
"module": "dist/index.module.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "microbundle",
"prepare": "npm run build"
},

@@ -20,14 +24,13 @@ "repository": {

"dependencies": {
"@babel/runtime": "^7.8.4",
"assert": "^2.0.0",
"base-x": "^3.0.8",
"base32.js": "^0.1.0",
"bigi": "^1.4.2",
"big-integer": "1.6.36",
"blakejs": "^1.1.0",
"bs58": "^4.0.1",
"crc": "^3.8.0",
"inherits": "latest",
"lodash": "^4.17.15",
"ripemd160-min": "0.0.6",
"safe-buffer": "^5.2.0",
"sha3": "^2.1.1"
},
"devDependencies": {
"microbundle": "^0.12.0-next.8"
}
}
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