@aamp/protocol 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/agent.d.ts +25 -0
- package/dist/src/agent.js +55 -0
- package/dist/src/constants.d.ts +21 -0
- package/dist/src/constants.js +32 -0
- package/dist/src/crypto.d.ts +8 -0
- package/dist/src/crypto.js +39 -0
- package/dist/src/express.d.ts +20 -0
- package/dist/src/express.js +75 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +30 -0
- package/dist/src/nextjs.d.ts +23 -0
- package/dist/src/nextjs.js +78 -0
- package/dist/src/publisher.d.ts +31 -0
- package/dist/src/publisher.js +84 -0
- package/dist/src/types.d.ts +81 -0
- package/dist/src/types.js +28 -0
- package/dist/test/handshake.spec.d.ts +1 -0
- package/dist/test/handshake.spec.js +53 -0
- package/package.json +24 -0
- package/src/agent.ts +72 -0
- package/src/constants.ts +35 -0
- package/src/crypto.ts +53 -0
- package/src/express.ts +104 -0
- package/src/index.ts +13 -0
- package/src/nextjs.ts +109 -0
- package/src/publisher.ts +107 -0
- package/src/types.ts +98 -0
- package/test/handshake.spec.ts +67 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration Test: Protocol Handshake
|
|
3
|
+
* Run using: npm test
|
|
4
|
+
* Location: sdk/typescript/test/handshake.spec.ts
|
|
5
|
+
*/
|
|
6
|
+
import { AAMPAgent } from '../src/agent';
|
|
7
|
+
import { AAMPPublisher } from '../src/publisher';
|
|
8
|
+
import { AccessPurpose } from '../src/types';
|
|
9
|
+
|
|
10
|
+
function base64ToUint8Array(base64: string): Uint8Array {
|
|
11
|
+
const binaryString = atob(base64);
|
|
12
|
+
const len = binaryString.length;
|
|
13
|
+
const bytes = new Uint8Array(len);
|
|
14
|
+
for (let i = 0; i < len; i++) {
|
|
15
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
16
|
+
}
|
|
17
|
+
return bytes;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function runTest() {
|
|
21
|
+
console.log("--- STARTING AAMP HANDSHAKE TEST ---");
|
|
22
|
+
|
|
23
|
+
// 1. Setup Publisher with Economic Policy
|
|
24
|
+
const publisher = new AAMPPublisher({
|
|
25
|
+
version: '1.1',
|
|
26
|
+
allowTraining: false,
|
|
27
|
+
allowRAG: true,
|
|
28
|
+
attributionRequired: true,
|
|
29
|
+
requiresPayment: true, // Publisher wants money...
|
|
30
|
+
allowAdSupportedAccess: true, // ...OR ads
|
|
31
|
+
paymentPointer: '$wallet.example.com/publisher'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// 2. Initialize Agent
|
|
35
|
+
const agent = new AAMPAgent();
|
|
36
|
+
await agent.initialize();
|
|
37
|
+
|
|
38
|
+
// TEST CASE A: Requesting RAG without Ads (Should FAIL due to Payment Requirement)
|
|
39
|
+
console.log("\n[TEST A] Requesting RAG (No Ads)...");
|
|
40
|
+
const reqA = await agent.createAccessRequest('/doc/1', AccessPurpose.RAG_RETRIEVAL, { adsDisplayed: false });
|
|
41
|
+
|
|
42
|
+
// Fix: Cast to any to avoid TS2769 error (Uint8Array vs BufferSource mismatch in ts-node)
|
|
43
|
+
const keyA = await crypto.subtle.importKey(
|
|
44
|
+
"spki",
|
|
45
|
+
base64ToUint8Array(reqA.publicKey!) as any,
|
|
46
|
+
{ name: "ECDSA", namedCurve: "P-256" },
|
|
47
|
+
true,
|
|
48
|
+
["verify"]
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const resA = await publisher.verifyRequest(reqA, keyA);
|
|
52
|
+
console.log("Result A (Expect Deny):", resA);
|
|
53
|
+
if (resA.allowed) throw new Error("Test A Failed (Should require payment)");
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// TEST CASE B: Requesting RAG WITH Ads (Should SUCCEED via Exemption)
|
|
57
|
+
console.log("\n[TEST B] Requesting RAG (With Ads)...");
|
|
58
|
+
const reqB = await agent.createAccessRequest('/doc/1', AccessPurpose.RAG_RETRIEVAL, { adsDisplayed: true });
|
|
59
|
+
|
|
60
|
+
const resB = await publisher.verifyRequest(reqB, keyA);
|
|
61
|
+
console.log("Result B (Expect Allow):", resB);
|
|
62
|
+
if (!resB.allowed) throw new Error("Test B Failed (Should allow via Ad exemption)");
|
|
63
|
+
|
|
64
|
+
console.log("\n--- ALL TESTS PASSED ---");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
runTest().catch(console.error);
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"lib": ["ES2020", "DOM"],
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*", "test/**/*"]
|
|
14
|
+
}
|