From e94ec0091900a5537ee26688faeebf1b0134b15c Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 25 Aug 2015 13:47:11 +1000 Subject: [PATCH 1/2] types: restore quacking behaviour --- src/types.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/types.js b/src/types.js index 94731c8..9ee5c6f 100644 --- a/src/types.js +++ b/src/types.js @@ -1,5 +1,3 @@ -var bigi = require('bigi') -var ecurve = require('ecurve') var typeforce = require('typeforce') function nBuffer (value, n) { @@ -24,9 +22,9 @@ function UInt53 (value) { } // external dependent types -function BigInt (value) { return !typeforce.Null(value) && value.constructor === bigi } -function ECCurve (value) { return !typeforce.Null(value) && value.constructor === ecurve.Curve } -function ECPoint (value) { return !typeforce.Null(value) && value.constructor === ecurve.Point } +var BigInt = typeforce.quacksLike('BigInteger') +var ECCurve = typeforce.quacksLike('Curve') +var ECPoint = typeforce.quacksLike('Point') // exposed, external API var ECSignature = typeforce.compile({ r: BigInt, s: BigInt }) From 97ecb313c267e5f0458f1ed2f4be75fad606067b Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 25 Aug 2015 13:52:24 +1000 Subject: [PATCH 2/2] tests: add type tests --- test/types.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/types.js diff --git a/test/types.js b/test/types.js new file mode 100644 index 0000000..9691d53 --- /dev/null +++ b/test/types.js @@ -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 () {})) + }) + }) +})