@notabene/verify-proof 1.3.3-next.1 → 1.4.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/LICENSE.md +21 -0
- package/README.md +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/tests/xlm.test.d.ts +1 -0
- package/dist/xlm.d.ts +2 -0
- package/package.json +4 -3
- package/src/index.ts +3 -0
- package/src/tests/index.test.ts +35 -0
- package/src/tests/xlm.test.ts +80 -0
- package/src/xlm.ts +25 -0
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/xlm.d.ts
ADDED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@notabene/verify-proof",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.4.0",
|
4
4
|
"description": "Verify ownership proofs",
|
5
5
|
"source": "src/index.ts",
|
6
6
|
"type": "module",
|
@@ -45,12 +45,13 @@
|
|
45
45
|
"dependencies": {
|
46
46
|
"@cardano-foundation/cardano-verify-datasignature": "^1.0.11",
|
47
47
|
"@noble/curves": "^1.7.0",
|
48
|
-
"@notabene/javascript-sdk": "
|
48
|
+
"@notabene/javascript-sdk": "2.9.0",
|
49
49
|
"@scure/base": "^1.2.1",
|
50
|
+
"@stellar/stellar-sdk": "^13.1.0",
|
50
51
|
"bip322-js": "^2.0.0",
|
51
52
|
"ox": "^0.2.2",
|
52
53
|
"tweetnacl": "^1.0.3",
|
53
54
|
"varuint-bitcoin": "^2.0.0",
|
54
|
-
"xrpl": "^4.2.
|
55
|
+
"xrpl": "^4.2.5"
|
55
56
|
}
|
56
57
|
}
|
package/src/index.ts
CHANGED
@@ -12,6 +12,7 @@ import { verifySolanaSignature } from "./solana";
|
|
12
12
|
import { verifyPersonalSignTIP191 } from "./tron";
|
13
13
|
import { verifyCIP8Signature } from "./cardano";
|
14
14
|
import { verifyPersonalSignXRPL } from "./xrpl";
|
15
|
+
import { verifyStellarSignature } from "./xlm";
|
15
16
|
|
16
17
|
export async function verifyProof(
|
17
18
|
proof: OwnershipProof,
|
@@ -40,6 +41,8 @@ export async function verifyProof(
|
|
40
41
|
return verifySolanaSignature(proof as SignatureProof);
|
41
42
|
case ProofTypes.XRP_ED25519:
|
42
43
|
return verifyPersonalSignXRPL(proof as SignatureProof, publicKey);
|
44
|
+
case ProofTypes.XLM_ED25519:
|
45
|
+
return verifyStellarSignature(proof as SignatureProof);
|
43
46
|
case ProofTypes.EIP712:
|
44
47
|
case ProofTypes.BIP137:
|
45
48
|
case ProofTypes.BIP322:
|
package/src/tests/index.test.ts
CHANGED
@@ -248,4 +248,39 @@ describe("verifyProof", () => {
|
|
248
248
|
expect(result.status).toBe(ProofStatus.FAILED);
|
249
249
|
});
|
250
250
|
});
|
251
|
+
|
252
|
+
describe("Stellar", () => {
|
253
|
+
const proof: SignatureProof = {
|
254
|
+
address: 'stellar:pubnet:GB4G3PJUA5NKFY5U4OJQGNZUL3QUPAJLMARNWXZNBKMGOUQJLPGXPOYG',
|
255
|
+
attestation: 'test message',
|
256
|
+
proof: 'Y8H4RDjxGsYSgDgLWsFN9i2vk/7cqc/nLejYK/MIElBcpeZxjn18qES92EuMMvkSIVnanRvTXSploOuHU9WCAQ==',
|
257
|
+
status: ProofStatus.PENDING,
|
258
|
+
type: ProofTypes.XLM_ED25519,
|
259
|
+
wallet_provider: 'STELLAR',
|
260
|
+
did: 'did:pkh:stellar:pubnet:GB4G3PJUA5NKFY5U4OJQGNZUL3QUPAJLMARNWXZNBKMGOUQJLPGXPOYG'
|
261
|
+
};
|
262
|
+
|
263
|
+
it("should verify proof", async () => {
|
264
|
+
const result = await verifyProof(proof);
|
265
|
+
expect(result.status).toBe(ProofStatus.VERIFIED);
|
266
|
+
});
|
267
|
+
|
268
|
+
it("should fail if invalid proof", async () => {
|
269
|
+
const result = await verifyProof({
|
270
|
+
...proof,
|
271
|
+
proof: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
272
|
+
} as SignatureProof);
|
273
|
+
|
274
|
+
expect(result.status).toBe(ProofStatus.FAILED);
|
275
|
+
});
|
276
|
+
|
277
|
+
it("should fail if invalid address format", async () => {
|
278
|
+
const result = await verifyProof({
|
279
|
+
...proof,
|
280
|
+
address: "stellar:pubnet:not-a-valid-public-key"
|
281
|
+
} as SignatureProof);
|
282
|
+
|
283
|
+
expect(result.status).toBe(ProofStatus.FAILED);
|
284
|
+
});
|
285
|
+
});
|
251
286
|
});
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
2
|
+
import { Keypair } from "@stellar/stellar-sdk";
|
3
|
+
import { verifyStellarSignature } from "../xlm";
|
4
|
+
import { ProofStatus, ProofTypes, SignatureProof } from "@notabene/javascript-sdk";
|
5
|
+
|
6
|
+
describe("verifyStellarSignature", () => {
|
7
|
+
const createValidProof = (): SignatureProof => {
|
8
|
+
const keypair = Keypair.fromSecret("SBKMCWGXNN6C6QMCXOUZFQ4DSCACRE4FKIIFQMBFORXLOATUUM7SH4SV");
|
9
|
+
const message = "test message";
|
10
|
+
const messageBuffer = Buffer.from(message, "utf-8");
|
11
|
+
const signature = keypair.sign(messageBuffer);
|
12
|
+
|
13
|
+
return {
|
14
|
+
address: `stellar:pubnet:${keypair.publicKey().toString()}`,
|
15
|
+
attestation: message,
|
16
|
+
proof: signature.toString("base64"),
|
17
|
+
status: ProofStatus.PENDING,
|
18
|
+
type: ProofTypes.XLM_ED25519,
|
19
|
+
wallet_provider: "STELLAR",
|
20
|
+
did: `did:pkh:stellar:pubnet:${keypair.publicKey().toString()}`
|
21
|
+
};
|
22
|
+
};
|
23
|
+
|
24
|
+
it("should verify a valid Stellar signature", () => {
|
25
|
+
const proof = createValidProof();
|
26
|
+
const result = verifyStellarSignature(proof);
|
27
|
+
expect(result.status).toBe(ProofStatus.VERIFIED);
|
28
|
+
});
|
29
|
+
|
30
|
+
it("should fail for invalid signature", () => {
|
31
|
+
const keypair1 = Keypair.random();
|
32
|
+
const keypair2 = Keypair.random();
|
33
|
+
const message = "test message";
|
34
|
+
const messageBuffer = Buffer.from(message, "utf-8");
|
35
|
+
const signature = keypair1.sign(messageBuffer);
|
36
|
+
|
37
|
+
const proof: SignatureProof = {
|
38
|
+
address: `stellar:pubnet:${keypair2.publicKey().toString()}`,
|
39
|
+
attestation: message,
|
40
|
+
proof: signature.toString("base64"),
|
41
|
+
status: ProofStatus.PENDING,
|
42
|
+
type: ProofTypes.XLM_ED25519,
|
43
|
+
wallet_provider: "STELLAR",
|
44
|
+
did: `did:pkh:stellar:pubnet:${keypair2.publicKey().toString()}`
|
45
|
+
};
|
46
|
+
|
47
|
+
const result = verifyStellarSignature(proof);
|
48
|
+
expect(result.status).toBe(ProofStatus.FAILED);
|
49
|
+
});
|
50
|
+
|
51
|
+
it("should fail for non-xlm namespace", () => {
|
52
|
+
const proof = {
|
53
|
+
...createValidProof(),
|
54
|
+
address: "eip155:1:0x000000000000000000000000000000000000dead" // Different namespace
|
55
|
+
} as SignatureProof;
|
56
|
+
|
57
|
+
const result = verifyStellarSignature(proof);
|
58
|
+
expect(result.status).toBe(ProofStatus.FAILED);
|
59
|
+
});
|
60
|
+
|
61
|
+
it("should fail for malformed address", () => {
|
62
|
+
const proof = {
|
63
|
+
...createValidProof(),
|
64
|
+
address: "stellar:pubnet"
|
65
|
+
} as unknown as SignatureProof;
|
66
|
+
|
67
|
+
const result = verifyStellarSignature(proof);
|
68
|
+
expect(result.status).toBe(ProofStatus.FAILED);
|
69
|
+
});
|
70
|
+
|
71
|
+
it("should fail for invalid public key format", () => {
|
72
|
+
const proof = {
|
73
|
+
...createValidProof(),
|
74
|
+
address: "stellar:pubnet:not-a-valid-public-key"
|
75
|
+
} as SignatureProof;
|
76
|
+
|
77
|
+
const result = verifyStellarSignature(proof);
|
78
|
+
expect(result.status).toBe(ProofStatus.FAILED);
|
79
|
+
});
|
80
|
+
});
|
package/src/xlm.ts
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
import { ProofStatus, SignatureProof } from "@notabene/javascript-sdk";
|
2
|
+
import { Keypair } from "@stellar/stellar-sdk";
|
3
|
+
|
4
|
+
export function verifyStellarSignature(
|
5
|
+
proof: SignatureProof,
|
6
|
+
): SignatureProof {
|
7
|
+
const [ns, , address] = proof.address.split(/:/);
|
8
|
+
if (ns !== "stellar") return { ...proof, status: ProofStatus.FAILED };
|
9
|
+
|
10
|
+
try {
|
11
|
+
const keypair = Keypair.fromPublicKey(address);
|
12
|
+
const messageBuffer = Buffer.from(proof.attestation, "utf-8");
|
13
|
+
const signatureBuffer = Buffer.from(proof.proof, "base64");
|
14
|
+
|
15
|
+
const verified = keypair.verify(messageBuffer, signatureBuffer);
|
16
|
+
|
17
|
+
return {
|
18
|
+
...proof,
|
19
|
+
status: verified ? ProofStatus.VERIFIED : ProofStatus.FAILED,
|
20
|
+
};
|
21
|
+
} catch (error) {
|
22
|
+
console.error(error);
|
23
|
+
return { ...proof, status: ProofStatus.FAILED };
|
24
|
+
}
|
25
|
+
}
|