MCPcopy Create free account
hub / github.com/WICG/webpackage / generateDataToBeSigned

Function generateDataToBeSigned

js/sign/src/utils/utils.ts:185–217  ·  view source on GitHub ↗
(
  webBundleHash: Uint8Array,
  integrityBlockCborBytes: Uint8Array,
  newAttributesCborBytes: Uint8Array
)

Source from the content-addressed store, hash-verified

183}
184
185export function generateDataToBeSigned(
186 webBundleHash: Uint8Array,
187 integrityBlockCborBytes: Uint8Array,
188 newAttributesCborBytes: Uint8Array
189): Uint8Array {
190 // The order is critical and must be the following:
191 // (0) hash of the bundle,
192 // (1) integrity block, and
193 // (2) attributes.
194 const dataParts = [
195 webBundleHash,
196 integrityBlockCborBytes,
197 newAttributesCborBytes,
198 ];
199
200 const bigEndianNumLength = 8;
201
202 const totalLength = dataParts.reduce((previous, current) => {
203 return previous + current.length;
204 }, /*one big endian num per part*/ dataParts.length * bigEndianNumLength);
205 const buffer = Buffer.alloc(totalLength);
206
207 let offset = 0;
208 dataParts.forEach((d) => {
209 buffer.writeBigInt64BE(BigInt(d.length), offset);
210 offset += bigEndianNumLength;
211
212 Buffer.from(d).copy(buffer, offset);
213 offset += d.length;
214 });
215
216 return new Uint8Array(buffer);
217}

Callers 2

validateSignaturesMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected