From 6a72f6ae87c3a5e1831417bd17c010153701cb6b Mon Sep 17 00:00:00 2001 From: Sal Samani <54984459+metasal1@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:43:56 +1100 Subject: [PATCH 1/2] Update check-publickey.md to include web3.js v2 example --- content/cookbook/wallets/check-publickey.md | 36 ++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/content/cookbook/wallets/check-publickey.md b/content/cookbook/wallets/check-publickey.md index 287f64c2e..ddfc94b0c 100644 --- a/content/cookbook/wallets/check-publickey.md +++ b/content/cookbook/wallets/check-publickey.md @@ -11,7 +11,36 @@ have a private key associated with them. You can check this by looking to see if the public key lies on the ed25519 curve. Only public keys that lie on the curve can be controlled by users with wallets. -```javascript file=/code/cookbook/wallets/check-public-key.ts#L1-L2,#L3-L19 + + + + +```typescript +import { isAddress } from "@solana/web3.js"; + +// Note that generateKeyPair() will always give a public key that is valid for users + +// Valid public key +const key = "5oNDL3swdJJF1g9DzJiZ4ynHXgszjAEpUkxVYejchzrY"; + +// Lies on the ed25519 curve and is suitable for users +console.log("Valid Address: ", isAddress(key)); + +// // Valid public key +const offCurveAddress = "4BJXYkfvg37zEmBbsacZjeQDpTNx91KppxFJxRqrz48e"; + +// // Not on the ed25519 curve, therefore not suitable for users +console.log("Valid Off Curve Address: ", isAddress(offCurveAddress)); + +// // Not a valid public key +const errorPubkey = "testPubkey"; +console.log("Invalid Address: ", isAddress(errorPubkey)); +``` + + + + +```typescript import { PublicKey } from "@solana/web3.js"; // Note that Keypair.generate() will always give a public key that is valid for users @@ -31,4 +60,9 @@ console.log(PublicKey.isOnCurve(offCurveAddress.toBytes())); // Not a valid public key const errorPubkey = new PublicKey("testPubkey"); +console.log(PublicKey.isOnCurve(errorPubkey.toBytes())); +``` + + + ``` From 6fa571dd6463ed4b22d83fcdcb20d8dc15943dbc Mon Sep 17 00:00:00 2001 From: metasal <54984459+metasal1@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:13:03 +1100 Subject: [PATCH 2/2] Update content/cookbook/wallets/check-publickey.md Co-authored-by: Nick Frostbutter <75431177+nickfrosty@users.noreply.github.com> --- content/cookbook/wallets/check-publickey.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/cookbook/wallets/check-publickey.md b/content/cookbook/wallets/check-publickey.md index ddfc94b0c..3aa440c73 100644 --- a/content/cookbook/wallets/check-publickey.md +++ b/content/cookbook/wallets/check-publickey.md @@ -65,4 +65,3 @@ console.log(PublicKey.isOnCurve(errorPubkey.toBytes())); -```