@notabene/verify-proof 1.11.0 → 1.12.0-next.12
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/README.md +21 -15
- package/dist/cjs/bitcoin-UIEQV3IM.cjs +403 -0
- package/dist/cjs/bitcoin-UIEQV3IM.cjs.map +1 -0
- package/dist/cjs/cardano-QG2S452K.cjs +36 -0
- package/dist/cjs/cardano-QG2S452K.cjs.map +1 -0
- package/dist/cjs/concordium-4B33UJJ5.cjs +44 -0
- package/dist/cjs/concordium-4B33UJJ5.cjs.map +1 -0
- package/dist/cjs/cosmos-JTT3AZCF.cjs +92 -0
- package/dist/cjs/cosmos-JTT3AZCF.cjs.map +1 -0
- package/dist/cjs/eth-BVXX47HH.cjs +36 -0
- package/dist/cjs/eth-BVXX47HH.cjs.map +1 -0
- package/dist/cjs/index.cjs +68 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +5 -0
- package/dist/cjs/solana-4WNBEQSU.cjs +348 -0
- package/dist/cjs/solana-4WNBEQSU.cjs.map +1 -0
- package/dist/cjs/tron-IM2O2VLM.cjs +57 -0
- package/dist/cjs/tron-IM2O2VLM.cjs.map +1 -0
- package/dist/cjs/xlm-CHT7RN4Z.cjs +27 -0
- package/dist/cjs/xlm-CHT7RN4Z.cjs.map +1 -0
- package/dist/cjs/xrpl-HJ2XWSOO.cjs +74 -0
- package/dist/cjs/xrpl-HJ2XWSOO.cjs.map +1 -0
- package/dist/esm/bitcoin-BTZ4TXEK.js +401 -0
- package/dist/esm/bitcoin-BTZ4TXEK.js.map +1 -0
- package/dist/esm/cardano-OMGAPH5N.js +30 -0
- package/dist/esm/cardano-OMGAPH5N.js.map +1 -0
- package/dist/esm/concordium-JJ5VEIOA.js +42 -0
- package/dist/esm/concordium-JJ5VEIOA.js.map +1 -0
- package/dist/esm/cosmos-AVIWAIX7.js +90 -0
- package/dist/esm/cosmos-AVIWAIX7.js.map +1 -0
- package/dist/esm/eth-GI4Z5V4T.js +33 -0
- package/dist/esm/eth-GI4Z5V4T.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +66 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/solana-ZARDAF6O.js +341 -0
- package/dist/esm/solana-ZARDAF6O.js.map +1 -0
- package/dist/esm/tron-FI2B6DRS.js +52 -0
- package/dist/esm/tron-FI2B6DRS.js.map +1 -0
- package/dist/esm/xlm-TNRZ5CFC.js +25 -0
- package/dist/esm/xlm-TNRZ5CFC.js.map +1 -0
- package/dist/esm/xrpl-52IBJ4EW.js +69 -0
- package/dist/esm/xrpl-52IBJ4EW.js.map +1 -0
- package/package.json +27 -6
- package/src/bitcoin.ts +43 -19
- package/src/cashaddr.ts +157 -0
- package/src/concordium.ts +34 -283
- package/src/cosmos.ts +44 -6
- package/src/index.ts +31 -20
- package/src/tests/bitcoin.test.ts +527 -16
- package/src/tests/concordium.test.ts +96 -134
- package/src/tests/cosmos.test.ts +139 -0
- package/src/tests/index.test.ts +7 -7
- package/src/tests/solana.test.ts +1 -1
- package/src/tests/xrpl.test.ts +8 -6
- package/dist/bitcoin.d.ts +0 -2
- package/dist/cardano.d.ts +0 -2
- package/dist/concordium.d.ts +0 -15
- package/dist/cosmos.d.ts +0 -2
- package/dist/eth.d.ts +0 -4
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/solana.d.ts +0 -17
- package/dist/tests/bitcoin.test.d.ts +0 -1
- package/dist/tests/cardano.test.d.ts +0 -1
- package/dist/tests/concordium.test.d.ts +0 -1
- package/dist/tests/cosmos.test.d.ts +0 -1
- package/dist/tests/eth.test.d.ts +0 -1
- package/dist/tests/index.test.d.ts +0 -1
- package/dist/tests/solana.test.d.ts +0 -1
- package/dist/tests/tron.test.d.ts +0 -1
- package/dist/tests/xlm.test.d.ts +0 -1
- package/dist/tests/xrpl.test.d.ts +0 -1
- package/dist/tron.d.ts +0 -6
- package/dist/xlm.d.ts +0 -2
- package/dist/xrpl.d.ts +0 -5
package/src/concordium.ts
CHANGED
|
@@ -1,309 +1,60 @@
|
|
|
1
1
|
import { ProofStatus, SignatureProof } from "@notabene/javascript-sdk";
|
|
2
|
+
import { VerifiablePresentation } from "@concordium/web-sdk";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
grpcUrl: string;
|
|
6
|
-
walletProxyUrl: string;
|
|
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
|
-
};
|
|
4
|
+
const CONCORDIUM_VERIFIER_URL =
|
|
5
|
+
"https://web3id-verifier.mainnet.concordium.software";
|
|
40
6
|
|
|
41
7
|
/**
|
|
42
|
-
* Verifies a Concordium signature proof
|
|
8
|
+
* Verifies a Concordium signature proof using Concordium's hosted verifier service
|
|
43
9
|
* @param proof The signature proof to verify
|
|
44
|
-
* @param options Optional configuration for network and timeouts
|
|
45
10
|
* @returns Promise resolving to the proof with updated status
|
|
46
11
|
*/
|
|
47
12
|
export const verifyConcordiumSignature = async (
|
|
48
13
|
proof: SignatureProof,
|
|
49
|
-
options: ConcordiumVerificationOptions = {}
|
|
50
14
|
): Promise<SignatureProof> => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// Parse and validate address format
|
|
55
|
-
const [ns, networkId, address] = proof.address.split(/:/);
|
|
15
|
+
const [ns] = proof.address.split(/:/);
|
|
16
|
+
|
|
56
17
|
if (ns !== "ccd") {
|
|
57
18
|
return { ...proof, status: ProofStatus.FAILED };
|
|
58
19
|
}
|
|
59
20
|
|
|
60
|
-
// Determine network from address or use config
|
|
61
|
-
let network = config.network;
|
|
62
|
-
if (networkId) {
|
|
63
|
-
// If network ID is specified in address, use it to determine network
|
|
64
|
-
network = networkId.includes("testnet") ? "testnet" : "mainnet";
|
|
65
|
-
}
|
|
66
|
-
|
|
67
21
|
try {
|
|
68
|
-
|
|
69
|
-
let signature: ConcordiumSignature;
|
|
70
|
-
try {
|
|
71
|
-
signature = JSON.parse(proof.proof) as ConcordiumSignature;
|
|
72
|
-
} catch {
|
|
73
|
-
return { ...proof, status: ProofStatus.FAILED };
|
|
74
|
-
}
|
|
22
|
+
const presentationJson = JSON.parse(proof.proof) as VerifiablePresentation;
|
|
75
23
|
|
|
76
|
-
//
|
|
77
|
-
if (
|
|
78
|
-
|
|
24
|
+
// Validate presentation context matches attestation
|
|
25
|
+
if (presentationJson.presentationContext !== proof.attestation) {
|
|
26
|
+
throw new Error("Presentation context does not match attestation");
|
|
79
27
|
}
|
|
80
28
|
|
|
81
|
-
//
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
}
|
|
98
|
-
|
|
99
|
-
// Production mode: validate account existence and get account info with retry logic
|
|
100
|
-
const accountInfo = await retryWithTimeout(
|
|
101
|
-
() => validateAccountAndGetInfo(address, network, config.timeout),
|
|
102
|
-
config.retries
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
if (!accountInfo) {
|
|
106
|
-
return { ...proof, status: ProofStatus.FAILED };
|
|
29
|
+
// Validate verifiableCredential exists and is not empty
|
|
30
|
+
if (
|
|
31
|
+
!presentationJson.verifiableCredential ||
|
|
32
|
+
presentationJson.verifiableCredential.length === 0
|
|
33
|
+
) {
|
|
34
|
+
throw new Error("Verifiable credential is missing or empty");
|
|
107
35
|
}
|
|
108
36
|
|
|
109
|
-
//
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// address,
|
|
116
|
-
// network
|
|
117
|
-
),
|
|
118
|
-
config.retries
|
|
119
|
-
);
|
|
37
|
+
// Use Concordium's hosted verifier instead of gRPC
|
|
38
|
+
const response = await fetch(`${CONCORDIUM_VERIFIER_URL}/v0/verify`, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { "Content-Type": "application/json" },
|
|
41
|
+
body: JSON.stringify(presentationJson),
|
|
42
|
+
});
|
|
120
43
|
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return { ...proof, status: ProofStatus.FAILED };
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
const errorText = await response.text();
|
|
46
|
+
throw new Error(`Verifier returned ${response.status}: ${errorText}`);
|
|
125
47
|
}
|
|
126
48
|
|
|
49
|
+
// If we get here, the proof is valid
|
|
50
|
+
return {
|
|
51
|
+
...proof,
|
|
52
|
+
status: ProofStatus.VERIFIED,
|
|
53
|
+
};
|
|
127
54
|
} catch {
|
|
128
|
-
return {
|
|
55
|
+
return {
|
|
56
|
+
...proof,
|
|
57
|
+
status: ProofStatus.FAILED,
|
|
58
|
+
};
|
|
129
59
|
}
|
|
130
60
|
};
|
|
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/cosmos.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { StdSignDoc, serializeSignDoc } from "@cosmjs/amino";
|
|
|
8
8
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
9
9
|
import { ripemd160 } from "@noble/hashes/legacy";
|
|
10
10
|
import { sha256 } from "@noble/hashes/sha2";
|
|
11
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
11
12
|
|
|
12
13
|
// Base64 decode
|
|
13
14
|
function base64ToUint8Array(base64: string): Uint8Array {
|
|
@@ -26,12 +27,47 @@ function toBase64Bytes(str: string): string {
|
|
|
26
27
|
|
|
27
28
|
// Cosmos address derivation (ADR-36)
|
|
28
29
|
// https://github.com/cosmos/cosmos-sdk/blob/214b11dcbaa129f7b4c0013b2103db9d54b85e9e/docs/architecture/adr-036-arbitrary-signature.md
|
|
29
|
-
function deriveCosmosAddress(pubkey: Uint8Array, prefix
|
|
30
|
+
function deriveCosmosAddress(pubkey: Uint8Array, prefix: string): string {
|
|
30
31
|
const sha = sha256(pubkey);
|
|
31
32
|
const rip = ripemd160(sha);
|
|
32
33
|
return bech32.encode(prefix, bech32.toWords(rip));
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
// Ethermint-style chains (Injective, Evmos, ...) use eth-secp256k1 keys: the account is
|
|
37
|
+
// the Ethereum address of the key, bech32-encoded under the chain prefix.
|
|
38
|
+
function deriveEthAddress(pubkey: Uint8Array, prefix: string): string {
|
|
39
|
+
const uncompressed = secp256k1.ProjectivePoint.fromHex(pubkey)
|
|
40
|
+
.toRawBytes(false)
|
|
41
|
+
.slice(1);
|
|
42
|
+
const eth = keccak_256(uncompressed).slice(-20);
|
|
43
|
+
return bech32.encode(prefix, bech32.toWords(eth));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Same selection Keplr's verifyADR36AminoSignDoc makes via its `algo` argument. The signed
|
|
47
|
+
// address tells us which key algorithm the chain uses, so we do not depend on the
|
|
48
|
+
// pub_key.type string wallets put in the amino signature.
|
|
49
|
+
type CosmosKeyAlgo = "secp256k1" | "ethsecp256k1";
|
|
50
|
+
|
|
51
|
+
function keyAlgoForAddress(
|
|
52
|
+
pubkey: Uint8Array,
|
|
53
|
+
address: string
|
|
54
|
+
): CosmosKeyAlgo | undefined {
|
|
55
|
+
const prefix = bech32Prefix(address);
|
|
56
|
+
if (deriveCosmosAddress(pubkey, prefix) === address) {
|
|
57
|
+
return "secp256k1";
|
|
58
|
+
}
|
|
59
|
+
if (deriveEthAddress(pubkey, prefix) === address) {
|
|
60
|
+
return "ethsecp256k1";
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Each Cosmos SDK chain has its own human-readable part (cosmos, celestia, axelar, ...),
|
|
66
|
+
// and bech32 separates it from the data with the last "1" in the string.
|
|
67
|
+
function bech32Prefix(address: string): string {
|
|
68
|
+
return address.slice(0, address.lastIndexOf("1"));
|
|
69
|
+
}
|
|
70
|
+
|
|
35
71
|
export async function verifyCosmosSignature(
|
|
36
72
|
proof: SignatureProof
|
|
37
73
|
): Promise<SignatureProof> {
|
|
@@ -47,9 +83,10 @@ export async function verifyCosmosSignature(
|
|
|
47
83
|
);
|
|
48
84
|
const signatureBytes = base64ToUint8Array(proof.proof);
|
|
49
85
|
|
|
50
|
-
// Step 1:
|
|
51
|
-
|
|
52
|
-
|
|
86
|
+
// Step 1: The pubkey must derive to the signed address; which derivation matches
|
|
87
|
+
// also decides the digest used in step 3.
|
|
88
|
+
const algo = keyAlgoForAddress(pubKeyBytes, address);
|
|
89
|
+
if (!algo) {
|
|
53
90
|
return { ...proof, status: ProofStatus.FAILED };
|
|
54
91
|
}
|
|
55
92
|
|
|
@@ -71,9 +108,10 @@ export async function verifyCosmosSignature(
|
|
|
71
108
|
memo: "",
|
|
72
109
|
};
|
|
73
110
|
|
|
74
|
-
// Step 3: Serialize + hash
|
|
111
|
+
// Step 3: Serialize + hash (ADR-036 digests are keccak256 on eth-secp256k1 chains)
|
|
75
112
|
const signBytes = await serializeSignDoc(signDoc);
|
|
76
|
-
const digest =
|
|
113
|
+
const digest =
|
|
114
|
+
algo === "ethsecp256k1" ? keccak_256(signBytes) : sha256(signBytes);
|
|
77
115
|
|
|
78
116
|
// Step 4: Verify using secp256k1
|
|
79
117
|
const verified = secp256k1.verify(signatureBytes, digest, pubKeyBytes);
|
package/src/index.ts
CHANGED
|
@@ -6,16 +6,8 @@ import {
|
|
|
6
6
|
ProofTypes,
|
|
7
7
|
ProofStatus,
|
|
8
8
|
} from "@notabene/javascript-sdk";
|
|
9
|
-
import { verifyBTCSignature } from "./bitcoin";
|
|
10
|
-
import { verifyPersonalSignEIP191 } from "./eth";
|
|
11
|
-
import { verifySolanaSignature, verifySolanaSIWS } from "./solana";
|
|
12
|
-
import { verifyPersonalSignTIP191 } from "./tron";
|
|
13
|
-
import { verifyCIP8Signature } from "./cardano";
|
|
14
|
-
import { verifyPersonalSignXRPL } from "./xrpl";
|
|
15
|
-
import { verifyStellarSignature } from "./xlm";
|
|
16
|
-
import { verifyConcordiumSignature } from "./concordium";
|
|
17
|
-
import { verifyCosmosSignature } from "./cosmos";
|
|
18
9
|
|
|
10
|
+
// Use dynamic imports to ensure Buffer is available before loading crypto libraries
|
|
19
11
|
export async function verifyProof(
|
|
20
12
|
proof: OwnershipProof,
|
|
21
13
|
publicKey?: string,
|
|
@@ -35,29 +27,48 @@ export async function verifyProof(
|
|
|
35
27
|
? ProofStatus.FLAGGED
|
|
36
28
|
: ProofStatus.FAILED,
|
|
37
29
|
};
|
|
38
|
-
case ProofTypes.CIP8:
|
|
30
|
+
case ProofTypes.CIP8: {
|
|
31
|
+
const { verifyCIP8Signature } = await import("./cardano");
|
|
39
32
|
return verifyCIP8Signature(proof as SignatureProof);
|
|
40
|
-
|
|
33
|
+
}
|
|
34
|
+
case ProofTypes.EIP191: {
|
|
35
|
+
const { verifyPersonalSignEIP191 } = await import("./eth");
|
|
41
36
|
return verifyPersonalSignEIP191(proof as SignatureProof);
|
|
42
|
-
|
|
37
|
+
}
|
|
38
|
+
case ProofTypes.ED25519: {
|
|
39
|
+
const { verifySolanaSignature } = await import("./solana");
|
|
43
40
|
return verifySolanaSignature(proof as SignatureProof);
|
|
44
|
-
|
|
41
|
+
}
|
|
42
|
+
case ProofTypes.SOL_SIWX: {
|
|
43
|
+
const { verifySolanaSIWS } = await import("./solana");
|
|
45
44
|
return verifySolanaSIWS(proof as SignatureProof);
|
|
46
|
-
|
|
45
|
+
}
|
|
46
|
+
case ProofTypes.XRP_ED25519: {
|
|
47
|
+
const { verifyPersonalSignXRPL } = await import("./xrpl");
|
|
47
48
|
return verifyPersonalSignXRPL(proof as SignatureProof, publicKey);
|
|
48
|
-
|
|
49
|
+
}
|
|
50
|
+
case ProofTypes.XLM_ED25519: {
|
|
51
|
+
const { verifyStellarSignature } = await import("./xlm");
|
|
49
52
|
return verifyStellarSignature(proof as SignatureProof);
|
|
50
|
-
|
|
53
|
+
}
|
|
54
|
+
case ProofTypes.CONCORDIUM: {
|
|
55
|
+
const { verifyConcordiumSignature } = await import("./concordium");
|
|
51
56
|
return verifyConcordiumSignature(proof as SignatureProof);
|
|
52
|
-
|
|
57
|
+
}
|
|
58
|
+
case ProofTypes.COSMOS: {
|
|
59
|
+
const { verifyCosmosSignature } = await import("./cosmos");
|
|
53
60
|
return verifyCosmosSignature(proof as SignatureProof);
|
|
61
|
+
}
|
|
54
62
|
case ProofTypes.EIP712:
|
|
55
63
|
case ProofTypes.BIP137:
|
|
56
|
-
case ProofTypes.BIP322:
|
|
64
|
+
case ProofTypes.BIP322: {
|
|
65
|
+
const { verifyBTCSignature } = await import("./bitcoin");
|
|
57
66
|
return verifyBTCSignature(proof as SignatureProof);
|
|
58
|
-
|
|
67
|
+
}
|
|
68
|
+
case ProofTypes.TIP191: {
|
|
69
|
+
const { verifyPersonalSignTIP191 } = await import("./tron");
|
|
59
70
|
return verifyPersonalSignTIP191(proof as SignatureProof);
|
|
60
|
-
|
|
71
|
+
}
|
|
61
72
|
case ProofTypes.MicroTransfer:
|
|
62
73
|
}
|
|
63
74
|
return proof;
|