2017-05-31 06:13:38 -07:00
|
|
|
var typeforce = require('typeforce')
|
|
|
|
|
|
|
|
function Buffer252bit (value) {
|
|
|
|
return typeforce.BufferN(32)(value) && (value[0] & 0x0f) === value[0]
|
|
|
|
}
|
|
|
|
|
2017-06-01 19:35:08 -07:00
|
|
|
var ZATOSHI_MAX = 21 * 1e14
|
|
|
|
function Zatoshi (value) {
|
|
|
|
return typeforce.UInt53(value) && value <= ZATOSHI_MAX
|
|
|
|
}
|
|
|
|
|
2017-05-31 06:13:38 -07:00
|
|
|
function BoolNum (value) {
|
|
|
|
return typeforce.Number(value) &&
|
|
|
|
value >= 0 &&
|
|
|
|
value <= 1
|
|
|
|
}
|
|
|
|
|
2017-05-31 06:16:33 -07:00
|
|
|
// exposed, external API
|
2017-06-01 19:35:08 -07:00
|
|
|
var Note = typeforce.compile({
|
|
|
|
a_pk: typeforce.BufferN(32),
|
|
|
|
value: Zatoshi,
|
|
|
|
rho: typeforce.BufferN(32),
|
|
|
|
r: typeforce.BufferN(32)
|
|
|
|
})
|
2017-05-31 06:16:33 -07:00
|
|
|
var PaymentAddress = typeforce.compile({
|
|
|
|
a_pk: typeforce.BufferN(32),
|
|
|
|
pk_enc: typeforce.BufferN(32)
|
|
|
|
})
|
|
|
|
var SpendingKey = typeforce.compile({
|
|
|
|
a_sk: Buffer252bit
|
|
|
|
})
|
|
|
|
|
2017-05-31 06:13:38 -07:00
|
|
|
// extend typeforce types with ours
|
|
|
|
var types = {
|
|
|
|
BoolNum: BoolNum,
|
|
|
|
Buffer252bit: Buffer252bit,
|
2017-05-31 06:16:33 -07:00
|
|
|
Buffer256bit: typeforce.BufferN(32),
|
2017-06-01 19:35:08 -07:00
|
|
|
Note: Note,
|
2017-05-31 06:16:33 -07:00
|
|
|
PaymentAddress: PaymentAddress,
|
2017-06-01 19:35:08 -07:00
|
|
|
SpendingKey: SpendingKey,
|
|
|
|
Zatoshi: Zatoshi
|
2017-05-31 06:13:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var typeName in typeforce) {
|
|
|
|
types[typeName] = typeforce[typeName]
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = types
|