Skip to content

Commit

Permalink
adjust pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
OR13 committed Oct 21, 2023
1 parent 9bea1a4 commit 4444759
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 113 deletions.
Binary file modified inclusion-proof.cose
Binary file not shown.
50 changes: 25 additions & 25 deletions inclusion-proof.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
~~~~ cbor-diag
18( / COSE Single Signer Data Object /
18( / COSE Sign 1 /
[
h'a3012604...392b6601', / Protected header /
{ / Unprotected header /
-22222: { / Proofs /
1: [ / Inclusion proofs (2) /
h'83040282...1f487bb1', / Inclusion proof 1 /
h'83040382...1f487bb1', / Inclusion proof 2 /
h'a3012604...392b6601', / Protected /
{ / Unprotected /
-22222: { / Proofs /
1: [ / Inclusion proofs (2) /
h'83040282...1f487bb1', / Inclusion proof 1 /
h'83040382...1f487bb1', / Inclusion proof 2 /
]
},
},
h'', / Detached payload /
h'0a1e2031...5cb26f93' / Signature /
h'', / Detached payload /
h'a490381e...c166e580' / Signature /
]
)
~~~~

~~~~ cbor-diag
{ / Protected header /
1: -7, / Cryptographic algorithm to use /
4: h'68747470...6d706c65', / Key identifier /
-11111: 1 / Verifiable data structure /
{ / Protected /
1: -7, / Cryptographic algorithm to use/
4: h'68747470...6d706c65', / Key identifier /
-11111: 1 / Verifiable data structure /
}
~~~~

~~~~ cbor-diag
[ / Inclusion proof 1 /
4, / Tree size /
2, / Leaf index /
[ / Inclusion hashes (2) /
h'a39655d4...d29a968a' / Intermediate hash 1 /
h'57187dff...1f487bb1' / Intermediate hash 2 /
[ / Inclusion proof 1 /
4, / Tree size /
2, / Leaf index /
[ / Inclusion hashes (2) /
h'a39655d4...d29a968a' / Intermediate hash 1 /
h'57187dff...1f487bb1' / Intermediate hash 2 /
]
]
~~~~

~~~~ cbor-diag
[ / Inclusion proof 2 /
4, / Tree size /
3, / Leaf index /
[ / Inclusion hashes (2) /
h'e7f16481...aab81688' / Intermediate hash 1 /
h'57187dff...1f487bb1' / Intermediate hash 2 /
[ / Inclusion proof 2 /
4, / Tree size /
3, / Leaf index /
[ / Inclusion hashes (2) /
h'e7f16481...aab81688' / Intermediate hash 1 /
h'57187dff...1f487bb1' / Intermediate hash 2 /
]
]
~~~~
12 changes: 9 additions & 3 deletions src/rfc/beautify/addComment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@

import { maxLineLength, commentOffset } from './constants'


export const addComment = (line: string, comment: string) => {
let paddedComment = ' '.repeat(maxLineLength - commentOffset - line.length) + `/ ` + `${comment}`
paddedComment = paddedComment + ' '.repeat(maxLineLength - line.length - paddedComment.length) + '/'
let linePrexiSpaces = maxLineLength - commentOffset - line.length
if (linePrexiSpaces < 0) {
linePrexiSpaces = 0;
}
let paddedComment = ' '.repeat(linePrexiSpaces) + `/ ` + `${comment}`

const lineSuffixSpaces = maxLineLength - line.length - paddedComment.length

paddedComment = paddedComment + ' '.repeat(lineSuffixSpaces) + '/'
return `${line}${paddedComment}`
}
4 changes: 2 additions & 2 deletions src/rfc/beautify/beautifyCoseSign1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export const beautifyCoseSign1 = async (data: Uint8Array): Promise<string[]> =>
const payloadLine = ` ${bufferToTruncatedBstr(decoded.value[2])},`
const signatureLine = ` ${bufferToTruncatedBstr(decoded.value[3])}`
const envelope = `
18( / COSE Single Signer Data Object /
${addComment(`18(`, 'COSE Sign 1')}
[
${addComment(protectedHeaderLine, 'Protected header')}
${addComment(protectedHeaderLine, 'Protected')}
${unprotectedHeaderLines}
${addComment(payloadLine, decoded.value[2].length > 0 ? `Payload` : `Detached payload`)}
${addComment(signatureLine, 'Signature')}
Expand Down
2 changes: 1 addition & 1 deletion src/rfc/beautify/beautifyProtectedHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const beautifyProtectedHeader = async (data: Buffer | Uint8Array) => {
result = result.replace('}', `\n}`)
result = result.split('\n').map((line: string) => {
if (line.trim() === '{') {
line = addComment(`{`, `Protected header`)
line = addComment(`{`, `Protected`)
return line
}
if (line.includes(`h'`) && line.length > maxBstrTruncateLength) {
Expand Down
4 changes: 2 additions & 2 deletions src/rfc/beautify/beautifyUnprotectedHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ labelMap.set(unprotectedHeader.scitt_receipt, beautifyReceipts)

export const beautifyUnprotectedHeader = async (unprotectedHeader: Map<number, unknown>) => {
let allBlocks = [] as string[]
let result = addComment(` {},`, `Unprotected header`)
let result = addComment(` {},`, `Unprotected`)
if (unprotectedHeader.size) {
let lines = [] as string[]
for (const [key, value] of unprotectedHeader.entries()) {
Expand All @@ -27,7 +27,7 @@ export const beautifyUnprotectedHeader = async (unprotectedHeader: Map<number, u
lines = [...lines, primaryLine]
allBlocks = [...allBlocks, ...otherBlocks]
}
const title = addComment(` {`, `Unprotected header`)
const title = addComment(` {`, `Unprotected`)
result = `${title}
${lines.join(' \n')}
},`
Expand Down
4 changes: 2 additions & 2 deletions src/rfc/beautify/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const maxLineLength = 76
export const commentOffset = 40
export const maxLineLength = 68
export const commentOffset = 32
export const maxBstrTruncateLength = 32
36 changes: 18 additions & 18 deletions test/cometre/consistency-proof.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
~~~~ cbor-diag
18( / COSE Single Signer Data Object /
18( / COSE Sign 1 /
[
h'a3012604...392b6601', / Protected header /
{ / Unprotected header /
-22222: { / Proofs /
2: [ / Consistency proofs (1) /
h'83040682...2e73a8ab', / Consistency proof 1 /
h'a3012604...392b6601', / Protected /
{ / Unprotected /
-22222: { / Proofs /
2: [ / Consistency proofs (1) /
h'83040682...2e73a8ab', / Consistency proof 1 /
]
},
},
h'430b6fd7...f74c7fc4', / Payload /
h'f5095fb2...692bc9fd' / Signature /
h'430b6fd7...f74c7fc4', / Payload /
h'03c9eb00...6201c3ad' / Signature /
]
)
~~~~

~~~~ cbor-diag
{ / Protected header /
1: -7, / Cryptographic algorithm to use /
4: h'68747470...6d706c65', / Key identifier /
-11111: 1 / Verifiable data structure /
{ / Protected /
1: -7, / Cryptographic algorithm to use/
4: h'68747470...6d706c65', / Key identifier /
-11111: 1 / Verifiable data structure /
}
~~~~

~~~~ cbor-diag
[ / Consistency proof 1 /
4, / Tree size 1 /
6, / Tree size 2 /
[ / Consistency hashes (2) /
h'0bdaaed3...32568964' / Intermediate hash 1 /
h'75f177fd...2e73a8ab' / Intermediate hash 2 /
[ / Consistency proof 1 /
4, / Tree size 1 /
6, / Tree size 2 /
[ / Consistency hashes (2) /
h'0bdaaed3...32568964' / Intermediate hash 1 /
h'75f177fd...2e73a8ab' / Intermediate hash 2 /
]
]
~~~~
36 changes: 18 additions & 18 deletions test/cometre/inclusion-proof.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
~~~~ cbor-diag
18( / COSE Single Signer Data Object /
18( / COSE Sign 1 /
[
h'a3012604...392b6601', / Protected header /
{ / Unprotected header /
-22222: { / Proofs /
1: [ / Inclusion proofs (1) /
h'83040282...1f487bb1', / Inclusion proof 1 /
h'a3012604...392b6601', / Protected /
{ / Unprotected /
-22222: { / Proofs /
1: [ / Inclusion proofs (1) /
h'83040282...1f487bb1', / Inclusion proof 1 /
]
},
},
h'', / Detached payload /
h'b53e2c6a...cb3f43cb' / Signature /
h'', / Detached payload /
h'bcbbeeca...1535f71f' / Signature /
]
)
~~~~

~~~~ cbor-diag
{ / Protected header /
1: -7, / Cryptographic algorithm to use /
4: h'68747470...6d706c65', / Key identifier /
-11111: 1 / Verifiable data structure /
{ / Protected /
1: -7, / Cryptographic algorithm to use/
4: h'68747470...6d706c65', / Key identifier /
-11111: 1 / Verifiable data structure /
}
~~~~

~~~~ cbor-diag
[ / Inclusion proof 1 /
4, / Tree size /
2, / Leaf index /
[ / Inclusion hashes (2) /
h'a39655d4...d29a968a' / Intermediate hash 1 /
h'57187dff...1f487bb1' / Intermediate hash 2 /
[ / Inclusion proof 1 /
4, / Tree size /
2, / Leaf index /
[ / Inclusion hashes (2) /
h'a39655d4...d29a968a' / Intermediate hash 1 /
h'57187dff...1f487bb1' / Intermediate hash 2 /
]
]
~~~~
Loading

0 comments on commit 4444759

Please sign in to comment.