0.10.0 • Published 2 months ago
@pcd/eddsa-pcd v0.10.0
This package defines a PCD designed to verify the authenticity of a message signed using an EdDSA key. |
---|
🛠 Install
Install the @pcd/eddsa-pcd
package with npm:
npm i @pcd/eddsa-pcd
or yarn:
yarn add @pcd/eddsa-pcd
📜 Usage
Prove
import { getEdDSAPublicKey, newEdDSAPrivateKey, prove } from "@pcd/eddsa-pcd"
import { ArgumentTypeName } from "@pcd/pcd-types"
// Generate a new EdDSA private key.
const privateKey = newEdDSAPrivateKey()
// Prepare the message to sign.
// It must be a list of hexadicimal strings.
const message = ["0xc", "0x7a", "0x8f"]
// Create a PCD with the required attributes and their types.
const pcd = await prove({
// The id is optional and if you don't pass it a random value will be automatically created.
id: {
argumentType: ArgumentTypeName.String
},
message: {
argumentType: ArgumentTypeName.StringArray,
value: message
},
privateKey: {
argumentType: ArgumentTypeName.String,
value: privateKey
}
})
console.log(pcd)
/*
EdDSAPCD {
type: 'eddsa-pcd',
id: '4c80affc-12c3-4d93-8983-cc38295ad31b',
claim: {
message: [ 12n, 122n, 143n ],
publicKey: [
'1d5ac1f31407018b7d413a4f52c8f74463b30e6ac2238220ad8b254de4eaa3a2',
'1e1de8a908826c3f9ac2e0ceee929ecd0caf3b99b3ef24523aaab796a6f733c4'
]
},
proof: {
signature: '39166dd6187378e2ef24d183bffe5bd1b2114344fcd5a56db562a12859c03b9a53b2f98de0b7d4f23dc49979d0e8f919f428a37e736163f7426259c13ecb7000'
}
}
*/
Verify
import { verify } from "@pcd/eddsa-pcd"
const isValid = await verify(pcd)
console.log(isValid) // true
Serialize
import { serialize } from "@pcd/eddsa-pcd"
const serialized = await serialize(pcd)
console.log(serialized)
/*
{
type: 'eddsa-pcd',
pcd: '{"type":"eddsa-pcd","id":"15bcc6ec-3482-4772-8a67-27630f8641c5","claim":{"message":["c","7a","8f"],"publicKey":["1d5ac1f31407018b7d413a4f52c8f74463b30e6ac2238220ad8b254de4eaa3a2","1e1de8a908826c3f9ac2e0ceee929ecd0caf3b99b3ef24523aaab796a6f733c4"]},"proof":{"signature":"71907bb4a1b5e27b2b9df54ac5cbebb45958f673b97030a79a3799e54ed3779eb499e710bb02231d9f9b6bb621375de7a68ad53bc3e5cef35c6531f9440d8d05"}}'
}
*/
Deserialize
import { deserialize } from "@pcd/eddsa-pcd"
const deserialized = await deserialize(serialized.pcd)
console.log(deserialized)
/*
EdDSAPCD {
type: 'eddsa-pcd',
id: '4c80affc-12c3-4d93-8983-cc38295ad31b',
claim: {
message: [ 12n, 122n, 143n ],
publicKey: [
'1d5ac1f31407018b7d413a4f52c8f74463b30e6ac2238220ad8b254de4eaa3a2',
'1e1de8a908826c3f9ac2e0ceee929ecd0caf3b99b3ef24523aaab796a6f733c4'
]
},
proof: {
signature: '39166dd6187378e2ef24d183bffe5bd1b2114344fcd5a56db562a12859c03b9a53b2f98de0b7d4f23dc49979d0e8f919f428a37e736163f7426259c13ecb7000'
}
}
*/
0.10.0
2 months ago
0.9.0
2 months ago
0.8.0
2 months ago
0.7.0
2 months ago
0.6.3
5 months ago
0.6.2
6 months ago
0.6.5
3 months ago
0.6.4
4 months ago
0.6.1
7 months ago
0.6.0
8 months ago
0.5.0
1 year ago
0.4.0
1 year ago
0.3.0
1 year ago
0.2.3-beta.5.0
1 year ago
0.2.3-beta.4.0
1 year ago
0.2.3-beta.3.0
1 year ago
0.2.3-beta.2.0
1 year ago
0.2.2
1 year ago
0.2.1
1 year ago
0.2.0
1 year ago
0.1.1
1 year ago