Merge pull request #450 from bitcoinjs/duckback
types: restore quacking behaviour
This commit is contained in:
commit
b66636ed5e
2 changed files with 17 additions and 5 deletions
|
@ -1,5 +1,3 @@
|
||||||
var bigi = require('bigi')
|
|
||||||
var ecurve = require('ecurve')
|
|
||||||
var typeforce = require('typeforce')
|
var typeforce = require('typeforce')
|
||||||
|
|
||||||
function nBuffer (value, n) {
|
function nBuffer (value, n) {
|
||||||
|
@ -24,9 +22,9 @@ function UInt53 (value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// external dependent types
|
// external dependent types
|
||||||
function BigInt (value) { return !typeforce.Null(value) && value.constructor === bigi }
|
var BigInt = typeforce.quacksLike('BigInteger')
|
||||||
function ECCurve (value) { return !typeforce.Null(value) && value.constructor === ecurve.Curve }
|
var ECCurve = typeforce.quacksLike('Curve')
|
||||||
function ECPoint (value) { return !typeforce.Null(value) && value.constructor === ecurve.Point }
|
var ECPoint = typeforce.quacksLike('Point')
|
||||||
|
|
||||||
// exposed, external API
|
// exposed, external API
|
||||||
var ECSignature = typeforce.compile({ r: BigInt, s: BigInt })
|
var ECSignature = typeforce.compile({ r: BigInt, s: BigInt })
|
||||||
|
|
14
test/types.js
Normal file
14
test/types.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/* global describe, it */
|
||||||
|
|
||||||
|
var assert = require('assert')
|
||||||
|
var types = require('../src/types')
|
||||||
|
|
||||||
|
describe('types', function () {
|
||||||
|
describe('ECCurve/ECPoint/BigInt', function () {
|
||||||
|
it('return true for duck types', function () {
|
||||||
|
assert(types.quacksLike('BigInteger', function BigInteger () {}))
|
||||||
|
assert(types.quacksLike('Curve', function Curve () {}))
|
||||||
|
assert(types.quacksLike('Point', function Point () {}))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Add table
Reference in a new issue