From 817d8375e4396f895e833a4ad660ffd844db8bff Mon Sep 17 00:00:00 2001 From: Orie Steele Date: Sat, 13 Jan 2024 09:13:40 -0600 Subject: [PATCH 1/4] comment out fs writing --- test/hpke/cose/direct.test.ts | 2 +- test/hpke/cose/wrap.test.ts | 2 +- test/hpke/jose/direct.test.ts | 2 +- test/hpke/jose/wrap.test.ts | 2 +- test/scitt/examples.md.test.ts | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/hpke/cose/direct.test.ts b/test/hpke/cose/direct.test.ts index 16bf1aa..8dd9740 100644 --- a/test/hpke/cose/direct.test.ts +++ b/test/hpke/cose/direct.test.ts @@ -6,7 +6,7 @@ import alternateDiagnostic from '../../../src/diagnostic' import { Suite0 } from '../common' -it('sanity', async () => { +it.skip('sanity', async () => { const k = await generate(Suite0) const pt = 'hello world' const m = new TextEncoder().encode(pt) diff --git a/test/hpke/cose/wrap.test.ts b/test/hpke/cose/wrap.test.ts index 6d5e25e..865a92f 100644 --- a/test/hpke/cose/wrap.test.ts +++ b/test/hpke/cose/wrap.test.ts @@ -6,7 +6,7 @@ import { Suite0 } from '../common' import alternateDiagnostic from '../../../src/diagnostic' import cbor from '../../../src/cbor' -it('sanity', async () => { +it.skip('sanity', async () => { const k = await generate(Suite0) const pt = 'hello world' const m = new TextEncoder().encode(pt) diff --git a/test/hpke/jose/direct.test.ts b/test/hpke/jose/direct.test.ts index 8752010..0e326b9 100644 --- a/test/hpke/jose/direct.test.ts +++ b/test/hpke/jose/direct.test.ts @@ -32,6 +32,6 @@ ${JSON.stringify(c, null, 2)} `.trim() - fs.writeFileSync('test/hpke/jose/direct.md', markdown) + // fs.writeFileSync('test/hpke/jose/direct.md', markdown) }) \ No newline at end of file diff --git a/test/hpke/jose/wrap.test.ts b/test/hpke/jose/wrap.test.ts index 04a367b..79d2339 100644 --- a/test/hpke/jose/wrap.test.ts +++ b/test/hpke/jose/wrap.test.ts @@ -31,5 +31,5 @@ ${JSON.stringify(c2, null, 2)} `.trim() - fs.writeFileSync('test/hpke/jose/wrap.md', markdown) + // fs.writeFileSync('test/hpke/jose/wrap.md', markdown) }) \ No newline at end of file diff --git a/test/scitt/examples.md.test.ts b/test/scitt/examples.md.test.ts index e8c37ac..0794582 100644 --- a/test/scitt/examples.md.test.ts +++ b/test/scitt/examples.md.test.ts @@ -364,7 +364,7 @@ it('x5c example', async () => { }) -afterAll(() => { - const final = lines.join('\n\n') - fs.writeFileSync('test/scitt/examples.md', final) -}) +// afterAll(() => { +// const final = lines.join('\n\n') +// fs.writeFileSync('test/scitt/examples.md', final) +// }) From ffb8093eae291e280618f46e504b515a1cc2acf6 Mon Sep 17 00:00:00 2001 From: Orie Steele Date: Sat, 13 Jan 2024 09:14:54 -0600 Subject: [PATCH 2/4] more comments --- test/cometre/CoMETRE.test.ts | 4 ++-- test/keys/examples.md.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cometre/CoMETRE.test.ts b/test/cometre/CoMETRE.test.ts index cfc071d..8759fc7 100644 --- a/test/cometre/CoMETRE.test.ts +++ b/test/cometre/CoMETRE.test.ts @@ -66,7 +66,7 @@ it('inclusion proof', async () => { }) const proofBlocks = await cose.rfc.diag(signed_inclusion_proof) - fs.writeFileSync('test/cometre/inclusion-proof.md', await cose.rfc.blocks(proofBlocks)) + // fs.writeFileSync('test/cometre/inclusion-proof.md', await cose.rfc.blocks(proofBlocks)) expect(verified_inclusion_proof).toBe( true, @@ -105,7 +105,7 @@ it('consistency proof', async () => { verifier, }) const proofBlocks = await cose.rfc.diag(signed_consistency_proof) - fs.writeFileSync('test/cometre/consistency-proof.md', await cose.rfc.blocks(proofBlocks)) + // fs.writeFileSync('test/cometre/consistency-proof.md', await cose.rfc.blocks(proofBlocks)) expect(verified).toBe(true) const verified_root = await verifier.verify(signed_consistency_proof) expect(verified_root).toEqual(new_root) diff --git a/test/keys/examples.md.test.ts b/test/keys/examples.md.test.ts index bc134a7..bf8d409 100644 --- a/test/keys/examples.md.test.ts +++ b/test/keys/examples.md.test.ts @@ -102,5 +102,5 @@ ${diag} afterAll(() => { const final = lines.join('\n\n') - fs.writeFileSync('test/keys/examples.md', final) + // fs.writeFileSync('test/keys/examples.md', final) }) From 1b89853bb098ea751b49b3dfcbadfe70e605978a Mon Sep 17 00:00:00 2001 From: Orie Steele Date: Sat, 13 Jan 2024 09:35:12 -0600 Subject: [PATCH 3/4] wip --- src/key/keyUtils.ts | 2 +- test/hpke/common.ts | 2 +- .../cose/cross-testing/cross-test.test.ts | 41 +++++++++++++++++++ test/hpke/cose/direct.md | 2 +- test/hpke/cose/wrap.md | 2 +- test/hpke/cose/wrap.test.ts | 2 +- 6 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 test/hpke/cose/cross-testing/cross-test.test.ts diff --git a/src/key/keyUtils.ts b/src/key/keyUtils.ts index 27dae9f..214a825 100644 --- a/src/key/keyUtils.ts +++ b/src/key/keyUtils.ts @@ -9,7 +9,7 @@ const algsMap = new Map([ [-7, 'ES256'], [-35, 'ES384'], [-36, 'ES512'], - [-55555, 'HPKE-Base-P256-SHA256-AES128GCM'] + [35, 'HPKE-Base-P256-SHA256-AES128GCM'] ]); const algorithms = { diff --git a/test/hpke/common.ts b/test/hpke/common.ts index 90ac88a..40d578d 100644 --- a/test/hpke/common.ts +++ b/test/hpke/common.ts @@ -9,7 +9,7 @@ export type PublicCoseKeyMap = Map export const encapsulated_key_header_label = -22222; -export const example_suite_label = -55555; +export const example_suite_label = 35; export const COSE_EncryptTag = 96 diff --git a/test/hpke/cose/cross-testing/cross-test.test.ts b/test/hpke/cose/cross-testing/cross-test.test.ts new file mode 100644 index 0000000..f75e720 --- /dev/null +++ b/test/hpke/cose/cross-testing/cross-test.test.ts @@ -0,0 +1,41 @@ +// import fs from 'fs' +// import generate from '../jose/generate' +// import wrap from './wrap' +// import * as coseKey from '../../../src/key' +// import { Suite0 } from '../common' +// import alternateDiagnostic from '../../../src/diagnostic' +// import cbor from '../../../src/cbor' + +import cbor from "../../../../src/cbor" + +import wrap from '../wrap' + +it('send 2 layer to friend', async () => { + // { + // / kty = 'EC2' / + // 1: 2, + // / kid = '01' / + // 2: h'3031', + // / alg = HPKE-Base-P256-SHA256-AES128GCM (Assumed: 35) / + // 3: 35, + // / crv = 'P-256' / + // -1: 1, + // / x / + // -2: h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d', + // / y / + // -3: h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd0084d19c' + // } + const recipientPublicKey = new Map([ + [1, 2], // kty = 'EC2' / + [2, Buffer.from('3031', 'hex')], // kid = '01' / + [3, 35], // alg = HPKE-Base-P256-SHA256-AES128GCM (Assumed: 35) / + [-1, 1], // crv = 'P-256' / + [-2, Buffer.from('65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d', 'hex')], // x / + [-3, Buffer.from('1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd0084d19c', 'hex')], // y / + ]) + const pt = 'hello world' + const m = new TextEncoder().encode(pt) + const c4 = await wrap.encrypt(m, recipientPublicKey) + console.log(c4) + +}) \ No newline at end of file diff --git a/test/hpke/cose/direct.md b/test/hpke/cose/direct.md index 42399f8..79f2889 100644 --- a/test/hpke/cose/direct.md +++ b/test/hpke/cose/direct.md @@ -6,7 +6,7 @@ { / COSE Key / 1: 2, / Type / 2: h'74657374...792d3432', / Identifier / - 3: -55555, / Algorithm / + 3: 35, / Algorithm / -1: 1, / Curve / -2: h'e1cbfcf7...f8542800', / x public key component / -3: h'2537ece3...1c28e6d5', / y public key component / diff --git a/test/hpke/cose/wrap.md b/test/hpke/cose/wrap.md index c7f675f..69bbe6f 100644 --- a/test/hpke/cose/wrap.md +++ b/test/hpke/cose/wrap.md @@ -6,7 +6,7 @@ { / COSE Key / 1: 2, / Type / 2: h'74657374...792d3432', / Identifier / - 3: -55555, / Algorithm / + 3: 35, / Algorithm / -1: 1, / Curve / -2: h'11198ff1...e6e82d47', / x public key component / -3: h'8779a21b...a2b5c32d', / y public key component / diff --git a/test/hpke/cose/wrap.test.ts b/test/hpke/cose/wrap.test.ts index 865a92f..0510616 100644 --- a/test/hpke/cose/wrap.test.ts +++ b/test/hpke/cose/wrap.test.ts @@ -26,7 +26,7 @@ it.skip('sanity', async () => { const dL1Protected = await alternateDiagnostic(decoded.value[3][0][0]) // console.log(dL1Protected) expect(dL1Protected).toBe(`{ -1: -55555 +1: 35 } `) const c4Diagnostic = await alternateDiagnostic(c4) From 6c5040ccdf997fc8b27fb442c9873df0084ccad0 Mon Sep 17 00:00:00 2001 From: Orie Steele Date: Sat, 13 Jan 2024 09:45:07 -0600 Subject: [PATCH 4/4] updates for cross test --- test/hpke/common.ts | 2 +- .../cose/cross-testing/cross-test.test.ts | 23 +++++++++++++++++-- test/hpke/cose/direct.md | 2 +- test/hpke/cose/wrap.md | 2 +- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/test/hpke/common.ts b/test/hpke/common.ts index 40d578d..e7fb8f2 100644 --- a/test/hpke/common.ts +++ b/test/hpke/common.ts @@ -8,7 +8,7 @@ export const Suite0 = 'HPKE-Base-P256-SHA256-AES128GCM' as Suite0 // aka APPLE-H export type PublicCoseKeyMap = Map export type SecretCoseKeyMap = Map -export const encapsulated_key_header_label = -22222; +export const encapsulated_key_header_label = -4; export const example_suite_label = 35; diff --git a/test/hpke/cose/cross-testing/cross-test.test.ts b/test/hpke/cose/cross-testing/cross-test.test.ts index f75e720..6e762d2 100644 --- a/test/hpke/cose/cross-testing/cross-test.test.ts +++ b/test/hpke/cose/cross-testing/cross-test.test.ts @@ -36,6 +36,25 @@ it('send 2 layer to friend', async () => { const pt = 'hello world' const m = new TextEncoder().encode(pt) const c4 = await wrap.encrypt(m, recipientPublicKey) - console.log(c4) - + // console.log(c4.toString('hex')) + // d8608443a10101a1054cc76efc0f1b057e5776bd70d0581b86ca9fcb76c70878e21a3a060b5783e9aed4be2826f95b9cacd766818344a1011823a20442303123584104cd5924f279ef1cd99ba24243cec2b5f795058e657f973d873ea99fa8a020d31b980644528636ec1cb1011e9b0828d4598054004188bd28b64da3bab0eb2fcc5c5820114637018aaac9cf03c81db3fa9c5fa15ef4b0d140edd4da815eada6e053fd9e + const diagnostic = await cbor.diagnose(c4) + // console.log(diagnostic) + // 96([ + // h'a10101', + // { + // 5: h'c76efc0f1b057e5776bd70d0' + // }, + // h'86ca9fcb76c70878e21a3a060b5783e9aed4be2826f95b9cacd766', + // [ + // [ + // h'a1011823', + // { + // 4: h'3031', + // -4: h'04cd5924f279ef1cd99ba24243cec2b5f795058e657f973d873ea99fa8a020d31b980644528636ec1cb1011e9b0828d4598054004188bd28b64da3bab0eb2fcc5c' + // }, + // h'114637018aaac9cf03c81db3fa9c5fa15ef4b0d140edd4da815eada6e053fd9e' + // ] + // ] + // ]) }) \ No newline at end of file diff --git a/test/hpke/cose/direct.md b/test/hpke/cose/direct.md index 79f2889..e3465f0 100644 --- a/test/hpke/cose/direct.md +++ b/test/hpke/cose/direct.md @@ -21,7 +21,7 @@ h'a10139d902', { 4: "test-key-42", - -22222: h'042b5c4...ed24ca04' / encapsulated key / + -4: h'042b5c4...ed24ca04' / encapsulated key / }, h'a054152691ebb37a679699be32e88979454aa474f87f05c866ad84' / cipher text / ]) diff --git a/test/hpke/cose/wrap.md b/test/hpke/cose/wrap.md index 69bbe6f..2a47cc5 100644 --- a/test/hpke/cose/wrap.md +++ b/test/hpke/cose/wrap.md @@ -28,7 +28,7 @@ h'a10139d902', { 4: "test-key-42", - -22222: h'0465031...c93fa9f' / encapsulated key / + -4: h'0465031...c93fa9f' / encapsulated key / }, h'9a78b4020d7320d7ffc9aff1f440acc7557a431497ff158dcc04b6644a20cda5' / encrypted key / ]