Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: restore quacking behaviour #450

Merged
merged 2 commits into from
Aug 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var bigi = require('bigi')
var ecurve = require('ecurve')
var typeforce = require('typeforce')

function nBuffer (value, n) {
Expand All @@ -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 })
Expand Down
14 changes: 14 additions & 0 deletions test/types.js
Original file line number Diff line number Diff line change
@@ -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 () {}))
})
})
})