MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / signRequest

Function signRequest

lib/src/client.ts:147–164  ·  view source on GitHub ↗
(
  /** The resource meant to be fetched */
  subject: string,
  agent: Agent,
  headers: HeadersObject,
)

Source from the content-addressed store, hash-verified

145 * the Agents subject is missing
146 */
147export async function signRequest(
148 /** The resource meant to be fetched */
149 subject: string,
150 agent: Agent,
151 headers: HeadersObject,
152): Promise<HeadersObject> {
153 if (agent.subject !== undefined) {
154 const privateKey = agent.privateKey;
155 const timestamp = getTimestampNow();
156 const message = `${subject} ${timestamp}`;
157 const signed = await signToBase64(message, privateKey);
158 headers['x-atomic-public-key'] = await agent.getPublicKey();
159 headers['x-atomic-signature'] = signed;
160 headers['x-atomic-timestamp'] = timestamp.toString();
161 headers['x-atomic-agent'] = agent?.subject;
162 }
163 return headers;
164}
165
166/**
167 * Uploads files to the `/upload` endpoint of the Store. Signs the Headers using

Callers 3

fetchAsFunction · 0.90
fetchResourceFunction · 0.85
uploadFilesFunction · 0.85

Calls 3

signToBase64Function · 0.90
getTimestampNowFunction · 0.85
getPublicKeyMethod · 0.80

Tested by

no test coverage detected