@simbachain/simba-chain-vc 0.3.7 → 0.3.8
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/index.d.ts +4 -0
- package/src/index.js +59 -17
- package/tests/cert.txt +21 -0
- package/tests/test_vp.mjs +83 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
|
|
3
3
|
|
|
4
4
|
- - -
|
|
5
|
+
## v0.3.8 - 2026-02-07
|
|
6
|
+
#### Bug Fixes
|
|
7
|
+
- http client options - (d04a356) - Andrew Harrison
|
|
8
|
+
|
|
9
|
+
- - -
|
|
10
|
+
|
|
5
11
|
## v0.3.7 - 2026-02-06
|
|
6
12
|
#### Bug Fixes
|
|
7
13
|
- change package name back to lowercase - (8a1fec8) - Katherine Smith
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -69,6 +69,9 @@ declare function getSecpVerificationMethod(
|
|
|
69
69
|
asAddress?: boolean,
|
|
70
70
|
relationship?: string,
|
|
71
71
|
): Bytes;
|
|
72
|
+
declare function configureLoader(
|
|
73
|
+
opts?: object,
|
|
74
|
+
): object;
|
|
72
75
|
declare function getActors(vc: VcLike): Actors;
|
|
73
76
|
|
|
74
77
|
declare function multicodecEncode(pk: Bytes, code?: number): string;
|
|
@@ -76,6 +79,7 @@ declare function multicodecEncode(pk: Bytes, code?: number): string;
|
|
|
76
79
|
export {
|
|
77
80
|
asPublicJwk,
|
|
78
81
|
asPrivateJwk,
|
|
82
|
+
configureLoader,
|
|
79
83
|
getPublicKey,
|
|
80
84
|
privateKeyFromHex,
|
|
81
85
|
newPrivateKey,
|
package/src/index.js
CHANGED
|
@@ -15,27 +15,57 @@ import { schemaCache } from "./context.js";
|
|
|
15
15
|
import { encodeVarint, varintLength } from "./varint.js";
|
|
16
16
|
import fs from "fs";
|
|
17
17
|
import path from "path";
|
|
18
|
+
import https from "https"
|
|
18
19
|
import { fileURLToPath } from 'url';
|
|
19
20
|
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
documentUrl: url
|
|
34
|
-
};
|
|
22
|
+
/**
|
|
23
|
+
* Configure HTTP client and context cache.
|
|
24
|
+
* Without calling this, the cached schema will not be used.
|
|
25
|
+
*
|
|
26
|
+
* @param {opts} dictionary containing options. Supported options are:
|
|
27
|
+
* `ca` optional. CA cert in PEM format for custom trusted CA
|
|
28
|
+
* `strict` optional. If true or "1", enforce cert verification
|
|
29
|
+
* @returns configured https Agent options
|
|
30
|
+
*/
|
|
31
|
+
const configureLoader = (opts) => {
|
|
32
|
+
if (opts === undefined) {
|
|
33
|
+
opts = {}
|
|
35
34
|
}
|
|
36
|
-
|
|
35
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
36
|
+
const __dirname = path.dirname(__filename);
|
|
37
|
+
const agentOptions = {}
|
|
38
|
+
if (opts['strict'] !== undefined) {
|
|
39
|
+
agentOptions['rejectUnauthorized'] = opts['strict'] === '1' || (opts['strict'] === '0' ? false : opts['strict']);
|
|
40
|
+
}
|
|
41
|
+
if (opts['ca'] !== undefined) {
|
|
42
|
+
agentOptions["ca"] = opts['ca']
|
|
43
|
+
}
|
|
44
|
+
console.log("[JSONLD] :: agent options: " + JSON.stringify(agentOptions))
|
|
45
|
+
if (Object.keys(agentOptions).length === 0) {
|
|
46
|
+
const nodeDocumentLoader = jsonld.documentLoaders.node();
|
|
47
|
+
} else {
|
|
48
|
+
const agent = new https.Agent(agentOptions)
|
|
49
|
+
const nodeDocumentLoader = jsonld.documentLoaders.node(
|
|
50
|
+
{httpsAgent: agent}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const customLoader = async (url, options) => {
|
|
54
|
+
console.log("[JSONLD] :: customLoader called with URL: " + url)
|
|
55
|
+
if(url in schemaCache) {
|
|
56
|
+
const filePath = path.join(__dirname, '..', 'contexts', schemaCache[url]);
|
|
57
|
+
const contextData = fs.readFileSync(filePath, 'utf8');
|
|
58
|
+
return {
|
|
59
|
+
contextUrl: null,
|
|
60
|
+
document: contextData,
|
|
61
|
+
documentUrl: url
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return nodeDocumentLoader(url);
|
|
65
|
+
};
|
|
66
|
+
jsonld.documentLoader = customLoader;
|
|
67
|
+
return agentOptions;
|
|
37
68
|
};
|
|
38
|
-
jsonld.documentLoader = customLoader;
|
|
39
69
|
|
|
40
70
|
|
|
41
71
|
/**
|
|
@@ -398,6 +428,18 @@ const multicodecEncode = (pk, code = 0xe7) => {
|
|
|
398
428
|
};
|
|
399
429
|
|
|
400
430
|
export {
|
|
401
|
-
asPrivateJwk,
|
|
431
|
+
asPrivateJwk,
|
|
432
|
+
asPublicJwk,
|
|
433
|
+
configureLoader,
|
|
434
|
+
createAccount,
|
|
435
|
+
createErc1912023Vp,
|
|
436
|
+
getActors,
|
|
437
|
+
getAddress,
|
|
438
|
+
getPublicKey,
|
|
439
|
+
getSecpVerificationMethod,
|
|
440
|
+
multicodecEncode,
|
|
441
|
+
newPrivateKey,
|
|
442
|
+
privateKeyFromHex,
|
|
443
|
+
signData
|
|
402
444
|
};
|
|
403
445
|
|
package/tests/cert.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIDfTCCAuagAwIBAgIDErvmMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT
|
|
3
|
+
MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0
|
|
4
|
+
aWZpY2F0ZSBBdXRob3JpdHkwHh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8PDITtZDOLC5MH0Y0FWDomrL
|
|
19
|
+
NhGc6Ehmo21/uBPUR/6LWlxz/K7ZGzIZOKuXNBSqltLroxwUCEm2u+WR74M26x1W
|
|
20
|
+
b8ravHNjkOR/ez4iyz0H7V84dJzjA1BOoa+Y7mHyhD8S
|
|
21
|
+
-----END CERTIFICATE-----
|
package/tests/test_vp.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { describe, before, it } from "mocha";
|
|
|
2
2
|
import { expect } from "chai";
|
|
3
3
|
import { bytesToHex } from "web3-utils";
|
|
4
4
|
import {
|
|
5
|
+
configureLoader,
|
|
5
6
|
createErc1912023Vp,
|
|
6
7
|
newPrivateKey,
|
|
7
8
|
privateKeyFromHex,
|
|
@@ -15,6 +16,12 @@ import {
|
|
|
15
16
|
asPrivateJwk,
|
|
16
17
|
multicodecEncode,
|
|
17
18
|
} from "../src/index.js";
|
|
19
|
+
import fs from "fs";
|
|
20
|
+
import path from "path";
|
|
21
|
+
import { fileURLToPath } from 'url';
|
|
22
|
+
|
|
23
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
24
|
+
const __dirname = path.dirname(__filename);
|
|
18
25
|
|
|
19
26
|
const complexActorsVc = {
|
|
20
27
|
"@context": [
|
|
@@ -539,6 +546,82 @@ describe("project", () => {
|
|
|
539
546
|
expect(vp.proof.type).to.equal("ERC191Signature2023");
|
|
540
547
|
});
|
|
541
548
|
});
|
|
549
|
+
describe("VP creation with configured loader no options", () => {
|
|
550
|
+
it("should create and sign a VP the same way didlib does", async () => {
|
|
551
|
+
const pkFromHex = privateKeyFromHex(
|
|
552
|
+
"22aabb811efca4e6f4748bd18a46b502fa85549df9fa07da649c0a148d7d5530",
|
|
553
|
+
);
|
|
554
|
+
const configured = configureLoader();
|
|
555
|
+
expect(configured).to.deep.equal({});
|
|
556
|
+
console.log("Configured loader " + configured)
|
|
557
|
+
const didRef = getSecpVerificationMethod(pkFromHex, diddoc);
|
|
558
|
+
const vp = await createErc1912023Vp(
|
|
559
|
+
pkFromHex,
|
|
560
|
+
vc,
|
|
561
|
+
"090jd4%000kjbndt!",
|
|
562
|
+
didRef,
|
|
563
|
+
);
|
|
564
|
+
expect(vp.proof.proofValue).to.equal(
|
|
565
|
+
"0xc0d2517bb2728cc8b213b6511e3b945800a1cf7806e58177117dec84fe0baf4631cad29e0424b8e122ee138605b785c3d17dc7fc5d117692b71527a8f330467e1b",
|
|
566
|
+
);
|
|
567
|
+
expect(vp.proof.challenge).to.equal(
|
|
568
|
+
"090jd4%000kjbndt!",
|
|
569
|
+
);
|
|
570
|
+
expect(vp.proof.proofPurpose).to.equal("assertionMethod");
|
|
571
|
+
expect(vp.proof.type).to.equal("ERC191Signature2023");
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
describe("VP creation with configured loader options", () => {
|
|
575
|
+
it("should create and sign a VP the same way didlib does", async () => {
|
|
576
|
+
const pkFromHex = privateKeyFromHex(
|
|
577
|
+
"22aabb811efca4e6f4748bd18a46b502fa85549df9fa07da649c0a148d7d5530",
|
|
578
|
+
);
|
|
579
|
+
const certPath = path.join(__dirname, 'cert.txt');
|
|
580
|
+
const cert = fs.readFileSync(certPath, 'utf8');
|
|
581
|
+
const configured = configureLoader({strict: '0', ca: cert});
|
|
582
|
+
expect(configured.rejectUnauthorized).to.equal(false);
|
|
583
|
+
expect(configured.ca).to.equal(cert);
|
|
584
|
+
const didRef = getSecpVerificationMethod(pkFromHex, diddoc);
|
|
585
|
+
const vp = await createErc1912023Vp(
|
|
586
|
+
pkFromHex,
|
|
587
|
+
vc,
|
|
588
|
+
"090jd4%000kjbndt!",
|
|
589
|
+
didRef,
|
|
590
|
+
);
|
|
591
|
+
expect(vp.proof.proofValue).to.equal(
|
|
592
|
+
"0xc0d2517bb2728cc8b213b6511e3b945800a1cf7806e58177117dec84fe0baf4631cad29e0424b8e122ee138605b785c3d17dc7fc5d117692b71527a8f330467e1b",
|
|
593
|
+
);
|
|
594
|
+
expect(vp.proof.challenge).to.equal(
|
|
595
|
+
"090jd4%000kjbndt!",
|
|
596
|
+
);
|
|
597
|
+
expect(vp.proof.proofPurpose).to.equal("assertionMethod");
|
|
598
|
+
expect(vp.proof.type).to.equal("ERC191Signature2023");
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
describe("VP creation with configured loader strict option", () => {
|
|
602
|
+
it("should create and sign a VP the same way didlib does", async () => {
|
|
603
|
+
const pkFromHex = privateKeyFromHex(
|
|
604
|
+
"22aabb811efca4e6f4748bd18a46b502fa85549df9fa07da649c0a148d7d5530",
|
|
605
|
+
);
|
|
606
|
+
const configured = configureLoader({strict: true});
|
|
607
|
+
expect(configured.rejectUnauthorized).to.equal(true);
|
|
608
|
+
const didRef = getSecpVerificationMethod(pkFromHex, diddoc);
|
|
609
|
+
const vp = await createErc1912023Vp(
|
|
610
|
+
pkFromHex,
|
|
611
|
+
vc,
|
|
612
|
+
"090jd4%000kjbndt!",
|
|
613
|
+
didRef,
|
|
614
|
+
);
|
|
615
|
+
expect(vp.proof.proofValue).to.equal(
|
|
616
|
+
"0xc0d2517bb2728cc8b213b6511e3b945800a1cf7806e58177117dec84fe0baf4631cad29e0424b8e122ee138605b785c3d17dc7fc5d117692b71527a8f330467e1b",
|
|
617
|
+
);
|
|
618
|
+
expect(vp.proof.challenge).to.equal(
|
|
619
|
+
"090jd4%000kjbndt!",
|
|
620
|
+
);
|
|
621
|
+
expect(vp.proof.proofPurpose).to.equal("assertionMethod");
|
|
622
|
+
expect(vp.proof.type).to.equal("ERC191Signature2023");
|
|
623
|
+
});
|
|
624
|
+
});
|
|
542
625
|
describe("Secp256k1", () => {
|
|
543
626
|
it("Should deterministically ECDSA sign 32 byte data", async () => {
|
|
544
627
|
const pkFromHex = privateKeyFromHex(
|