@transmute/cose
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -49,2 +49,10 @@ "use strict"; | ||
} | ||
case -13: { | ||
lines.push((0, addComment_1.addComment)(`${indentSpaces}${key}: ${(0, bufferToTruncatedBstr_1.bufferToTruncatedBstr)(value)},`, 'Post quantum private key')); | ||
break; | ||
} | ||
case -14: { | ||
lines.push((0, addComment_1.addComment)(`${indentSpaces}${key}: ${(0, bufferToTruncatedBstr_1.bufferToTruncatedBstr)(value)},`, 'Post quantum public key')); | ||
break; | ||
} | ||
default: { | ||
@@ -51,0 +59,0 @@ throw new Error('Unsupported cose key value: ' + key); |
/// <reference types="node" /> | ||
export declare const beautifyProtectedHeader: (data: Buffer | Uint8Array) => Promise<any>; | ||
export declare const beautifyProtectedHeader: (data: Buffer | Uint8Array) => Promise<string>; |
@@ -18,36 +18,48 @@ "use strict"; | ||
const cbor_1 = __importDefault(require("../../cbor")); | ||
const constants_1 = require("./constants"); | ||
// https://www.iana.org/assignments/cose/cose.xhtml | ||
const protectedHeaderTagToDescription = (tag) => { | ||
const descriptions = new Map(); | ||
descriptions.set(1, 'Algorithm'); | ||
descriptions.set(2, 'Critical parameters'); | ||
descriptions.set(3, 'Content type'); | ||
descriptions.set(4, 'Key identifier'); | ||
descriptions.set(-11111, 'Verifiable data structure'); | ||
return descriptions.get(tag) || `${tag} unknown cbor content`; | ||
}; | ||
const bufferToTruncatedBstr_1 = require("./bufferToTruncatedBstr"); | ||
const unprotectedHeader_1 = __importDefault(require("../../unprotectedHeader")); | ||
const beautifyProtectedHeader = (data) => __awaiter(void 0, void 0, void 0, function* () { | ||
const diagnostic = yield cbor_1.default.web.diagnose(data); | ||
const mapItemSpacer = ` `; | ||
let result = diagnostic; | ||
result = result.replace('{', `{\n${mapItemSpacer}`); | ||
result = result.replace(/, /g, `,\n${mapItemSpacer}`); | ||
result = result.replace('}', `\n}`); | ||
result = result.split('\n').map((line) => { | ||
if (line.trim() === '{') { | ||
line = (0, addComment_1.addComment)(`{`, `Protected`); | ||
return line; | ||
const protectedHeader = yield cbor_1.default.web.decode(data); | ||
const lines = []; | ||
for (const [label, value] of protectedHeader.entries()) { | ||
if (label === 1) { | ||
lines.push((0, addComment_1.addComment)(` ${label}: ${value},`, 'Algorithm')); | ||
} | ||
if (line.includes(`h'`) && line.length > constants_1.maxBstrTruncateLength) { | ||
line = line.replace(/h'(.{8}).+(.{8})'/g, `h'$1...$2'`); | ||
else if (label === 2) { | ||
lines.push((0, addComment_1.addComment)(` ${label}: ${value},`, 'Criticality')); | ||
} | ||
if (line === '' || line.trim() === '{' || line.trim() === '}') { | ||
return line; | ||
else if (label === 3) { | ||
lines.push((0, addComment_1.addComment)(` ${label}: ${value},`, 'Content type')); | ||
} | ||
const maybeIntLabel = parseInt(line.split(':')[0], 10); | ||
return (0, addComment_1.addComment)(line, `${protectedHeaderTagToDescription(maybeIntLabel)}`); | ||
}).join('\n'); | ||
return result; | ||
else if (label === 4) { | ||
lines.push((0, addComment_1.addComment)(` ${label}: ${(0, bufferToTruncatedBstr_1.bufferToTruncatedBstr)(value)},`, 'Key identifier')); | ||
} | ||
else if (label === 13) { | ||
lines.push((0, addComment_1.addComment)(` ${label}: {`, 'CWT Claims')); | ||
for (const [claimKey, claimValue] of value.entries()) { | ||
if (claimKey === 1) { | ||
lines.push((0, addComment_1.addComment)(` ${claimKey}: ${claimValue},`, 'Issuer')); | ||
} | ||
else if (claimKey === 2) { | ||
lines.push((0, addComment_1.addComment)(` ${claimKey}: ${claimValue},`, 'Subject')); | ||
} | ||
else { | ||
lines.push((0, addComment_1.addComment)(` ${claimKey}: ${claimValue},`, 'Claim')); | ||
} | ||
} | ||
lines.push(` }`); | ||
} | ||
else if (label === unprotectedHeader_1.default.verifiable_data_structure) { | ||
lines.push((0, addComment_1.addComment)(` ${label}: ${value},`, 'Verifiable Data Structure')); | ||
} | ||
else { | ||
lines.push((0, addComment_1.addComment)(` ${label}: ${value},`, 'Parameter')); | ||
} | ||
} | ||
return ` | ||
${(0, addComment_1.addComment)('{', 'Protected')} | ||
${lines.join('\n')} | ||
} | ||
`.trim(); | ||
}); | ||
exports.beautifyProtectedHeader = beautifyProtectedHeader; |
@@ -11,2 +11,5 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,5 +20,6 @@ exports.beautifyReceipts = void 0; | ||
const beautifyCoseSign1_1 = require("./beautifyCoseSign1"); | ||
const unprotectedHeader_1 = __importDefault(require("../../unprotectedHeader")); | ||
const beautifyReceipts = (receipts) => __awaiter(void 0, void 0, void 0, function* () { | ||
const blocks = [ | ||
`${(0, addComment_1.addComment)(` 300: [`, `Receipts (${receipts.length})`)} | ||
`${(0, addComment_1.addComment)(` ${unprotectedHeader_1.default.scitt_receipt}: [`, `Receipts (${receipts.length})`)} | ||
${receipts.map((receipt, i) => { | ||
@@ -22,0 +26,0 @@ const truncated = (0, bufferToTruncatedBstr_1.bufferToTruncatedBstr)(receipt); |
@@ -0,2 +1,3 @@ | ||
import * as statement from './statement'; | ||
import * as receipt from './receipt'; | ||
export { receipt }; | ||
export { statement, receipt }; |
@@ -26,4 +26,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.receipt = void 0; | ||
exports.receipt = exports.statement = void 0; | ||
const statement = __importStar(require("./statement")); | ||
exports.statement = statement; | ||
const receipt = __importStar(require("./receipt")); | ||
exports.receipt = receipt; |
import { SecretCoseKeyMap } from '../../key/types'; | ||
export type RequestScittReceipt = { | ||
iss: string; | ||
sub: string; | ||
index: number; | ||
@@ -9,2 +11,2 @@ entries?: ArrayBuffer[]; | ||
}; | ||
export declare const issue: ({ index, entries, leaves, signer, secretCoseKey }: RequestScittReceipt) => Promise<ArrayBuffer>; | ||
export declare const issue: ({ iss, sub, index, entries, leaves, signer, secretCoseKey }: RequestScittReceipt) => Promise<ArrayBuffer>; |
@@ -48,3 +48,3 @@ "use strict"; | ||
const signer_1 = __importDefault(require("../../lib/signer")); | ||
const issue = ({ index, entries, leaves, signer, secretCoseKey }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const issue = ({ iss, sub, index, entries, leaves, signer, secretCoseKey }) => __awaiter(void 0, void 0, void 0, function* () { | ||
let treeLeaves = leaves; | ||
@@ -63,2 +63,5 @@ if (entries) { | ||
const protectedHeaderMap = new Map(); | ||
const cwtClaimsMap = new Map(); | ||
cwtClaimsMap.set(1, iss); | ||
cwtClaimsMap.set(2, sub); | ||
if (secretCoseKey) { | ||
@@ -70,2 +73,3 @@ const secretKeyJwk = yield key.exportJWK(secretCoseKey); | ||
protectedHeaderMap.set(unprotectedHeader_1.default.verifiable_data_structure, 1); // using RFC9162 verifiable data structure | ||
protectedHeaderMap.set(13, cwtClaimsMap); | ||
receiptSigner = (0, signer_1.default)({ | ||
@@ -72,0 +76,0 @@ secretKeyJwk: secretKeyJwk |
@@ -1,1 +0,1 @@ | ||
export type UnprotectedHeader = Map<number, string | number | object>; | ||
export type UnprotectedHeader = Map<number | string, string | number | object>; |
@@ -33,6 +33,6 @@ "use strict"; | ||
// will be registered in https://github.com/ietf-scitt/draft-steele-cose-merkle-tree-proofs | ||
verifiable_data_structure: -11111, | ||
verifiable_data_structure_proofs: -22222, | ||
verifiable_data_structure: -111, | ||
verifiable_data_structure_proofs: -222, | ||
// will be registered in https://datatracker.ietf.org/doc/draft-birkholz-scitt-receipts/ | ||
scitt_receipt: -33333, | ||
scitt_receipt: -333, //'TBD_3', | ||
}; | ||
@@ -39,0 +39,0 @@ const unprotectedHeader = Object.assign(Object.assign({}, unprotectedHeaderTags), { get: (message) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const verifiable_data_structure_proofs = { | ||
inclusion_proof: 1, | ||
consistency_proof: 2, | ||
inclusion_proof: -1, | ||
consistency_proof: -2, | ||
}; | ||
exports.default = verifiable_data_structure_proofs; |
{ | ||
"name": "@transmute/cose", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "COSE and related work.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -49,2 +49,10 @@ import { bufferToTruncatedBstr } from "../rfc/beautify/bufferToTruncatedBstr"; | ||
} | ||
case -13: { | ||
lines.push(addComment(`${indentSpaces}${key}: ${bufferToTruncatedBstr(value)},`, 'Post quantum private key')) | ||
break | ||
} | ||
case -14: { | ||
lines.push(addComment(`${indentSpaces}${key}: ${bufferToTruncatedBstr(value)},`, 'Post quantum public key')) | ||
break | ||
} | ||
default: { | ||
@@ -51,0 +59,0 @@ throw new Error('Unsupported cose key value: ' + key) |
@@ -5,39 +5,46 @@ import { addComment } from "./addComment" | ||
import cbor from "../../cbor"; | ||
import { maxBstrTruncateLength } from './constants' | ||
// https://www.iana.org/assignments/cose/cose.xhtml | ||
const protectedHeaderTagToDescription = (tag: number) => { | ||
const descriptions = new Map(); | ||
descriptions.set(1, 'Algorithm') | ||
descriptions.set(2, 'Critical parameters') | ||
descriptions.set(3, 'Content type') | ||
descriptions.set(4, 'Key identifier') | ||
descriptions.set(-11111, 'Verifiable data structure') | ||
import { bufferToTruncatedBstr } from "./bufferToTruncatedBstr"; | ||
import { default as tags } from "../../unprotectedHeader"; | ||
return descriptions.get(tag) || `${tag} unknown cbor content` | ||
} | ||
export const beautifyProtectedHeader = async (data: Buffer | Uint8Array) => { | ||
const protectedHeader = await cbor.web.decode(data) | ||
const lines = [] as string[] | ||
for (const [label, value] of protectedHeader.entries()) { | ||
if (label === 1) { | ||
lines.push(addComment(` ${label}: ${value},`, 'Algorithm')) | ||
} else if (label === 2) { | ||
lines.push(addComment(` ${label}: ${value},`, 'Criticality')) | ||
} else if (label === 3) { | ||
lines.push(addComment(` ${label}: ${value},`, 'Content type')) | ||
} else if (label === 4) { | ||
lines.push(addComment(` ${label}: ${bufferToTruncatedBstr(value)},`, 'Key identifier')) | ||
} else if (label === 13) { | ||
lines.push(addComment(` ${label}: {`, 'CWT Claims')) | ||
for (const [claimKey, claimValue] of value.entries()) { | ||
if (claimKey === 1) { | ||
lines.push(addComment(` ${claimKey}: ${claimValue},`, 'Issuer')) | ||
} else if (claimKey === 2) { | ||
lines.push(addComment(` ${claimKey}: ${claimValue},`, 'Subject')) | ||
} else { | ||
lines.push(addComment(` ${claimKey}: ${claimValue},`, 'Claim')) | ||
} | ||
export const beautifyProtectedHeader = async (data: Buffer | Uint8Array) => { | ||
const diagnostic = await cbor.web.diagnose(data) | ||
const mapItemSpacer = ` ` | ||
let result = diagnostic; | ||
result = result.replace('{', `{\n${mapItemSpacer}`) | ||
result = result.replace(/, /g, `,\n${mapItemSpacer}`) | ||
result = result.replace('}', `\n}`) | ||
result = result.split('\n').map((line: string) => { | ||
if (line.trim() === '{') { | ||
line = addComment(`{`, `Protected`) | ||
return line | ||
} | ||
lines.push(` }`) | ||
} else if (label === tags.verifiable_data_structure) { | ||
lines.push(addComment(` ${label}: ${value},`, 'Verifiable Data Structure')) | ||
} else { | ||
lines.push(addComment(` ${label}: ${value},`, 'Parameter')) | ||
} | ||
if (line.includes(`h'`) && line.length > maxBstrTruncateLength) { | ||
line = line.replace(/h'(.{8}).+(.{8})'/g, `h'$1...$2'`) | ||
} | ||
if (line === '' || line.trim() === '{' || line.trim() === '}') { | ||
return line | ||
} | ||
const maybeIntLabel = parseInt(line.split(':')[0], 10) | ||
return addComment(line, `${protectedHeaderTagToDescription(maybeIntLabel)}`) | ||
}).join('\n') | ||
return result | ||
} | ||
return ` | ||
${addComment('{', 'Protected')} | ||
${lines.join('\n')} | ||
} | ||
`.trim() | ||
} |
@@ -7,5 +7,8 @@ import { addComment } from "./addComment" | ||
import { default as tags } from '../../unprotectedHeader' | ||
export const beautifyReceipts = async (receipts: Buffer[]) => { | ||
const blocks = [ | ||
`${addComment(` 300: [`, `Receipts (${receipts.length})`)} | ||
`${addComment(` ${tags.scitt_receipt}: [`, `Receipts (${receipts.length})`)} | ||
${receipts.map((receipt, i: number) => { | ||
@@ -12,0 +15,0 @@ const truncated = bufferToTruncatedBstr(receipt) |
@@ -0,3 +1,4 @@ | ||
import * as statement from './statement' | ||
import * as receipt from './receipt' | ||
export { receipt } | ||
export { statement, receipt } |
@@ -19,2 +19,4 @@ | ||
export type RequestScittReceipt = { | ||
iss: string | ||
sub: string | ||
index: number | ||
@@ -28,3 +30,3 @@ entries?: ArrayBuffer[] | ||
export const issue = async ({ index, entries, leaves, signer, secretCoseKey }: RequestScittReceipt): Promise<ArrayBuffer> => { | ||
export const issue = async ({ iss, sub, index, entries, leaves, signer, secretCoseKey }: RequestScittReceipt): Promise<ArrayBuffer> => { | ||
let treeLeaves = leaves | ||
@@ -46,2 +48,5 @@ if (entries) { | ||
const protectedHeaderMap = new Map() | ||
const cwtClaimsMap = new Map() | ||
cwtClaimsMap.set(1, iss) | ||
cwtClaimsMap.set(2, sub) | ||
if (secretCoseKey) { | ||
@@ -53,2 +58,3 @@ const secretKeyJwk = await key.exportJWK(secretCoseKey as any) | ||
protectedHeaderMap.set(unprotectedHeader.verifiable_data_structure, 1) // using RFC9162 verifiable data structure | ||
protectedHeaderMap.set(13, cwtClaimsMap) | ||
receiptSigner = getSigner({ | ||
@@ -55,0 +61,0 @@ secretKeyJwk: secretKeyJwk as any |
@@ -1,1 +0,1 @@ | ||
export type UnprotectedHeader = Map<number, string | number | object> | ||
export type UnprotectedHeader = Map<number | string, string | number | object> |
@@ -11,7 +11,7 @@ import * as cbor from 'cbor-web' | ||
// will be registered in https://github.com/ietf-scitt/draft-steele-cose-merkle-tree-proofs | ||
verifiable_data_structure: -11111, // int | ||
verifiable_data_structure_proofs: -22222, // a map of ints to array of bstrs | ||
verifiable_data_structure: -111, // 'TBD_1', // int | ||
verifiable_data_structure_proofs: -222, //'TBD_2', // a map of ints to array of bstrs | ||
// will be registered in https://datatracker.ietf.org/doc/draft-birkholz-scitt-receipts/ | ||
scitt_receipt: -33333, | ||
scitt_receipt: -333, //'TBD_3', | ||
} | ||
@@ -18,0 +18,0 @@ |
const verifiable_data_structure_proofs = { | ||
inclusion_proof: 1, | ||
consistency_proof: 2, | ||
inclusion_proof: -1, | ||
consistency_proof: -2, | ||
} | ||
export default verifiable_data_structure_proofs |
222979
237
4849