-
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.
Merge pull request #9 from transmute-industries/feat/refactor-registr…
…y-examples Update scitt registry related diagnostics
- Loading branch information
Showing
15 changed files
with
584 additions
and
109 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import * as statement from './statement' | ||
import * as receipt from './receipt' | ||
|
||
export { receipt } | ||
export { statement, receipt } |
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,26 @@ | ||
|
||
import cbor from '../../cbor' | ||
|
||
import { default as tags } from '../../unprotectedHeader' | ||
|
||
type RequestAddReceipt = { | ||
statement: ArrayBuffer // really signed statement | ||
receipt: ArrayBuffer | ||
} | ||
|
||
export const addReceipt = ({ statement, receipt }: RequestAddReceipt) => { | ||
const decoded = cbor.decode(statement) | ||
let unprotectedHeader = decoded.value[1] | ||
if (!(unprotectedHeader instanceof Map)) { | ||
unprotectedHeader = new Map() | ||
} | ||
const existingReceipts = unprotectedHeader.get(tags.scitt_receipt) | ||
if (!existingReceipts) { | ||
unprotectedHeader.set(tags.scitt_receipt, [receipt]) | ||
} else { | ||
existingReceipts.push(receipt) | ||
} | ||
decoded.value[1] = unprotectedHeader | ||
return cbor.encode(decoded) | ||
} | ||
|
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,2 @@ | ||
export * from './issue' | ||
export * from './addReceipt' |
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,44 @@ | ||
|
||
|
||
import detachPayload from '../../detachPayload' | ||
import { typedArrayToBuffer } from '../../utils' | ||
import * as key from '../../key' | ||
import { SecretCoseKeyMap } from '../../key/types' | ||
import getSigner from "../../lib/signer" | ||
|
||
export type RequestScittSignedStatement = { | ||
iss: string | ||
sub: string | ||
cty: string | ||
payload: ArrayBuffer | ||
signer?: any, | ||
secretCoseKey?: SecretCoseKeyMap | ||
} | ||
|
||
export const issue = async ({ iss, sub, cty, payload, signer, secretCoseKey }: RequestScittSignedStatement): Promise<ArrayBuffer> => { | ||
let receiptSigner = signer | ||
const protectedHeaderMap = new Map() | ||
const unprotectedHeaderMap = new Map() | ||
const cwtClaimsMap = new Map() | ||
cwtClaimsMap.set(1, iss) | ||
cwtClaimsMap.set(2, sub) | ||
if (secretCoseKey) { | ||
const secretKeyJwk = await key.exportJWK(secretCoseKey as any) | ||
secretKeyJwk.alg = key.utils.algorithms.toJOSE.get(secretCoseKey.get(3) as number) | ||
protectedHeaderMap.set(1, secretCoseKey.get(3) as number) // set alg from the restricted key | ||
protectedHeaderMap.set(3, cty) // content type of the payload | ||
protectedHeaderMap.set(4, secretCoseKey.get(2) as number) // set kid from the restricted key | ||
protectedHeaderMap.set(13, cwtClaimsMap) | ||
receiptSigner = getSigner({ | ||
secretKeyJwk: secretKeyJwk as any | ||
}) | ||
} | ||
const signedStatement = await receiptSigner.sign({ | ||
protectedHeader: protectedHeaderMap, | ||
unprotectedHeader: unprotectedHeaderMap, | ||
payload | ||
}) | ||
const { signature } = await detachPayload(signedStatement) | ||
return typedArrayToBuffer(signature) | ||
|
||
} |
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 +1 @@ | ||
export type UnprotectedHeader = Map<number, string | number | object> | ||
export type UnprotectedHeader = Map<number | string, string | number | object> |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
|
||
|
||
const verifiable_data_structure_proofs = { | ||
inclusion_proof: 1, | ||
consistency_proof: 2, | ||
inclusion_proof: -1, | ||
consistency_proof: -2, | ||
} | ||
|
||
export default verifiable_data_structure_proofs |
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
Oops, something went wrong.