-
Notifications
You must be signed in to change notification settings - Fork 0
/
ap-request.ts
41 lines (33 loc) · 1.4 KB
/
ap-request.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as assert from 'assert';
import { genRsaKeyPair } from '../src/keypair';
import { createSignedPost, createSignedGet } from '../src/ap-request';
import { buildParsedSignature } from './utils';
import * as httpSignature from 'http-signature';
describe('ap-request', () => {
it('createSignedPost with verify', async () => {
const keypair = await genRsaKeyPair();
const key = { keyId: 'x', 'privateKeyPem': keypair.privateKey };
const url = 'https://example.com/inbox';
const activity = { a: 1 };
const body = JSON.stringify(activity);
const headers = {
'User-Agent': 'UA'
};
const rsult = createSignedPost({ key, url, body, additionalHeaders: headers });
const parsed = buildParsedSignature(rsult.signingString, rsult.signature, 'rsa-sha256');
const result = httpSignature.verifySignature(parsed, keypair.publicKey);
assert.deepStrictEqual(result, true);
});
it('createSignedGet with verify', async () => {
const keypair = await genRsaKeyPair();
const key = { keyId: 'x', 'privateKeyPem': keypair.privateKey };
const url = 'https://example.com/inbox';
const headers = {
'User-Agent': 'UA'
};
const rsult = createSignedGet({ key, url, additionalHeaders: headers });
const parsed = buildParsedSignature(rsult.signingString, rsult.signature, 'rsa-sha256');
const result = httpSignature.verifySignature(parsed, keypair.publicKey);
assert.deepStrictEqual(result, true);
});
});