UNPKG

tim

Version:

Tradle's P2P OTR-based chat with plaintext and structured messages, and the ability to externalize messages onto a blockchain (currently bitcoin's)

52 lines (41 loc) 1.11 kB
const extend = require('xtend/mutable') const typeforce = require('typeforce') const constants = require('@tradle/constants') const protocol = require('@tradle/protocol') const CUR_HASH = constants.CUR_HASH const ROOT_HASH = constants.ROOT_HASH exports.hasRootHash = function (value) { return !!value[ROOT_HASH] } exports.identifier = function (value) { return value.fingerprint || value.pubKey || value[ROOT_HASH] } exports.pubKey = typeforce.compile({ fingerprint: 'String', purpose: 'String', type: 'String', value: 'String', networkName: '?String' }) exports.identity = typeforce.compile({ pubkeys: typeforce.arrayOf(exports.pubKey) }) exports.identityInfo = typeforce.compile({ [ROOT_HASH]: 'String', [CUR_HASH]: 'String', identity: exports.identity }) // exports.identifierStrict = function (value) { // return r.pubKey || r[ROOT_HASH] // } exports.ecPubKey = function (value) { return hex(value) } exports.hex = function (value) { try { return parseInt(value, 16).toString(16) === value } catch (err) { return false } } extend(exports, protocol.types)