ripple-account-family
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -9,6 +9,6 @@ "use strict"; | ||
}; | ||
var publicKeyToAddress = function (version, data) { | ||
var publicKeyToAddress = function (version, publieKey) { | ||
var payload = Buffer.allocUnsafe(20 + 1); | ||
payload.writeUInt8(version, 0); | ||
var hash = hash_1.hash160(data); | ||
var hash = hash_1.hash160(publieKey); | ||
hash.copy(payload, 1); | ||
@@ -15,0 +15,0 @@ return bs58check.encode(payload); |
export declare class ColdWallet { | ||
private publicGenerator; | ||
constructor(publicGeneratorHex: string); | ||
getAddress(accountIndex: number): string; | ||
getAddress(accountIndex?: number): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var addressCodec = require("ripple-address-codec"); | ||
var accountfamily_1 = require("../accountfamily"); | ||
var hash_1 = require("../crypto/hash"); | ||
var publicKeyToAddress = function (publicKey) { | ||
return addressCodec.encodeAccountID(hash_1.hash160(publicKey)); | ||
}; | ||
var address_1 = require("../misc/address"); | ||
var ColdWallet = /** @class */ (function () { | ||
@@ -14,3 +10,4 @@ function ColdWallet(publicGeneratorHex) { | ||
ColdWallet.prototype.getAddress = function (accountIndex) { | ||
return publicKeyToAddress(accountfamily_1.derivePublicKey(this.publicGenerator, accountIndex)); | ||
if (accountIndex === void 0) { accountIndex = 0; } | ||
return address_1.encodeAddress(accountfamily_1.derivePublicKey(this.publicGenerator, accountIndex)); | ||
}; | ||
@@ -17,0 +14,0 @@ return ColdWallet; |
@@ -5,4 +5,4 @@ import { Wallet } from './wallet'; | ||
constructor(seed: string); | ||
derive(accountIndex: number): Wallet; | ||
derive(accountIndex?: number): Wallet; | ||
getPublicGenerator(): string; | ||
} |
@@ -12,2 +12,3 @@ "use strict"; | ||
RootWallet.prototype.derive = function (accountIndex) { | ||
if (accountIndex === void 0) { accountIndex = 0; } | ||
return new wallet_1.Wallet(accountfamily_1.derivePrivateKey(this.privateGenerator, accountIndex), accountIndex); | ||
@@ -14,0 +15,0 @@ }; |
@@ -16,5 +16,22 @@ "use strict"; | ||
describe('test', function () { | ||
var _this = this; | ||
it('misc encode address', function () { | ||
var entropy = Buffer.from('b03a909b81eb1e10db1a2198442109d8', 'hex'); | ||
var seed = keypair.generateSeed({ entropy: entropy }); | ||
var key = keypair.deriveKeypair(seed); | ||
var ans = keypair.deriveAddress(key.publicKey); | ||
var res = address_1.encodeAddress(Buffer.from(key.publicKey, 'hex')); | ||
assert.equal(ans, res); | ||
}); | ||
it('misc decode address', function () { | ||
var entropy = Buffer.from('b03a909b81eb1e10db1a2198442109d8', 'hex'); | ||
var seed = keypair.generateSeed({ entropy: entropy }); | ||
var key = keypair.deriveKeypair(seed); | ||
var address = keypair.deriveAddress(key.publicKey); | ||
var res = address_1.decodeAddress(address); | ||
assert.equal(res.type, 'p2pkh'); | ||
assert.equal(res.version, 0x00); | ||
}); | ||
it('misc decode secret', function () { | ||
var entropy = Buffer.from('b03a909b81eb1e10db1a2198442109d8', 'hex'); | ||
var seed = keypair.generateSeed(entropy); | ||
var seed = keypair.generateSeed(); | ||
var ans = codec.decodeSeed(seed); | ||
@@ -44,3 +61,3 @@ var res = address_1.decodeSecret(seed); | ||
it('offical compatible test 2', function () { | ||
this.timeout(15000); | ||
_this.timeout(15000); | ||
var seed = keypair.generateSeed(); | ||
@@ -51,10 +68,16 @@ var rw = new __1.RootWallet(seed); | ||
var address = keypair.deriveAddress(key.publicKey); | ||
var info = rw.derive(i).getInfo(); | ||
var wallet = rw.derive(i); | ||
var info = wallet.getInfo(); | ||
assert.equal(address, info.address, [i, seed].join()); | ||
assert.equal(key.publicKey, info.publickey, [i, seed].join()); | ||
assert.equal(key.privateKey, info.privatekey, [i, seed].join()); | ||
var pair = wallet.getKeyPair(); | ||
assert.equal(wallet.getAddress(), address); | ||
assert.equal(wallet.getAccountIndex(), i); | ||
assert.equal(pair.publicKey, key.publicKey); | ||
assert.equal(pair.privateKey, key.privateKey); | ||
} | ||
}); | ||
it('publicGenerator test', function () { | ||
this.timeout(15000); | ||
_this.timeout(15000); | ||
var rw = new __1.RootWallet(keypair.generateSeed()); | ||
@@ -61,0 +84,0 @@ var cw = new __1.ColdWallet(rw.getPublicGenerator()); |
{ | ||
"name": "ripple-account-family", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "ripple account family", | ||
@@ -27,6 +27,6 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"bn.js": "^5.0.0", | ||
"create-hash": "^1.1.3", | ||
"elliptic": "^6.5.0", | ||
"ripple-bs58check": "^2.0.2" | ||
"bn.js": "5.0.0", | ||
"create-hash": "1.1.3", | ||
"elliptic": "6.5.0", | ||
"ripple-bs58check": "2.0.2" | ||
}, | ||
@@ -42,3 +42,3 @@ "devDependencies": { | ||
"mocha": "^5.0.5", | ||
"ripple-keypairs": "", | ||
"ripple-keypairs": "0.11.0", | ||
"ripple-address-codec": "2.0.1", | ||
@@ -45,0 +45,0 @@ "typescript": "^3.0.0" |
@@ -39,11 +39,16 @@ # node-ripple-account-family | ||
## transaction sign ? | ||
## transaction sign | ||
see https://github.com/you21979/node-ripple-sign-keypairs/ | ||
``` | ||
const RippleApi = require('ripple-lib').RippleAPI | ||
const api = new RippleApi(); | ||
const options = { signAs: '' }; | ||
const txJSON = 'preparePayment output...' | ||
## original library | ||
const seed = "ss7vwFuNi2Zud1ekn68LivP2P7UF1" | ||
const rw = new RootWallet(seed) | ||
const keypair = rw.derive(0).getKeyPair() | ||
const signedTx = api.sign(txJSON, void 0, options, keypair) | ||
console.log(signedTx) | ||
``` | ||
this library base on ripple-keypairs | ||
* https://github.com/ripple/ripple-keypairs | ||
@@ -17,6 +17,6 @@ import { hash160 } from '../crypto/hash' | ||
const publicKeyToAddress = (version: number, data: Buffer): string => { | ||
const publicKeyToAddress = (version: number, publieKey: Buffer): string => { | ||
const payload = Buffer.allocUnsafe(20 + 1) | ||
payload.writeUInt8(version, 0) | ||
const hash = hash160(data) | ||
const hash = hash160(publieKey) | ||
hash.copy(payload, 1) | ||
@@ -23,0 +23,0 @@ return bs58check.encode(payload) |
@@ -1,9 +0,4 @@ | ||
const addressCodec = require("ripple-address-codec") | ||
import { derivePublicKey } from "../accountfamily" | ||
import { hash160 } from '../crypto/hash' | ||
import { encodeAddress } from '../misc/address' | ||
const publicKeyToAddress = function(publicKey: Buffer): string{ | ||
return addressCodec.encodeAccountID(hash160(publicKey)) | ||
} | ||
export class ColdWallet{ | ||
@@ -14,6 +9,6 @@ private publicGenerator: Buffer | ||
} | ||
getAddress(accountIndex: number): string{ | ||
return publicKeyToAddress(derivePublicKey(this.publicGenerator, accountIndex)) | ||
getAddress(accountIndex: number = 0): string{ | ||
return encodeAddress(derivePublicKey(this.publicGenerator, accountIndex)) | ||
} | ||
} | ||
@@ -11,3 +11,3 @@ import { decodeSecret } from '../misc/address' | ||
} | ||
derive(accountIndex: number): Wallet{ | ||
derive(accountIndex: number = 0): Wallet{ | ||
return new Wallet(derivePrivateKey(this.privateGenerator, accountIndex), accountIndex) | ||
@@ -14,0 +14,0 @@ } |
import * as assert from 'assert' | ||
import { RootWallet, ColdWallet } from '..' | ||
import { decodeSecret, encodeSecret } from '../lib/misc/address' | ||
import { decodeAddress, encodeAddress, decodeSecret, encodeSecret } from '../lib/misc/address' | ||
const keypair = require('ripple-keypairs') | ||
@@ -9,5 +9,23 @@ const codec = require('ripple-address-codec') | ||
it('misc encode address', ()=>{ | ||
const entropy = Buffer.from('b03a909b81eb1e10db1a2198442109d8', 'hex') | ||
const seed: string = keypair.generateSeed({ entropy }) | ||
const key = keypair.deriveKeypair(seed) | ||
const ans = keypair.deriveAddress(key.publicKey) | ||
const res = encodeAddress(Buffer.from(key.publicKey, 'hex')) | ||
assert.equal(ans, res) | ||
}) | ||
it('misc decode address', ()=>{ | ||
const entropy = Buffer.from('b03a909b81eb1e10db1a2198442109d8', 'hex') | ||
const seed: string = keypair.generateSeed({ entropy }) | ||
const key = keypair.deriveKeypair(seed) | ||
const address = keypair.deriveAddress(key.publicKey) | ||
const res = decodeAddress(address) | ||
assert.equal(res.type, 'p2pkh') | ||
assert.equal(res.version, 0x00) | ||
}) | ||
it('misc decode secret', () => { | ||
const entropy = Buffer.from('b03a909b81eb1e10db1a2198442109d8', 'hex') | ||
const seed: string = keypair.generateSeed(entropy) | ||
const seed: string = keypair.generateSeed() | ||
const ans = codec.decodeSeed(seed) | ||
@@ -28,3 +46,3 @@ const res = decodeSecret(seed) | ||
it('offical compatible test 1', function () { | ||
it('offical compatible test 1', () => { | ||
const seed = keypair.generateSeed() | ||
@@ -39,3 +57,3 @@ const key = keypair.deriveKeypair(seed) | ||
}) | ||
it('offical compatible test 2', function () { | ||
it('offical compatible test 2', () => { | ||
this.timeout(15000) | ||
@@ -47,9 +65,16 @@ const seed = keypair.generateSeed() | ||
const address = keypair.deriveAddress(key.publicKey) | ||
const info = rw.derive(i).getInfo() | ||
const wallet = rw.derive(i) | ||
const info = wallet.getInfo() | ||
assert.equal(address, info.address, [i,seed].join()) | ||
assert.equal(key.publicKey, info.publickey, [i,seed].join()) | ||
assert.equal(key.privateKey, info.privatekey, [i,seed].join()) | ||
const pair = wallet.getKeyPair() | ||
assert.equal(wallet.getAddress(), address) | ||
assert.equal(wallet.getAccountIndex(), i) | ||
assert.equal(pair.publicKey, key.publicKey) | ||
assert.equal(pair.privateKey, key.privateKey) | ||
} | ||
}) | ||
it('publicGenerator test', function () { | ||
it('publicGenerator test', () => { | ||
this.timeout(15000) | ||
@@ -56,0 +81,0 @@ const rw = new RootWallet(keypair.generateSeed()) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
31619
748
54
0
+ Addedbn.js@5.0.0(transitive)
+ Addedcreate-hash@1.1.3(transitive)
+ Addedelliptic@6.5.0(transitive)
- Removedbn.js@5.2.1(transitive)
- Removedcreate-hash@1.2.0(transitive)
- Removedelliptic@6.6.1(transitive)
- Removedmd5.js@1.3.5(transitive)
Updatedbn.js@5.0.0
Updatedcreate-hash@1.1.3
Updatedelliptic@6.5.0
Updatedripple-bs58check@2.0.2