@notabene/verify-proof 1.11.1-next.1 → 1.12.0-next.2
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/concordium-QRNV23F7.js +45 -0
- package/dist/concordium-QRNV23F7.js.map +1 -0
- package/dist/concordium-YD34X2QM.cjs +47 -0
- package/dist/concordium-YD34X2QM.cjs.map +1 -0
- package/dist/index.cjs +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/concordium.ts +40 -284
- package/src/index.ts +0 -1
- package/src/tests/bitcoin.test.ts +335 -16
- package/src/tests/concordium.test.ts +96 -134
- package/src/tests/index.test.ts +7 -7
- package/dist/concordium-HQC37GCK.cjs +0 -188
- package/dist/concordium-HQC37GCK.cjs.map +0 -1
- package/dist/concordium-XX4XYLLU.js +0 -186
- package/dist/concordium-XX4XYLLU.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import './chunk-E3V5ATTC.js';
|
|
3
|
+
import { ProofStatus } from '@notabene/javascript-sdk';
|
|
4
|
+
import { ConcordiumGRPCWebClient, getPublicData, verifyPresentation } from '@concordium/web-sdk';
|
|
5
|
+
|
|
6
|
+
if (typeof globalThis !== 'undefined' && !globalThis.Buffer) { globalThis.Buffer = Buffer; }
|
|
7
|
+
var verifyConcordiumSignature = async (proof) => {
|
|
8
|
+
try {
|
|
9
|
+
const grpcWebClient = new ConcordiumGRPCWebClient(
|
|
10
|
+
"https://grpc.mainnet.concordium.software",
|
|
11
|
+
2e4
|
|
12
|
+
);
|
|
13
|
+
const presentationJson = JSON.parse(proof.proof);
|
|
14
|
+
if (presentationJson.presentationContext !== proof.attestation) {
|
|
15
|
+
throw new Error("Presentation context does not match attestation");
|
|
16
|
+
}
|
|
17
|
+
if (!presentationJson.verifiableCredential || presentationJson.verifiableCredential.length === 0) {
|
|
18
|
+
throw new Error("Verifiable credential is missing or empty");
|
|
19
|
+
}
|
|
20
|
+
const context = await grpcWebClient.getCryptographicParameters();
|
|
21
|
+
const publicData = await getPublicData(
|
|
22
|
+
grpcWebClient,
|
|
23
|
+
"Mainnet",
|
|
24
|
+
presentationJson
|
|
25
|
+
);
|
|
26
|
+
verifyPresentation(
|
|
27
|
+
presentationJson,
|
|
28
|
+
context,
|
|
29
|
+
publicData.map((p) => p.inputs)
|
|
30
|
+
);
|
|
31
|
+
return {
|
|
32
|
+
...proof,
|
|
33
|
+
status: ProofStatus.VERIFIED
|
|
34
|
+
};
|
|
35
|
+
} catch {
|
|
36
|
+
return {
|
|
37
|
+
...proof,
|
|
38
|
+
status: ProofStatus.FAILED
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { verifyConcordiumSignature };
|
|
44
|
+
//# sourceMappingURL=concordium-QRNV23F7.js.map
|
|
45
|
+
//# sourceMappingURL=concordium-QRNV23F7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/concordium.ts"],"names":[],"mappings":";;;;;;AAcO,IAAM,yBAAA,GAA4B,OACvC,KAAA,KAC4B;AAC5B,EAAA,IAAI;AAEF,IAAA,MAAM,gBAAgB,IAAI,uBAAA;AAAA,MACxB,0CAAA;AAAA,MACA;AAAA,KACF;AAGA,IAAA,MAAM,gBAAA,GAAmB,IAAA,CAAK,KAAA,CAAM,KAAA,CAAM,KAAK,CAAA;AAG/C,IAAA,IAAI,gBAAA,CAAiB,mBAAA,KAAwB,KAAA,CAAM,WAAA,EAAa;AAC9D,MAAA,MAAM,IAAI,MAAM,iDAAiD,CAAA;AAAA,IACnE;AAGA,IAAA,IACE,CAAC,gBAAA,CAAiB,oBAAA,IAClB,gBAAA,CAAiB,oBAAA,CAAqB,WAAW,CAAA,EACjD;AACA,MAAA,MAAM,IAAI,MAAM,2CAA2C,CAAA;AAAA,IAC7D;AAEA,IAAA,MAAM,OAAA,GAAU,MAAM,aAAA,CAAc,0BAAA,EAA2B;AAE/D,IAAA,MAAM,aAAa,MAAM,aAAA;AAAA,MACvB,aAAA;AAAA,MACA,SAAA;AAAA,MACA;AAAA,KACF;AAEA,IAAA,kBAAA;AAAA,MACE,gBAAA;AAAA,MACA,OAAA;AAAA,MACA,UAAA,CAAW,GAAA,CAAI,CAAC,CAAA,KAAM,EAAE,MAAM;AAAA,KAChC;AAEA,IAAA,OAAO;AAAA,MACL,GAAG,KAAA;AAAA,MACH,QAAQ,WAAA,CAAY;AAAA,KACtB;AAAA,EACF,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO;AAAA,MACL,GAAG,KAAA;AAAA,MACH,QAAQ,WAAA,CAAY;AAAA,KACtB;AAAA,EACF;AACF","file":"concordium-QRNV23F7.js","sourcesContent":["import { ProofStatus, SignatureProof } from \"@notabene/javascript-sdk\";\nimport {\n ConcordiumGRPCWebClient,\n verifyPresentation,\n VerifiablePresentation,\n getPublicData,\n} from \"@concordium/web-sdk\";\n\n/**\n * Verifies a Concordium signature proof with proper cryptographic validation\n * @param proof The signature proof to verify\n * @param options Optional configuration for network and timeouts\n * @returns Promise resolving to the proof with updated status\n */\nexport const verifyConcordiumSignature = async (\n proof: SignatureProof,\n): Promise<SignatureProof> => {\n try {\n // Merge with default options\n const grpcWebClient = new ConcordiumGRPCWebClient(\n \"https://grpc.mainnet.concordium.software\",\n 20000\n );\n\n // verifiable presentation parsed from proof\n const presentationJson = JSON.parse(proof.proof) as VerifiablePresentation;\n\n // Validate presentation context matches attestation\n if (presentationJson.presentationContext !== proof.attestation) {\n throw new Error(\"Presentation context does not match attestation\");\n }\n\n // Validate verifiableCredential exists and is not empty\n if (\n !presentationJson.verifiableCredential ||\n presentationJson.verifiableCredential.length === 0\n ) {\n throw new Error(\"Verifiable credential is missing or empty\");\n }\n\n const context = await grpcWebClient.getCryptographicParameters();\n\n const publicData = await getPublicData(\n grpcWebClient,\n \"Mainnet\",\n presentationJson\n );\n\n verifyPresentation(\n presentationJson,\n context,\n publicData.map((p) => p.inputs)\n );\n\n return {\n ...proof,\n status: ProofStatus.VERIFIED,\n };\n } catch {\n return {\n ...proof,\n status: ProofStatus.FAILED,\n };\n }\n};\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var buffer = require('buffer');
|
|
4
|
+
require('./chunk-OAXNH5XR.cjs');
|
|
5
|
+
var javascriptSdk = require('@notabene/javascript-sdk');
|
|
6
|
+
var webSdk = require('@concordium/web-sdk');
|
|
7
|
+
|
|
8
|
+
if (typeof globalThis !== 'undefined' && !globalThis.Buffer) { globalThis.Buffer = buffer.Buffer; }
|
|
9
|
+
var verifyConcordiumSignature = async (proof) => {
|
|
10
|
+
try {
|
|
11
|
+
const grpcWebClient = new webSdk.ConcordiumGRPCWebClient(
|
|
12
|
+
"https://grpc.mainnet.concordium.software",
|
|
13
|
+
2e4
|
|
14
|
+
);
|
|
15
|
+
const presentationJson = JSON.parse(proof.proof);
|
|
16
|
+
if (presentationJson.presentationContext !== proof.attestation) {
|
|
17
|
+
throw new Error("Presentation context does not match attestation");
|
|
18
|
+
}
|
|
19
|
+
if (!presentationJson.verifiableCredential || presentationJson.verifiableCredential.length === 0) {
|
|
20
|
+
throw new Error("Verifiable credential is missing or empty");
|
|
21
|
+
}
|
|
22
|
+
const context = await grpcWebClient.getCryptographicParameters();
|
|
23
|
+
const publicData = await webSdk.getPublicData(
|
|
24
|
+
grpcWebClient,
|
|
25
|
+
"Mainnet",
|
|
26
|
+
presentationJson
|
|
27
|
+
);
|
|
28
|
+
webSdk.verifyPresentation(
|
|
29
|
+
presentationJson,
|
|
30
|
+
context,
|
|
31
|
+
publicData.map((p) => p.inputs)
|
|
32
|
+
);
|
|
33
|
+
return {
|
|
34
|
+
...proof,
|
|
35
|
+
status: javascriptSdk.ProofStatus.VERIFIED
|
|
36
|
+
};
|
|
37
|
+
} catch {
|
|
38
|
+
return {
|
|
39
|
+
...proof,
|
|
40
|
+
status: javascriptSdk.ProofStatus.FAILED
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.verifyConcordiumSignature = verifyConcordiumSignature;
|
|
46
|
+
//# sourceMappingURL=concordium-YD34X2QM.cjs.map
|
|
47
|
+
//# sourceMappingURL=concordium-YD34X2QM.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/concordium.ts"],"names":["ConcordiumGRPCWebClient","getPublicData","verifyPresentation","ProofStatus"],"mappings":";;;;;;;;AAcO,IAAM,yBAAA,GAA4B,OACvC,KAAA,KAC4B;AAC5B,EAAA,IAAI;AAEF,IAAA,MAAM,gBAAgB,IAAIA,8BAAA;AAAA,MACxB,0CAAA;AAAA,MACA;AAAA,KACF;AAGA,IAAA,MAAM,gBAAA,GAAmB,IAAA,CAAK,KAAA,CAAM,KAAA,CAAM,KAAK,CAAA;AAG/C,IAAA,IAAI,gBAAA,CAAiB,mBAAA,KAAwB,KAAA,CAAM,WAAA,EAAa;AAC9D,MAAA,MAAM,IAAI,MAAM,iDAAiD,CAAA;AAAA,IACnE;AAGA,IAAA,IACE,CAAC,gBAAA,CAAiB,oBAAA,IAClB,gBAAA,CAAiB,oBAAA,CAAqB,WAAW,CAAA,EACjD;AACA,MAAA,MAAM,IAAI,MAAM,2CAA2C,CAAA;AAAA,IAC7D;AAEA,IAAA,MAAM,OAAA,GAAU,MAAM,aAAA,CAAc,0BAAA,EAA2B;AAE/D,IAAA,MAAM,aAAa,MAAMC,oBAAA;AAAA,MACvB,aAAA;AAAA,MACA,SAAA;AAAA,MACA;AAAA,KACF;AAEA,IAAAC,yBAAA;AAAA,MACE,gBAAA;AAAA,MACA,OAAA;AAAA,MACA,UAAA,CAAW,GAAA,CAAI,CAAC,CAAA,KAAM,EAAE,MAAM;AAAA,KAChC;AAEA,IAAA,OAAO;AAAA,MACL,GAAG,KAAA;AAAA,MACH,QAAQC,yBAAA,CAAY;AAAA,KACtB;AAAA,EACF,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO;AAAA,MACL,GAAG,KAAA;AAAA,MACH,QAAQA,yBAAA,CAAY;AAAA,KACtB;AAAA,EACF;AACF","file":"concordium-YD34X2QM.cjs","sourcesContent":["import { ProofStatus, SignatureProof } from \"@notabene/javascript-sdk\";\nimport {\n ConcordiumGRPCWebClient,\n verifyPresentation,\n VerifiablePresentation,\n getPublicData,\n} from \"@concordium/web-sdk\";\n\n/**\n * Verifies a Concordium signature proof with proper cryptographic validation\n * @param proof The signature proof to verify\n * @param options Optional configuration for network and timeouts\n * @returns Promise resolving to the proof with updated status\n */\nexport const verifyConcordiumSignature = async (\n proof: SignatureProof,\n): Promise<SignatureProof> => {\n try {\n // Merge with default options\n const grpcWebClient = new ConcordiumGRPCWebClient(\n \"https://grpc.mainnet.concordium.software\",\n 20000\n );\n\n // verifiable presentation parsed from proof\n const presentationJson = JSON.parse(proof.proof) as VerifiablePresentation;\n\n // Validate presentation context matches attestation\n if (presentationJson.presentationContext !== proof.attestation) {\n throw new Error(\"Presentation context does not match attestation\");\n }\n\n // Validate verifiableCredential exists and is not empty\n if (\n !presentationJson.verifiableCredential ||\n presentationJson.verifiableCredential.length === 0\n ) {\n throw new Error(\"Verifiable credential is missing or empty\");\n }\n\n const context = await grpcWebClient.getCryptographicParameters();\n\n const publicData = await getPublicData(\n grpcWebClient,\n \"Mainnet\",\n presentationJson\n );\n\n verifyPresentation(\n presentationJson,\n context,\n publicData.map((p) => p.inputs)\n );\n\n return {\n ...proof,\n status: ProofStatus.VERIFIED,\n };\n } catch {\n return {\n ...proof,\n status: ProofStatus.FAILED,\n };\n }\n};\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ async function verifyProof(proof, publicKey) {
|
|
|
42
42
|
return verifyStellarSignature(proof);
|
|
43
43
|
}
|
|
44
44
|
case javascriptSdk.ProofTypes.CONCORDIUM: {
|
|
45
|
-
const { verifyConcordiumSignature } = await import('./concordium-
|
|
45
|
+
const { verifyConcordiumSignature } = await import('./concordium-YD34X2QM.cjs');
|
|
46
46
|
return verifyConcordiumSignature(proof);
|
|
47
47
|
}
|
|
48
48
|
case javascriptSdk.ProofTypes.COSMOS: {
|
|
@@ -59,7 +59,6 @@ async function verifyProof(proof, publicKey) {
|
|
|
59
59
|
const { verifyPersonalSignTIP191 } = await import('./tron-F5AARBY4.cjs');
|
|
60
60
|
return verifyPersonalSignTIP191(proof);
|
|
61
61
|
}
|
|
62
|
-
case javascriptSdk.ProofTypes.BIP137_XPUB:
|
|
63
62
|
case javascriptSdk.ProofTypes.MicroTransfer:
|
|
64
63
|
}
|
|
65
64
|
return proof;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["ProofTypes","ProofStatus"],"mappings":";;;;;;;AAUA,eAAsB,WAAA,CACpB,OACA,SAAA,EACyB;AACzB,EAAA,QAAQ,MAAM,IAAA;AAAM,IAClB,KAAKA,wBAAA,CAAW,eAAA;AACd,MAAA,OAAO;AAAA,QACL,GAAG,KAAA;AAAA,QACH,MAAA,EAAS,KAAA,CAA2B,SAAA,GAChCC,yBAAA,CAAY,WACZA,yBAAA,CAAY;AAAA,OAClB;AAAA,IACF,KAAKD,wBAAA,CAAW,UAAA;AACd,MAAA,OAAO;AAAA,QACL,GAAG,KAAA;AAAA,QACH,MAAA,EAAS,KAAA,CAA0B,GAAA,GAC/BC,yBAAA,CAAY,UACZA,yBAAA,CAAY;AAAA,OAClB;AAAA,IACF,KAAKD,yBAAW,IAAA,EAAM;AACpB,MAAA,MAAM,EAAE,mBAAA,EAAoB,GAAI,MAAM,OAAO,wBAAW,CAAA;AACxD,MAAA,OAAO,oBAAoB,KAAuB,CAAA;AAAA,IACpD;AAAA,IACA,KAAKA,yBAAW,MAAA,EAAQ;AACtB,MAAA,MAAM,EAAE,wBAAA,EAAyB,GAAI,MAAM,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AA;AAElB,EAAA,OAAO,KAAA;AACT","file":"index.cjs","sourcesContent":["import {\n type OwnershipProof,\n SignatureProof,\n DeclarationProof,\n ScreenshotProof,\n ProofTypes,\n ProofStatus,\n} from \"@notabene/javascript-sdk\";\n\n// Use dynamic imports to ensure Buffer is available before loading crypto libraries\nexport async function verifyProof(\n proof: OwnershipProof,\n publicKey?: string,\n): Promise<OwnershipProof> {\n switch (proof.type) {\n case ProofTypes.SelfDeclaration:\n return {\n ...proof,\n status: (proof as DeclarationProof).confirmed\n ? ProofStatus.VERIFIED\n : ProofStatus.FAILED,\n };\n case ProofTypes.Screenshot:\n return {\n ...proof,\n status: (proof as ScreenshotProof).url\n ? ProofStatus.FLAGGED\n : ProofStatus.FAILED,\n };\n case ProofTypes.CIP8: {\n const { verifyCIP8Signature } = await import(\"./cardano\");\n return verifyCIP8Signature(proof as SignatureProof);\n }\n case ProofTypes.EIP191: {\n const { verifyPersonalSignEIP191 } = await import(\"./eth\");\n return verifyPersonalSignEIP191(proof as SignatureProof);\n }\n case ProofTypes.ED25519: {\n const { verifySolanaSignature } = await import(\"./solana\");\n return verifySolanaSignature(proof as SignatureProof);\n }\n case ProofTypes.SOL_SIWX: {\n const { verifySolanaSIWS } = await import(\"./solana\");\n return verifySolanaSIWS(proof as SignatureProof);\n }\n case ProofTypes.XRP_ED25519: {\n const { verifyPersonalSignXRPL } = await import(\"./xrpl\");\n return verifyPersonalSignXRPL(proof as SignatureProof, publicKey);\n }\n case ProofTypes.XLM_ED25519: {\n const { verifyStellarSignature } = await import(\"./xlm\");\n return verifyStellarSignature(proof as SignatureProof);\n }\n case ProofTypes.CONCORDIUM: {\n const { verifyConcordiumSignature } = await import(\"./concordium\");\n return verifyConcordiumSignature(proof as SignatureProof);\n }\n case ProofTypes.COSMOS: {\n const { verifyCosmosSignature } = await import(\"./cosmos\");\n return verifyCosmosSignature(proof as SignatureProof);\n }\n case ProofTypes.EIP712:\n case ProofTypes.BIP137:\n case ProofTypes.BIP322: {\n const { verifyBTCSignature } = await import(\"./bitcoin\");\n return verifyBTCSignature(proof as SignatureProof);\n }\n case ProofTypes.TIP191: {\n const { verifyPersonalSignTIP191 } = await import(\"./tron\");\n return verifyPersonalSignTIP191(proof as SignatureProof);\n }\n case ProofTypes.MicroTransfer:\n }\n return proof;\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ async function verifyProof(proof, publicKey) {
|
|
|
40
40
|
return verifyStellarSignature(proof);
|
|
41
41
|
}
|
|
42
42
|
case ProofTypes.CONCORDIUM: {
|
|
43
|
-
const { verifyConcordiumSignature } = await import('./concordium-
|
|
43
|
+
const { verifyConcordiumSignature } = await import('./concordium-QRNV23F7.js');
|
|
44
44
|
return verifyConcordiumSignature(proof);
|
|
45
45
|
}
|
|
46
46
|
case ProofTypes.COSMOS: {
|
|
@@ -57,7 +57,6 @@ async function verifyProof(proof, publicKey) {
|
|
|
57
57
|
const { verifyPersonalSignTIP191 } = await import('./tron-OBLPB2LN.js');
|
|
58
58
|
return verifyPersonalSignTIP191(proof);
|
|
59
59
|
}
|
|
60
|
-
case ProofTypes.BIP137_XPUB:
|
|
61
60
|
case ProofTypes.MicroTransfer:
|
|
62
61
|
}
|
|
63
62
|
return proof;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAUA,eAAsB,WAAA,CACpB,OACA,SAAA,EACyB;AACzB,EAAA,QAAQ,MAAM,IAAA;AAAM,IAClB,KAAK,UAAA,CAAW,eAAA;AACd,MAAA,OAAO;AAAA,QACL,GAAG,KAAA;AAAA,QACH,MAAA,EAAS,KAAA,CAA2B,SAAA,GAChC,WAAA,CAAY,WACZ,WAAA,CAAY;AAAA,OAClB;AAAA,IACF,KAAK,UAAA,CAAW,UAAA;AACd,MAAA,OAAO;AAAA,QACL,GAAG,KAAA;AAAA,QACH,MAAA,EAAS,KAAA,CAA0B,GAAA,GAC/B,WAA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,IACA,KAAK,WAAW,MAAA,EAAQ;AACtB,MAAA,MAAM,EAAE,wBAAA,EAAyB,GAAI,MAAM,OAAO,oBAAQ,CAAA;AAC1D,MAAA,OAAO,yBAAyB,KAAuB,CAAA;AAAA,IACzD;AAAA,IACA,KAAK,UAAA,CAAW,aAAA;AAAA;AAElB,EAAA,OAAO,KAAA;AACT","file":"index.js","sourcesContent":["import {\n type OwnershipProof,\n SignatureProof,\n DeclarationProof,\n ScreenshotProof,\n ProofTypes,\n ProofStatus,\n} from \"@notabene/javascript-sdk\";\n\n// Use dynamic imports to ensure Buffer is available before loading crypto libraries\nexport async function verifyProof(\n proof: OwnershipProof,\n publicKey?: string,\n): Promise<OwnershipProof> {\n switch (proof.type) {\n case ProofTypes.SelfDeclaration:\n return {\n ...proof,\n status: (proof as DeclarationProof).confirmed\n ? ProofStatus.VERIFIED\n : ProofStatus.FAILED,\n };\n case ProofTypes.Screenshot:\n return {\n ...proof,\n status: (proof as ScreenshotProof).url\n ? ProofStatus.FLAGGED\n : ProofStatus.FAILED,\n };\n case ProofTypes.CIP8: {\n const { verifyCIP8Signature } = await import(\"./cardano\");\n return verifyCIP8Signature(proof as SignatureProof);\n }\n case ProofTypes.EIP191: {\n const { verifyPersonalSignEIP191 } = await import(\"./eth\");\n return verifyPersonalSignEIP191(proof as SignatureProof);\n }\n case ProofTypes.ED25519: {\n const { verifySolanaSignature } = await import(\"./solana\");\n return verifySolanaSignature(proof as SignatureProof);\n }\n case ProofTypes.SOL_SIWX: {\n const { verifySolanaSIWS } = await import(\"./solana\");\n return verifySolanaSIWS(proof as SignatureProof);\n }\n case ProofTypes.XRP_ED25519: {\n const { verifyPersonalSignXRPL } = await import(\"./xrpl\");\n return verifyPersonalSignXRPL(proof as SignatureProof, publicKey);\n }\n case ProofTypes.XLM_ED25519: {\n const { verifyStellarSignature } = await import(\"./xlm\");\n return verifyStellarSignature(proof as SignatureProof);\n }\n case ProofTypes.CONCORDIUM: {\n const { verifyConcordiumSignature } = await import(\"./concordium\");\n return verifyConcordiumSignature(proof as SignatureProof);\n }\n case ProofTypes.COSMOS: {\n const { verifyCosmosSignature } = await import(\"./cosmos\");\n return verifyCosmosSignature(proof as SignatureProof);\n }\n case ProofTypes.EIP712:\n case ProofTypes.BIP137:\n case ProofTypes.BIP322: {\n const { verifyBTCSignature } = await import(\"./bitcoin\");\n return verifyBTCSignature(proof as SignatureProof);\n }\n case ProofTypes.TIP191: {\n const { verifyPersonalSignTIP191 } = await import(\"./tron\");\n return verifyPersonalSignTIP191(proof as SignatureProof);\n }\n case ProofTypes.MicroTransfer:\n }\n return proof;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notabene/verify-proof",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0-next.2",
|
|
4
4
|
"description": "Verify ownership proofs",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@cardano-foundation/cardano-verify-datasignature": "^1.0.11",
|
|
55
|
+
"@concordium/web-sdk": "^11.0.0",
|
|
55
56
|
"@cosmjs/amino": "^0.34.0",
|
|
56
57
|
"@noble/curves": "^1.7.0",
|
|
57
58
|
"@notabene/javascript-sdk": "2.11.0-next.2",
|
package/src/concordium.ts
CHANGED
|
@@ -1,42 +1,10 @@
|
|
|
1
1
|
import { ProofStatus, SignatureProof } from "@notabene/javascript-sdk";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const NETWORKS: Record<string, ConcordiumNetwork> = {
|
|
10
|
-
testnet: {
|
|
11
|
-
grpcUrl: "https://grpc.testnet.concordium.com:20000",
|
|
12
|
-
walletProxyUrl: "https://wallet-proxy.testnet.concordium.com"
|
|
13
|
-
},
|
|
14
|
-
mainnet: {
|
|
15
|
-
grpcUrl: "https://grpc.mainnet.concordium.com:20000",
|
|
16
|
-
walletProxyUrl: "https://wallet-proxy.mainnet.concordium.software"
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// Configuration options for verification
|
|
21
|
-
interface ConcordiumVerificationOptions {
|
|
22
|
-
network?: "testnet" | "mainnet";
|
|
23
|
-
timeout?: number; // timeout in milliseconds
|
|
24
|
-
retries?: number; // number of retry attempts
|
|
25
|
-
testMode?: boolean; // skip network calls for testing
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Signature object type
|
|
29
|
-
interface ConcordiumSignature {
|
|
30
|
-
[key: string]: string | ConcordiumSignature;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Default options
|
|
34
|
-
const DEFAULT_OPTIONS: Required<ConcordiumVerificationOptions> = {
|
|
35
|
-
network: "testnet",
|
|
36
|
-
timeout: 50000, // 10 seconds
|
|
37
|
-
retries: 3,
|
|
38
|
-
testMode: true
|
|
39
|
-
};
|
|
2
|
+
import {
|
|
3
|
+
ConcordiumGRPCWebClient,
|
|
4
|
+
verifyPresentation,
|
|
5
|
+
VerifiablePresentation,
|
|
6
|
+
getPublicData,
|
|
7
|
+
} from "@concordium/web-sdk";
|
|
40
8
|
|
|
41
9
|
/**
|
|
42
10
|
* Verifies a Concordium signature proof with proper cryptographic validation
|
|
@@ -46,264 +14,52 @@ const DEFAULT_OPTIONS: Required<ConcordiumVerificationOptions> = {
|
|
|
46
14
|
*/
|
|
47
15
|
export const verifyConcordiumSignature = async (
|
|
48
16
|
proof: SignatureProof,
|
|
49
|
-
options: ConcordiumVerificationOptions = {}
|
|
50
17
|
): Promise<SignatureProof> => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return { ...proof, status: ProofStatus.FAILED };
|
|
58
|
-
}
|
|
18
|
+
try {
|
|
19
|
+
// Merge with default options
|
|
20
|
+
const grpcWebClient = new ConcordiumGRPCWebClient(
|
|
21
|
+
"https://grpc.mainnet.concordium.software",
|
|
22
|
+
20000
|
|
23
|
+
);
|
|
59
24
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (networkId) {
|
|
63
|
-
// If network ID is specified in address, use it to determine network
|
|
64
|
-
network = networkId.includes("testnet") ? "testnet" : "mainnet";
|
|
65
|
-
}
|
|
25
|
+
// verifiable presentation parsed from proof
|
|
26
|
+
const presentationJson = JSON.parse(proof.proof) as VerifiablePresentation;
|
|
66
27
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
signature = JSON.parse(proof.proof) as ConcordiumSignature;
|
|
72
|
-
} catch {
|
|
73
|
-
return { ...proof, status: ProofStatus.FAILED };
|
|
28
|
+
// Validate presentation context matches attestation
|
|
29
|
+
if (presentationJson.presentationContext !== proof.attestation) {
|
|
30
|
+
throw new Error("Presentation context does not match attestation");
|
|
74
31
|
}
|
|
75
32
|
|
|
76
|
-
//
|
|
77
|
-
if (
|
|
78
|
-
|
|
33
|
+
// Validate verifiableCredential exists and is not empty
|
|
34
|
+
if (
|
|
35
|
+
!presentationJson.verifiableCredential ||
|
|
36
|
+
presentationJson.verifiableCredential.length === 0
|
|
37
|
+
) {
|
|
38
|
+
throw new Error("Verifiable credential is missing or empty");
|
|
79
39
|
}
|
|
80
40
|
|
|
81
|
-
|
|
82
|
-
if (config.testMode) {
|
|
83
|
-
// Perform signature format validation
|
|
84
|
-
try {
|
|
85
|
-
const signatureHex = convertSignatureToHex(signature);
|
|
86
|
-
|
|
87
|
-
// Validate signature format
|
|
88
|
-
if (!signatureHex || signatureHex.length < 64 || !/^[0-9a-fA-F]+$/.test(signatureHex)) {
|
|
89
|
-
return { ...proof, status: ProofStatus.FAILED };
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return { ...proof, status: ProofStatus.VERIFIED };
|
|
93
|
-
|
|
94
|
-
} catch {
|
|
95
|
-
return { ...proof, status: ProofStatus.FAILED };
|
|
96
|
-
}
|
|
97
|
-
}
|
|
41
|
+
const context = await grpcWebClient.getCryptographicParameters();
|
|
98
42
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
43
|
+
const publicData = await getPublicData(
|
|
44
|
+
grpcWebClient,
|
|
45
|
+
"Mainnet",
|
|
46
|
+
presentationJson
|
|
103
47
|
);
|
|
104
48
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// Perform cryptographic signature verification
|
|
110
|
-
const isValidSignature = await retryWithTimeout(
|
|
111
|
-
() => verifyCryptographicSignature(
|
|
112
|
-
signature,
|
|
113
|
-
config.timeout,
|
|
114
|
-
// proof.attestation,
|
|
115
|
-
// address,
|
|
116
|
-
// network
|
|
117
|
-
),
|
|
118
|
-
config.retries
|
|
49
|
+
verifyPresentation(
|
|
50
|
+
presentationJson,
|
|
51
|
+
context,
|
|
52
|
+
publicData.map((p) => p.inputs)
|
|
119
53
|
);
|
|
120
54
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
55
|
+
return {
|
|
56
|
+
...proof,
|
|
57
|
+
status: ProofStatus.VERIFIED,
|
|
58
|
+
};
|
|
127
59
|
} catch {
|
|
128
|
-
return {
|
|
60
|
+
return {
|
|
61
|
+
...proof,
|
|
62
|
+
status: ProofStatus.FAILED,
|
|
63
|
+
};
|
|
129
64
|
}
|
|
130
65
|
};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Validates that a Concordium account exists and retrieves account information
|
|
134
|
-
*/
|
|
135
|
-
async function validateAccountAndGetInfo(
|
|
136
|
-
address: string,
|
|
137
|
-
network: "testnet" | "mainnet",
|
|
138
|
-
timeout: number
|
|
139
|
-
): Promise<boolean> {
|
|
140
|
-
const networkConfig = NETWORKS[network];
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
// Check account existence via wallet proxy (faster than gRPC for existence check)
|
|
144
|
-
const controller = new AbortController();
|
|
145
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
146
|
-
|
|
147
|
-
const response = await fetch(
|
|
148
|
-
`${networkConfig.walletProxyUrl}/v0/accEncryptionKey/${address}`,
|
|
149
|
-
{
|
|
150
|
-
method: 'GET',
|
|
151
|
-
headers: {
|
|
152
|
-
'Accept': 'application/json',
|
|
153
|
-
'User-Agent': 'verify-proof/1.6.0'
|
|
154
|
-
},
|
|
155
|
-
signal: controller.signal
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
clearTimeout(timeoutId);
|
|
160
|
-
return response.ok;
|
|
161
|
-
|
|
162
|
-
} catch (error) {
|
|
163
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
164
|
-
throw new Error(`Account validation timeout after ${timeout}ms`);
|
|
165
|
-
}
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Performs cryptographic verification of the signature using Concordium SDK
|
|
172
|
-
* For production use, this would use the actual Concordium SDK verification methods
|
|
173
|
-
* Currently implementing a comprehensive validation approach
|
|
174
|
-
*/
|
|
175
|
-
async function verifyCryptographicSignature(
|
|
176
|
-
signature: ConcordiumSignature,
|
|
177
|
-
timeout: number,
|
|
178
|
-
// message?: string, // intentionally left out for now. Will enable for mainnet.
|
|
179
|
-
// address?: string,
|
|
180
|
-
// network?: "testnet" | "mainnet"
|
|
181
|
-
): Promise<boolean> {
|
|
182
|
-
try {
|
|
183
|
-
// Convert signature format for verification
|
|
184
|
-
const signatureHex = convertSignatureToHex(signature);
|
|
185
|
-
|
|
186
|
-
// For production, implement proper signature verification
|
|
187
|
-
// This is a placeholder for the actual SDK verification
|
|
188
|
-
// The exact method depends on the available SDK version
|
|
189
|
-
|
|
190
|
-
// Validate that we have a proper signature hex string
|
|
191
|
-
if (!signatureHex || signatureHex.length < 64) {
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// For now, return true if we have a valid signature structure
|
|
196
|
-
// In production, this should call the actual SDK verification method
|
|
197
|
-
// Example:
|
|
198
|
-
// const client = new ConcordiumGRPCNodeClient(networkConfig.grpcUrl, 20000, credentials.createInsecure(), { timeout });
|
|
199
|
-
// const result = await client.verifyAccountSignature(address, message, signatureHex);
|
|
200
|
-
|
|
201
|
-
// Placeholder validation - replace with actual SDK call
|
|
202
|
-
return signatureHex.length >= 64 && /^[0-9a-fA-F]+$/.test(signatureHex);
|
|
203
|
-
|
|
204
|
-
} catch (error) {
|
|
205
|
-
// Handle specific error types
|
|
206
|
-
if (error instanceof Error) {
|
|
207
|
-
if (error.message?.includes("timeout")) {
|
|
208
|
-
throw new Error(`Signature verification timeout after ${timeout}ms`);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (error.message?.includes("UNAVAILABLE")) {
|
|
212
|
-
throw new Error("Concordium node unavailable");
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (error.message?.includes("NOT_FOUND")) {
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
throw error;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Converts the signature object to the format expected by Concordium SDK
|
|
226
|
-
*/
|
|
227
|
-
function convertSignatureToHex(signature: ConcordiumSignature): string {
|
|
228
|
-
try {
|
|
229
|
-
// Handle different signature formats
|
|
230
|
-
if (typeof signature === 'string') {
|
|
231
|
-
return signature;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Handle nested signature object format (common from wallet)
|
|
235
|
-
if (signature && typeof signature === 'object') {
|
|
236
|
-
// Extract signature from nested structure
|
|
237
|
-
const extractSignature = (obj: ConcordiumSignature): string | null => {
|
|
238
|
-
if (typeof obj === 'string') {
|
|
239
|
-
return obj;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (obj && typeof obj === 'object') {
|
|
243
|
-
for (const key in obj) {
|
|
244
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
245
|
-
const value = obj[key];
|
|
246
|
-
if (typeof value === 'string') {
|
|
247
|
-
return value;
|
|
248
|
-
} else if (typeof value === 'object') {
|
|
249
|
-
const result = extractSignature(value);
|
|
250
|
-
if (result) return result;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return null;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
const extractedSig = extractSignature(signature);
|
|
260
|
-
if (extractedSig) {
|
|
261
|
-
return extractedSig;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
throw new Error("Unable to extract signature from object");
|
|
266
|
-
|
|
267
|
-
} catch (error) {
|
|
268
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
269
|
-
throw new Error(`Invalid signature format: ${errorMessage}`);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Utility function to retry operations with exponential backoff
|
|
275
|
-
*/
|
|
276
|
-
async function retryWithTimeout<T>(
|
|
277
|
-
operation: () => Promise<T>,
|
|
278
|
-
maxRetries: number
|
|
279
|
-
): Promise<T> {
|
|
280
|
-
let lastError: Error = new Error("No attempts made");
|
|
281
|
-
|
|
282
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
283
|
-
try {
|
|
284
|
-
return await operation();
|
|
285
|
-
} catch (error) {
|
|
286
|
-
const errorInstance = error instanceof Error ? error : new Error(String(error));
|
|
287
|
-
lastError = errorInstance;
|
|
288
|
-
|
|
289
|
-
// Don't retry on certain types of errors
|
|
290
|
-
if (
|
|
291
|
-
errorInstance.message?.includes("Invalid signature") ||
|
|
292
|
-
errorInstance.message?.includes("Account not found")
|
|
293
|
-
) {
|
|
294
|
-
throw errorInstance;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// Don't retry on the last attempt
|
|
298
|
-
if (attempt === maxRetries) {
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Exponential backoff: wait 2^attempt * 1000ms
|
|
303
|
-
const delay = Math.min(Math.pow(2, attempt) * 1000, 5000);
|
|
304
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
throw lastError;
|
|
309
|
-
}
|
package/src/index.ts
CHANGED