Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to sign headers #40

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/pages/background/services/signify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SignifyClient, Tier, ready } from "signify-ts";
import { SignifyClient, Tier, ready, Authenticater } from "signify-ts";

const Signify = () => {
let _client: SignifyClient | null;
Expand Down Expand Up @@ -41,12 +41,47 @@ const Signify = () => {
_client = null;
};

const signHeaders = async (aidName: string, method:string, path:string, origin: string) => {
const hab = await _client?.identifiers().get(aidName);
const keeper = _client?.manager!.get(hab);

const authenticator = new Authenticater(
keeper.signers[0],
keeper.signers[0].verfer
);

const headers = new Headers();
headers.set('Signify-Resource', hab.prefix);
headers.set(
'Signify-Timestamp',
new Date().toISOString().replace('Z', '000+00:00')
);
headers.set('Origin', origin);

const fields = [
'@method',
'@path',
'signify-resource',
'signify-timestamp',
'origin'
];

const signed_headers = authenticator.sign(
headers,
method,
path,
fields
);
return signed_headers;
};

return {
connect,
isConnected,
disconnect,
listIdentifiers,
listCredentials,
signHeaders
};
};

Expand Down