Skip to content

Commit 83b58cc

Browse files
author
Corey B
committed
fix: trim template in signature payload to prevent whitespace mismatch
1 parent e3c52c6 commit 83b58cc

5 files changed

Lines changed: 15 additions & 20 deletions

File tree

examples/bank_statement_v2.fdd

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"VerifiableCredential"
1010
],
1111
"issuer": "did:web:spuds0588.github.io:open-fdd",
12-
"issuanceDate": "2026-04-12T04:28:27.881Z",
12+
"issuanceDate": "2026-04-12T04:48:42.859Z",
1313
"credentialSubject": {
1414
"bankName": "First National Bank",
1515
"accountHolder": "Jordan M. Castillo",
@@ -123,10 +123,10 @@
123123
},
124124
"proof": {
125125
"type": "Ed25519Signature2020",
126-
"created": "2026-04-12T04:28:27.883Z",
126+
"created": "2026-04-12T04:48:42.861Z",
127127
"proofPurpose": "assertionMethod",
128128
"verificationMethod": "did:web:spuds0588.github.io:open-fdd#key-1",
129-
"signatureValue": "HD4kZWfbRiXWmG94FaI1WyKPjJLah9Ebtb+kYrU7GXVlsOb3z8Lxq9U0o4fuozvhwfaGuwjkvBHl/BhCLQ38DA=="
129+
"signatureValue": "lYrOkcUX+t0CfThS2M+wE38Fkpd/Frn5gdl1jBQsn/J5PYNLWP6IgxpgRhFSemrw2Y7dvtLNOXlGPxHiqIWLBg=="
130130
}
131131
}
132132
</script>
@@ -138,8 +138,7 @@
138138
</script>
139139

140140
<template shadowrootmode="open" bind="#fdd-data, #user-notes">
141-
142-
<style>
141+
<style>
143142
* { box-sizing: border-box; margin: 0; padding: 0; }
144143
.stmt { max-width: 820px; margin: 2rem auto; font-family: 'Segoe UI', system-ui, sans-serif; color: #1e293b; }
145144
.header { background: linear-gradient(135deg, #1e3a5f, #0ea5e9); color: white; padding: 2rem; border-radius: 8px 8px 0 0; display: flex; justify-content: space-between; align-items: flex-end; }
@@ -216,6 +215,5 @@
216215
<span>This statement is a Formatted Data Document (.fdd) — tamper-evident and machine-readable.</span>
217216
</div>
218217
</div>
219-
220218
</template>
221219
</fdd-container>

examples/legal_contract.fdd

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"VerifiableCredential"
1010
],
1111
"issuer": "did:web:spuds0588.github.io:open-fdd",
12-
"issuanceDate": "2026-04-12T04:28:27.888Z",
12+
"issuanceDate": "2026-04-12T04:48:42.866Z",
1313
"credentialSubject": {
1414
"documentTitle": "Consulting Services Agreement",
1515
"documentId": "HSL-2026-0041",
@@ -55,10 +55,10 @@
5555
},
5656
"proof": {
5757
"type": "Ed25519Signature2020",
58-
"created": "2026-04-12T04:28:27.888Z",
58+
"created": "2026-04-12T04:48:42.866Z",
5959
"proofPurpose": "assertionMethod",
6060
"verificationMethod": "did:web:spuds0588.github.io:open-fdd#key-1",
61-
"signatureValue": "HuZG30SseNW9Cf3c+j4BoIq6/70XRTJplYb2jpe5Gsn1XrKDFmVsVN/SLOvZt+753OxnRh8y1/b8Byxmzam9AA=="
61+
"signatureValue": "L6pVN8/fjzlL3wCxeHrcHbiMKzn2FpwwQXa+08dBR//m3TKRKtACFke6wtDhyPfChXkopX9u29CZtUVYG2QeAw=="
6262
}
6363
}
6464
</script>
@@ -72,8 +72,7 @@
7272
</script>
7373

7474
<template shadowrootmode="open" bind="#fdd-data, #user-notes">
75-
76-
<style>
75+
<style>
7776
* { box-sizing: border-box; margin: 0; padding: 0; }
7877
.doc { max-width: 760px; margin: 2rem auto; padding: 2.5rem; background: #fff; border: 1px solid #d1d5db; font-family: 'Times New Roman', Georgia, serif; color: #1a1a1a; }
7978
.doc-title { text-align: center; font-size: 1.5rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.25rem; }
@@ -156,6 +155,5 @@
156155
Governing Law: {{governingLaw}} · This document is cryptographically signed. Issuer: did:web:hartwell-law.example
157156
</div>
158157
</div>
159-
160158
</template>
161159
</fdd-container>

examples/medical_lab_result.fdd

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"VerifiableCredential"
1010
],
1111
"issuer": "did:web:spuds0588.github.io:open-fdd",
12-
"issuanceDate": "2026-04-12T04:28:27.886Z",
12+
"issuanceDate": "2026-04-12T04:48:42.864Z",
1313
"credentialSubject": {
1414
"patientName": "Alexandra Rivera",
1515
"dateOfBirth": "1987-03-22",
@@ -65,10 +65,10 @@
6565
},
6666
"proof": {
6767
"type": "Ed25519Signature2020",
68-
"created": "2026-04-12T04:28:27.886Z",
68+
"created": "2026-04-12T04:48:42.864Z",
6969
"proofPurpose": "assertionMethod",
7070
"verificationMethod": "did:web:spuds0588.github.io:open-fdd#key-1",
71-
"signatureValue": "hrFWVQ03c9lflDzjzxdr1rRb43R2+H+rgK8LlcbE/YbZ1ZetACkfOR/g+nCw1J1er7o1oz935mcQv1WKy0VSCQ=="
71+
"signatureValue": "zYsuQ+vfunqtiv+WSIHCNS0hwj1TTYV9vDpYfS/+fdh2zpHPkTXdfGa63XNOVtzdV/rgjmEzo6Nc+1sKlF65CQ=="
7272
}
7373
}
7474
</script>
@@ -80,8 +80,7 @@
8080
</script>
8181

8282
<template shadowrootmode="open" bind="#fdd-data, #user-notes">
83-
84-
<style>
83+
<style>
8584
* { box-sizing: border-box; margin: 0; padding: 0; }
8685
body { font-family: 'Segoe UI', system-ui, sans-serif; }
8786
.report { max-width: 800px; margin: 2rem auto; padding: 2rem; background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; }
@@ -151,6 +150,5 @@
151150
Issuer: did:web:valleymedical.example
152151
</div>
153152
</div>
154-
155153
</template>
156154
</fdd-container>

lib/node-fdd/src/sign.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import path from 'path';
2929
* @returns {string} - Complete .fdd file content
3030
*/
3131
export function signFdd(data, template, privateKeyPem, issuerUri, mutableData = {}) {
32+
template = template.trim();
3233
const privateKey = crypto.createPrivateKey(privateKeyPem);
3334

3435
// Build the Verifiable Credential wrapper (without proof first)
@@ -132,7 +133,7 @@ export async function verify(fddString) {
132133
delete vcWithoutProof.proof;
133134

134135
const templateMatch = fddString.match(/<template[^>]*>([\s\S]*?)<\/template>/i);
135-
const template = templateMatch ? templateMatch[1] : '';
136+
const template = templateMatch ? templateMatch[1].trim() : '';
136137
const payload = Buffer.from(JSON.stringify(vcWithoutProof) + '\n---template---\n' + template, 'utf8');
137138

138139
try {

site/sandbox.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ <h1>Statement for {{accountHolder}}</h1>
464464
// step 6
465465
set('payload','run', N('Reconstructing the exact byte sequence that was signed…'));
466466
const tmplMatch = source.match(/<template[^>]*>([\s\S]*?)<\/template>/i);
467-
const tmpl = tmplMatch ? tmplMatch[1] : '';
467+
const tmpl = tmplMatch ? tmplMatch[1].trim() : '';
468468
const vcNP = JSON.parse(JSON.stringify(vc)); delete vcNP.proof;
469469
const payloadStr = JSON.stringify(vcNP) + '\n---template---\n' + tmpl;
470470
const payloadBytes = new TextEncoder().encode(payloadStr);

0 commit comments

Comments
 (0)