-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update identifiers for scitt messages
- Loading branch information
Showing
6 changed files
with
81 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import cbor from "./cbor" | ||
import { EMPTY_BUFFER } from './lib/common' | ||
|
||
export const extractTBS = (message: Uint8Array) => { | ||
const { tag, value } = cbor.decode(message) | ||
if (tag !== 18) { | ||
throw new Error('only cose sign 1 is supported') | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const [protectedHeaderBytes, unprotectedHeaderMap, payloadBuffer] = value | ||
const tbs = cbor.encode([ | ||
'Signature1', | ||
protectedHeaderBytes, | ||
EMPTY_BUFFER, | ||
payloadBuffer | ||
]); | ||
return tbs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './urn' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import { base64url } from "jose"; | ||
import { createHash } from 'crypto' | ||
|
||
import cose from '../../../src' | ||
|
||
const urnPrefix = `urn:ietf:params:scitt` | ||
const nodeCryptoHashFunction = 'sha256' | ||
const mandatoryBaseEncoding = `base64url` // no pad . | ||
|
||
// https://www.iana.org/assignments/named-information/named-information.xhtml | ||
const nodeCryptoToIanaNamedHashFunctions = { | ||
[nodeCryptoHashFunction]: 'sha-256' | ||
} | ||
|
||
export const urn = (type: string, message: Buffer) => { | ||
if (['statement', 'transparent-statement'].includes(type)) { | ||
const messageHashBase64 = base64url.encode(createHash(nodeCryptoHashFunction).update(message).digest()); | ||
const scittUrn = `${urnPrefix}:${type}:${nodeCryptoToIanaNamedHashFunctions[nodeCryptoHashFunction]}:${mandatoryBaseEncoding}:${messageHashBase64}` | ||
return scittUrn; | ||
} else { | ||
const tbs = cose.extractTBS(message) | ||
const messageHashBase64 = base64url.encode(createHash(nodeCryptoHashFunction).update(tbs).digest()); | ||
const scittUrn = `${urnPrefix}:${type}:${nodeCryptoToIanaNamedHashFunctions[nodeCryptoHashFunction]}:${mandatoryBaseEncoding}:${messageHashBase64}` | ||
return scittUrn | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as statement from './statement' | ||
import * as receipt from './receipt' | ||
|
||
export { statement, receipt } | ||
import * as identifiers from './identifiers' | ||
export { statement, receipt, identifiers } |