UNPKG

jsonld-signatures

Version:

An implementation of the Linked Data Signatures specifications for JSON-LD in JavaScript.

40 lines (36 loc) 860 B
/* * Copyright (c) 2017-2021 Digital Bazaar, Inc. All rights reserved. */ 'use strict'; const api = {}; module.exports = api; /** * Converts the given date into W3C datetime format (eg: 2011-03-09T21:55:41Z). * * @param date the date to convert. * * @return the date in W3C datetime format. */ api.w3cDate = date => { if(date === undefined || date === null) { date = new Date(); } else if(typeof date === 'number' || typeof date === 'string') { date = new Date(date); } const str = date.toISOString(); return str.substr(0, str.length - 5) + 'Z'; }; /** * Concatenates two Uint8Arrays. * * @param b1 {Uint8Array}. * @param b2 {Uint8Array}. * * @return {Uint8Array} the result. */ api.concat = (b1, b2) => { const rval = new Uint8Array(b1.length + b2.length); rval.set(b1, 0); rval.set(b2, b1.length); return rval; };