-
Notifications
You must be signed in to change notification settings - Fork 8
/
identifier.spec.ts
45 lines (39 loc) · 1.26 KB
/
identifier.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { randomBytes } from 'crypto'
import { expect } from 'chai'
import {
Identifier,
LATEST_VERSION,
TOKEN_ID_SIZE,
ErrUnknownVersion,
decodeIdentifierFromMacaroon,
} from '../src'
import { testChallenges } from './data'
describe('Macaroon Identifier', () => {
it('should properly serialize identifier of known version', () => {
const options = {
version: LATEST_VERSION,
paymentHash: randomBytes(32),
tokenId: randomBytes(TOKEN_ID_SIZE),
}
const identifier = new Identifier(options)
const encodeId = (): Buffer => identifier.encode()
expect(encodeId).to.not.throw()
const decoded = Identifier.decode(identifier.encode())
expect(decoded).to.deep.equal(options)
})
it('should fail for unknown identifier version', () => {
const options = {
version: LATEST_VERSION + 1,
paymentHash: randomBytes(32),
tokenId: randomBytes(TOKEN_ID_SIZE),
}
const encodeId = (): Identifier => new Identifier(options)
expect(encodeId).to.throw(ErrUnknownVersion, options.version.toString())
})
it('can decode from different macaroon types', () => {
for (const { macaroon } of testChallenges) {
const id = decodeIdentifierFromMacaroon(macaroon)
Identifier.fromString(id)
}
})
})