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

Add types def #7

Merged
merged 5 commits into from
Mar 5, 2021
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
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
coverage/
node_modules/
scripts/*.template.js
dist/index.js
dist/*
types/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ docs/build/
/.nyc_output/
.DS_Store
package-lock.json
.vscode
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const validationResult = cc.validateFulfillment(fulfillment, condition)
const cc = require('crypto-conditions')

const myFulfillment = new cc.PreimageSha256()
myFulfillment.setPreimage(new Buffer(''))
myFulfillment.setPreimage(Buffer.from(''))
console.log(myFulfillment.getConditionUri())
// prints 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
```
Expand All @@ -100,7 +100,7 @@ console.log(myFulfillment.getConditionUri())
const cc = require('crypto-conditions')

const myFulfillment = new cc.PreimageSha256()
myFulfillment.setPreimage(new Buffer(''))
myFulfillment.setPreimage(Buffer.from(''))
console.log(myFulfillment.serializeUri())
// prints 'oAKAAA'
```
Expand All @@ -124,7 +124,7 @@ parsedFulfillment.validate()
const cc = require('crypto-conditions')

const ed25519Fulfillment = new cc.Ed25519Sha256()
ed25519Fulfillment.setPublicKey(new Buffer('ec172b93ad5e563bf4932c70e1245034c35467ef2efd4d64ebf819683467e2bf', 'hex'))
ed25519Fulfillment.setPublicKey(Buffer.from('ec172b93ad5e563bf4932c70e1245034c35467ef2efd4d64ebf819683467e2bf', 'hex'))
console.log(ed25519Fulfillment.getConditionUri())
// prints 'ni:///sha-256;U1YhFdW0lOI-SVF3PbDP4t_lVefj_-tB5P11yvfBaoE?fpt=ed25519-sha-256&cost=131072'
```
Expand All @@ -134,13 +134,13 @@ console.log(ed25519Fulfillment.getConditionUri())
``` js
const cc = require('crypto-conditions')

const edPrivateKey = new Buffer('833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42', 'hex')
const edPrivateKey = Buffer.from('833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42', 'hex')

const ed25519Fulfillment = new cc.Ed25519Sha256()
// ed25519Fulfillment.setPublicKey(new Buffer('...'))
// ed25519Fulfillment.setSignature(new Buffer('...'))
// ed25519Fulfillment.setPublicKey(Buffer.from('...'))
// ed25519Fulfillment.setSignature(Buffer.from('...'))
// -- or --
ed25519Fulfillment.sign(new Buffer('Hello World! Conditions are here!'), edPrivateKey)
ed25519Fulfillment.sign(Buffer.from('Hello World! Conditions are here!'), edPrivateKey)
console.log(ed25519Fulfillment.getConditionUri())
// prints 'ni:///sha-256;U1YhFdW0lOI-SVF3PbDP4t_lVefj_-tB5P11yvfBaoE?fpt=ed25519-sha-256&cost=131072'
console.log(ed25519Fulfillment.serializeUri())
Expand All @@ -154,7 +154,7 @@ const cc = require('crypto-conditions')

const fulfillment = 'pGSAIOwXK5OtXlY79JMscOEkUDTDVGfvLv1NZOv4GWg0Z-K_gUC2IpH62UMvjymLnEpIldvik_b_2hpo2t8Mze9fR6DHISpf6jzal6P0wD6p8uisHOyGpR1FISer26CdG28zHAcK'
const condition = 'ni:///sha-256;U1YhFdW0lOI-SVF3PbDP4t_lVefj_-tB5P11yvfBaoE?fpt=ed25519-sha-256&cost=131072'
const message = new Buffer('Hello World! Conditions are here!')
const message = Buffer.from('Hello World! Conditions are here!')

const result = cc.validateFulfillment(fulfillment, condition, message)
// result === true
Expand Down Expand Up @@ -197,7 +197,7 @@ console.log(thresholdFulfillmentUri)
const cc = require('crypto-conditions')

const prefix = new cc.PrefixSha256()
prefix.setPrefix(new Buffer('2016:'))
prefix.setPrefix(Buffer.from('2016:'))
prefix.setMaxMessageLength(65536)
prefix.setSubconditionUri('ni:///sha-256;U1YhFdW0lOI-SVF3PbDP4t_lVefj_-tB5P11yvfBaoE?fpt=ed25519-sha-256&cost=131072')
console.log(prefix.getConditionUri())
Expand All @@ -210,15 +210,15 @@ console.log(prefix.getConditionUri())
const cc = require('crypto-conditions')

const prefix = new cc.PrefixSha256()
prefix.setPrefix(new Buffer('Hello World! '))
prefix.setPrefix(Buffer.from('Hello World! '))
prefix.setMaxMessageLength(16384)
prefix.setSubfulfillmentUri('pGSAIOwXK5OtXlY79JMscOEkUDTDVGfvLv1NZOv4GWg0Z-K_gUC2IpH62UMvjymLnEpIldvik_b_2hpo2t8Mze9fR6DHISpf6jzal6P0wD6p8uisHOyGpR1FISer26CdG28zHAcK')
const fulfillmentUri = prefix.serializeUri()
console.log(fulfillmentUri)
// prints 'oXuADUhlbGxvIFdvcmxkISCBAkAAomakZIAg7Bcrk61eVjv0kyxw4SRQNMNUZ-8u_U1k6_gZaDRn4r-BQLYikfrZQy-PKYucSkiV2-KT9v_aGmja3wzN719HoMchKl_qPNqXo_TAPqny6Kwc7IalHUUhJ6vboJ0bbzMcBwo'

const conditionUri = prefix.getConditionUri()
const message = new Buffer('Conditions are here!')
const message = Buffer.from('Conditions are here!')
cc.validateFulfillment(fulfillmentUri, conditionUri, message)
```

Expand All @@ -228,7 +228,7 @@ cc.validateFulfillment(fulfillmentUri, conditionUri, message)
const cc = require('crypto-conditions')

const rsaFulfillment = new cc.RsaSha256()
rsaFulfillment.setPublicModulus(new Buffer('b30e7a938783babf836850ff49e14f87e3f92d5c46e33feca3e4f0b22358580b11765995f4b8eea7fb4712c2e1e316f7f775a953d232216a169d9a64ddc007120a400b37f2afc077b62fe304de74de6a119ec4076b529c4f6096b0baad4f533df0173b9b822fd85d65fa4befa92d8f524f69cbca0136bd80d095c169aec0e095', 'hex'))
rsaFulfillment.setPublicModulus(Buffer.from('b30e7a938783babf836850ff49e14f87e3f92d5c46e33feca3e4f0b22358580b11765995f4b8eea7fb4712c2e1e316f7f775a953d232216a169d9a64ddc007120a400b37f2afc077b62fe304de74de6a119ec4076b529c4f6096b0baad4f533df0173b9b822fd85d65fa4befa92d8f524f69cbca0136bd80d095c169aec0e095', 'hex'))
console.log(rsaFulfillment.getConditionUri())
// prints 'ni:///sha-256;j2luKLUjz-Ilu0jdDQO-Eg5Srmu06lEs4dsZHHVxcdc?fpt=rsa-sha-256&cost=16384'
```
Expand All @@ -238,7 +238,7 @@ console.log(rsaFulfillment.getConditionUri())
``` js
const cc = require('crypto-conditions')

const exampleMessage = new Buffer('Hello World! Conditions are here!')
const exampleMessage = Buffer.from('Hello World! Conditions are here!')
const privateKey =
'-----BEGIN RSA PRIVATE KEY-----\n' +
'MIICXAIBAAKBgQCzDnqTh4O6v4NoUP9J4U+H4/ktXEbjP+yj5PCyI1hYCxF2WZX0\n' +
Expand All @@ -257,8 +257,8 @@ const privateKey =
'-----END RSA PRIVATE KEY-----\n'

const rsaFulfillment = new cc.RsaSha256()
// rsaFulfillment.setPublicModulus(new Buffer('...'))
// rsaFulfillment.setSignature(new Buffer('...'))
// rsaFulfillment.setPublicModulus(Buffer.from('...'))
// rsaFulfillment.setSignature(Buffer.from('...'))
// -- or --
rsaFulfillment.sign(exampleMessage, privateKey)
console.log(rsaFulfillment.serializeUri().length)
Expand Down Expand Up @@ -305,7 +305,7 @@ const cc = require('crypto-conditions')
const myCondition = new cc.Condition()
myCondition.setTypeId(cc.PreimageSha256.TYPE_ID)
myCondition.setSubtypes(new Set('preimage-sha-256'))
myCondition.setHash(new Buffer('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'hex'))
myCondition.setHash(Buffer.from('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'hex'))
myCondition.setCost(0)
console.log(myCondition.serializeUri())
// prints 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
Expand Down
32 changes: 16 additions & 16 deletions docs/README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const validationResult = cc.validateFulfillment(fulfillment, condition)
const cc = require('five-bells-condition')

const myFulfillment = new cc.PreimageSha256()
myFulfillment.setPreimage(new Buffer(''))
myFulfillment.setPreimage(Buffer.from(''))
console.log(myFulfillment.getConditionUri())
// prints 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
```
Expand All @@ -85,7 +85,7 @@ console.log(myFulfillment.getConditionUri())
const cc = require('five-bells-condition')

const myFulfillment = new cc.PreimageSha256()
myFulfillment.setPreimage(new Buffer(''))
myFulfillment.setPreimage(Buffer.from(''))
console.log(myFulfillment.serializeUri())
// prints 'oAKAAA'
```
Expand All @@ -109,7 +109,7 @@ parsedFulfillment.validate()
const cc = require('five-bells-condition')

const ed25519Fulfillment = new cc.Ed25519Sha256()
ed25519Fulfillment.setPublicKey(new Buffer('ec172b93ad5e563bf4932c70e1245034c35467ef2efd4d64ebf819683467e2bf', 'hex'))
ed25519Fulfillment.setPublicKey(Buffer.from('ec172b93ad5e563bf4932c70e1245034c35467ef2efd4d64ebf819683467e2bf', 'hex'))
console.log(ed25519Fulfillment.getConditionUri())
// prints 'ni:///sha-256;U1YhFdW0lOI-SVF3PbDP4t_lVefj_-tB5P11yvfBaoE?fpt=ed25519-sha-256&cost=131072'
```
Expand All @@ -119,13 +119,13 @@ console.log(ed25519Fulfillment.getConditionUri())
``` js
const cc = require('five-bells-condition')

const edPrivateKey = new Buffer('833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42', 'hex')
const edPrivateKey = Buffer.from('833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42', 'hex')

const ed25519Fulfillment = new cc.Ed25519Sha256()
// ed25519Fulfillment.setPublicKey(new Buffer('...'))
// ed25519Fulfillment.setSignature(new Buffer('...'))
// ed25519Fulfillment.setPublicKey(Buffer.from('...'))
// ed25519Fulfillment.setSignature(Buffer.from('...'))
// -- or --
ed25519Fulfillment.sign(new Buffer('Hello World! Conditions are here!'), edPrivateKey)
ed25519Fulfillment.sign(Buffer.from('Hello World! Conditions are here!'), edPrivateKey)
console.log(ed25519Fulfillment.getConditionUri())
// prints 'ni:///sha-256;U1YhFdW0lOI-SVF3PbDP4t_lVefj_-tB5P11yvfBaoE?fpt=ed25519-sha-256&cost=131072'
console.log(ed25519Fulfillment.serializeUri())
Expand All @@ -139,7 +139,7 @@ const cc = require('five-bells-condition')

const fulfillment = 'pGSAIOwXK5OtXlY79JMscOEkUDTDVGfvLv1NZOv4GWg0Z-K_gUC2IpH62UMvjymLnEpIldvik_b_2hpo2t8Mze9fR6DHISpf6jzal6P0wD6p8uisHOyGpR1FISer26CdG28zHAcK'
const condition = 'ni:///sha-256;U1YhFdW0lOI-SVF3PbDP4t_lVefj_-tB5P11yvfBaoE?fpt=ed25519-sha-256&cost=131072'
const message = new Buffer('Hello World! Conditions are here!')
const message = Buffer.from('Hello World! Conditions are here!')

const result = cc.validateFulfillment(fulfillment, condition, message)
// result === true
Expand Down Expand Up @@ -182,7 +182,7 @@ console.log(thresholdFulfillmentUri)
const cc = require('five-bells-condition')

const prefix = new cc.PrefixSha256()
prefix.setPrefix(new Buffer('2016:'))
prefix.setPrefix(Buffer.from('2016:'))
prefix.setMaxMessageLength(65536)
prefix.setSubconditionUri('ni:///sha-256;U1YhFdW0lOI-SVF3PbDP4t_lVefj_-tB5P11yvfBaoE?fpt=ed25519-sha-256&cost=131072')
console.log(prefix.getConditionUri())
Expand All @@ -195,15 +195,15 @@ console.log(prefix.getConditionUri())
const cc = require('five-bells-condition')

const prefix = new cc.PrefixSha256()
prefix.setPrefix(new Buffer('Hello World! '))
prefix.setPrefix(Buffer.from('Hello World! '))
prefix.setMaxMessageLength(16384)
prefix.setSubfulfillmentUri('pGSAIOwXK5OtXlY79JMscOEkUDTDVGfvLv1NZOv4GWg0Z-K_gUC2IpH62UMvjymLnEpIldvik_b_2hpo2t8Mze9fR6DHISpf6jzal6P0wD6p8uisHOyGpR1FISer26CdG28zHAcK')
const fulfillmentUri = prefix.serializeUri()
console.log(fulfillmentUri)
// prints 'oXuADUhlbGxvIFdvcmxkISCBAkAAomakZIAg7Bcrk61eVjv0kyxw4SRQNMNUZ-8u_U1k6_gZaDRn4r-BQLYikfrZQy-PKYucSkiV2-KT9v_aGmja3wzN719HoMchKl_qPNqXo_TAPqny6Kwc7IalHUUhJ6vboJ0bbzMcBwo'

const conditionUri = prefix.getConditionUri()
const message = new Buffer('Conditions are here!')
const message = Buffer.from('Conditions are here!')
cc.validateFulfillment(fulfillmentUri, conditionUri, message)
```

Expand All @@ -213,7 +213,7 @@ cc.validateFulfillment(fulfillmentUri, conditionUri, message)
const cc = require('five-bells-condition')

const rsaFulfillment = new cc.RsaSha256()
rsaFulfillment.setPublicModulus(new Buffer('b30e7a938783babf836850ff49e14f87e3f92d5c46e33feca3e4f0b22358580b11765995f4b8eea7fb4712c2e1e316f7f775a953d232216a169d9a64ddc007120a400b37f2afc077b62fe304de74de6a119ec4076b529c4f6096b0baad4f533df0173b9b822fd85d65fa4befa92d8f524f69cbca0136bd80d095c169aec0e095', 'hex'))
rsaFulfillment.setPublicModulus(Buffer.from('b30e7a938783babf836850ff49e14f87e3f92d5c46e33feca3e4f0b22358580b11765995f4b8eea7fb4712c2e1e316f7f775a953d232216a169d9a64ddc007120a400b37f2afc077b62fe304de74de6a119ec4076b529c4f6096b0baad4f533df0173b9b822fd85d65fa4befa92d8f524f69cbca0136bd80d095c169aec0e095', 'hex'))
console.log(rsaFulfillment.getConditionUri())
// prints 'ni:///sha-256;j2luKLUjz-Ilu0jdDQO-Eg5Srmu06lEs4dsZHHVxcdc?fpt=rsa-sha-256&cost=16384'
```
Expand All @@ -223,7 +223,7 @@ console.log(rsaFulfillment.getConditionUri())
``` js
const cc = require('five-bells-condition')

const exampleMessage = new Buffer('Hello World! Conditions are here!')
const exampleMessage = Buffer.from('Hello World! Conditions are here!')
const privateKey =
'-----BEGIN RSA PRIVATE KEY-----\n' +
'MIICXAIBAAKBgQCzDnqTh4O6v4NoUP9J4U+H4/ktXEbjP+yj5PCyI1hYCxF2WZX0\n' +
Expand All @@ -242,8 +242,8 @@ const privateKey =
'-----END RSA PRIVATE KEY-----\n'

const rsaFulfillment = new cc.RsaSha256()
// rsaFulfillment.setPublicModulus(new Buffer('...'))
// rsaFulfillment.setSignature(new Buffer('...'))
// rsaFulfillment.setPublicModulus(Buffer.from('...'))
// rsaFulfillment.setSignature(Buffer.from('...'))
// -- or --
rsaFulfillment.sign(exampleMessage, privateKey)
console.log(rsaFulfillment.serializeUri().length)
Expand Down Expand Up @@ -290,7 +290,7 @@ const cc = require('five-bells-condition')
const myCondition = new cc.Condition()
myCondition.setTypeId(cc.PreimageSha256.TYPE_ID)
myCondition.setSubtypes(new Set('preimage-sha-256'))
myCondition.setHash(new Buffer('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'hex'))
myCondition.setHash(Buffer.from('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'hex'))
myCondition.setCost(0)
console.log(myCondition.serializeUri())
// prints 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Implementation of crypto-conditions in JavaScript",
"main": "index.js",
"browser": "./dist/index.js",
"types": "./types/index.d.ts",
"directories": {
"test": "test"
},
Expand Down
20 changes: 10 additions & 10 deletions test/conditionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,45 +119,45 @@ describe('Condition', function () {
// })
//
// it('should throw when given a Buffer', function () {
// assert.throws(() => Condition.fromUri(new Buffer('cc:0:3:47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU:0', 'utf8')),
// assert.throws(() => Condition.fromUri(Buffer.from('cc:0:3:47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU:0', 'utf8')),
// 'Serialized condition must be a string')
// })
// })
//
// describe('fromBinary', function () {
// it('successfully parses the minimal condition', function () {
// const condition = Condition.fromBinary(new Buffer('0000010320e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550102', 'hex'))
// const condition = Condition.fromBinary(Buffer.from('0000010320e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550102', 'hex'))
//
// assert.instanceOf(condition, Condition)
// assert.equal(condition.getHash().toString('hex'), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
// })
//
// it('rejects a condition with less than two bytes', function () {
// assert.throws(() => Condition.fromBinary(new Buffer('00', 'hex')))
// assert.throws(() => Condition.fromBinary(Buffer.from('00', 'hex')))
// })
//
// it('rejects a condition containing no fingerprint', function () {
// assert.throws(() => Condition.fromBinary(new Buffer('0000', 'hex')))
// assert.throws(() => Condition.fromBinary(Buffer.from('0000', 'hex')))
// })
//
// it.skip('rejects a condition containing extra bytes', function () {
// assert.throws(() => Condition.fromBinary(new Buffer('000000010000', 'hex')))
// assert.throws(() => Condition.fromBinary(Buffer.from('000000010000', 'hex')))
// })
//
// it('rejects a condition with non-canonical zero byte length prefix', function () {
// assert.throws(() => Condition.fromBinary(new Buffer('000080', 'hex')), 'Length prefix encoding is not canonical')
// assert.throws(() => Condition.fromBinary(Buffer.from('000080', 'hex')), 'Length prefix encoding is not canonical')
// })
//
// it('rejects a condition with non-canonical single byte length prefix', function () {
// assert.throws(() => Condition.fromBinary(new Buffer('0000810100', 'hex')), 'Length prefix encoding is not canonical')
// assert.throws(() => Condition.fromBinary(Buffer.from('0000810100', 'hex')), 'Length prefix encoding is not canonical')
// })
//
// it('rejects a condition with non-canonical two byte length prefix', function () {
// assert.throws(() => Condition.fromBinary(new Buffer('000082000100', 'hex')), 'Length prefix encoding is not canonical')
// assert.throws(() => Condition.fromBinary(Buffer.from('000082000100', 'hex')), 'Length prefix encoding is not canonical')
// })
//
// it('rejects a condition with too large of a length prefix', function () {
// assert.throws(() => Condition.fromBinary(new Buffer('00008700000000000000', 'hex')), 'Tried to read too large integer (requested: 7, max: 6)')
// assert.throws(() => Condition.fromBinary(Buffer.from('00008700000000000000', 'hex')), 'Tried to read too large integer (requested: 7, max: 6)')
// })
// })
//
Expand All @@ -179,7 +179,7 @@ describe('Condition', function () {
//
// describe('setHash', function () {
// it('should set the hash', function () {
// const hash = new Buffer('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'hex')
// const hash = Buffer.from('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'hex')
// const condition = new Condition()
//
// condition.setHash(hash)
Expand Down
14 changes: 7 additions & 7 deletions test/fulfillmentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,31 @@ describe('Fulfillment', function () {
})

// it('rejects a fulfillment with less than two bytes', function () {
// assert.throws(() => Fulfillment.fromBinary(new Buffer('00', 'hex')))
// assert.throws(() => Fulfillment.fromBinary(Buffer.from('00', 'hex')))
// })
//
// it('rejects a fulfillment containing no payload', function () {
// assert.throws(() => Fulfillment.fromBinary(new Buffer('0000', 'hex')))
// assert.throws(() => Fulfillment.fromBinary(Buffer.from('0000', 'hex')))
// })
//
// it.skip('rejects a fulfillment containing extra bytes', function () {
// assert.throws(() => Fulfillment.fromBinary(new Buffer('00000000', 'hex')))
// assert.throws(() => Fulfillment.fromBinary(Buffer.from('00000000', 'hex')))
// })
//
// it('rejects a fulfillment with non-canonical zero byte length prefix', function () {
// assert.throws(() => Fulfillment.fromBinary(new Buffer('000080', 'hex')), 'Length prefix encoding is not canonical')
// assert.throws(() => Fulfillment.fromBinary(Buffer.from('000080', 'hex')), 'Length prefix encoding is not canonical')
// })
//
// it('rejects a fulfillment with non-canonical single byte length prefix', function () {
// assert.throws(() => Fulfillment.fromBinary(new Buffer('0000810100', 'hex')), 'Length prefix encoding is not canonical')
// assert.throws(() => Fulfillment.fromBinary(Buffer.from('0000810100', 'hex')), 'Length prefix encoding is not canonical')
// })
//
// it('rejects a fulfillment with non-canonical two byte length prefix', function () {
// assert.throws(() => Fulfillment.fromBinary(new Buffer('000082000100', 'hex')), 'Length prefix encoding is not canonical')
// assert.throws(() => Fulfillment.fromBinary(Buffer.from('000082000100', 'hex')), 'Length prefix encoding is not canonical')
// })
//
// it('rejects a fulfillment with too large of a length prefix', function () {
// assert.throws(() => Fulfillment.fromBinary(new Buffer('00008700000000000000', 'hex')), 'Tried to read too large integer (requested: 7, max: 6)')
// assert.throws(() => Fulfillment.fromBinary(Buffer.from('00008700000000000000', 'hex')), 'Tried to read too large integer (requested: 7, max: 6)')
// })
})

Expand Down
9 changes: 9 additions & 0 deletions types/crypto/mgf1.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type Mgf1Options = {
hashAlgorithm?: string;
};

export default class Mgf1 {
constructor(opts?: Mgf1Options);

generate(seed: Buffer, maskLength: number): Buffer;
}
17 changes: 17 additions & 0 deletions types/crypto/pss.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export type PssOptions = {
hashAlgorithm?: string;
};

export default class Pss {
static EMPTY_BUFFER: Buffer;

constructor(opts?: PssOptions);

encode(message: Buffer, encodedMessageBits: number): Buffer;

verify(
message: Buffer,
encodedMessage: Buffer,
encodedMessageBits: number
): boolean;
}
Loading