@collectorcrypt/vrf-client 0.1.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/dist/addresses.d.ts +34 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/addresses.js +87 -0
- package/dist/addresses.js.map +1 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -0
- package/dist/idl/cc_vrf.json +1024 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/light.d.ts +98 -0
- package/dist/light.d.ts.map +1 -0
- package/dist/light.js +182 -0
- package/dist/light.js.map +1 -0
- package/dist/operations.d.ts +172 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +417 -0
- package/dist/operations.js.map +1 -0
- package/dist/program.d.ts +9 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +21 -0
- package/dist/program.js.map +1 -0
- package/dist/verifyEndToEnd.d.ts +124 -0
- package/dist/verifyEndToEnd.d.ts.map +1 -0
- package/dist/verifyEndToEnd.js +150 -0
- package/dist/verifyEndToEnd.js.map +1 -0
- package/package.json +49 -0
- package/src/addresses.ts +105 -0
- package/src/constants.ts +16 -0
- package/src/idl/cc_vrf.json +1024 -0
- package/src/index.ts +80 -0
- package/src/light.ts +259 -0
- package/src/operations.ts +655 -0
- package/src/program.ts +17 -0
- package/src/verifyEndToEnd.ts +305 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Derive the compressed-PDA address of a VrfAuthority. This is the address
|
|
4
|
+
* the Light state Merkle tree indexes — NOT a Solana account address.
|
|
5
|
+
*
|
|
6
|
+
* Seeds: ["vrf_authority", owner_pubkey, label_bytes]
|
|
7
|
+
*/
|
|
8
|
+
export declare function deriveAuthorityAddress(owner: PublicKey, label: Uint8Array, programId: PublicKey): PublicKey;
|
|
9
|
+
/**
|
|
10
|
+
* Derive the compressed-PDA address of a VrfProofCommit.
|
|
11
|
+
*
|
|
12
|
+
* Seeds: ["vrf_proof", authority_pubkey, memo_hash]
|
|
13
|
+
*/
|
|
14
|
+
export declare function deriveProofCommitAddress(authority: PublicKey, memoHash: Uint8Array, programId: PublicKey): PublicKey;
|
|
15
|
+
/**
|
|
16
|
+
* Derive the compressed-PDA address of a VrfProofCommitWithBeta. Uses a
|
|
17
|
+
* same seed prefix as regular VrfProofCommit records. This makes registry
|
|
18
|
+
* mode and registry+beta mutually exclusive for a given (authority, memo).
|
|
19
|
+
*
|
|
20
|
+
* Seeds: ["vrf_proof", authority_pubkey, memo_hash]
|
|
21
|
+
*/
|
|
22
|
+
export declare function deriveProofCommitWithBetaAddress(authority: PublicKey, memoHash: Uint8Array, programId: PublicKey): PublicKey;
|
|
23
|
+
/** Convenience: SHA-256 a UTF-8 memo string. */
|
|
24
|
+
export declare function memoHash(memo: string | Uint8Array): Uint8Array;
|
|
25
|
+
/** Convenience: SHA-256 the alpha bytes. */
|
|
26
|
+
export declare function alphaHash(alpha: Uint8Array): Uint8Array;
|
|
27
|
+
/** Convenience: SHA-256 the proof bytes. */
|
|
28
|
+
export declare function proofHash(proof: Uint8Array): Uint8Array;
|
|
29
|
+
/**
|
|
30
|
+
* Pad a short utf-8 label to 32 bytes (right-padded with zeroes). Useful for
|
|
31
|
+
* human-readable labels like "gacha" or "lottery".
|
|
32
|
+
*/
|
|
33
|
+
export declare function encodeLabel(label: string): Uint8Array;
|
|
34
|
+
//# sourceMappingURL=addresses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../src/addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAa5C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,SAAS,GACnB,SAAS,CAMX;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,UAAU,EACpB,SAAS,EAAE,SAAS,GACnB,SAAS,CAUX;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,UAAU,EACpB,SAAS,EAAE,SAAS,GACnB,SAAS,CAUX;AAED,gDAAgD;AAChD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAI9D;AAED,4CAA4C;AAC5C,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAEvD;AAED,4CAA4C;AAC5C,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAEvD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAQrD"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deriveAuthorityAddress = deriveAuthorityAddress;
|
|
4
|
+
exports.deriveProofCommitAddress = deriveProofCommitAddress;
|
|
5
|
+
exports.deriveProofCommitWithBetaAddress = deriveProofCommitWithBetaAddress;
|
|
6
|
+
exports.memoHash = memoHash;
|
|
7
|
+
exports.alphaHash = alphaHash;
|
|
8
|
+
exports.proofHash = proofHash;
|
|
9
|
+
exports.encodeLabel = encodeLabel;
|
|
10
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
11
|
+
const stateless_js_1 = require("@lightprotocol/stateless.js");
|
|
12
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
/**
|
|
15
|
+
* Derive the compressed-PDA address of a VrfAuthority. This is the address
|
|
16
|
+
* the Light state Merkle tree indexes — NOT a Solana account address.
|
|
17
|
+
*
|
|
18
|
+
* Seeds: ["vrf_authority", owner_pubkey, label_bytes]
|
|
19
|
+
*/
|
|
20
|
+
function deriveAuthorityAddress(owner, label, programId) {
|
|
21
|
+
if (label.length !== 32) {
|
|
22
|
+
throw new Error("label must be exactly 32 bytes");
|
|
23
|
+
}
|
|
24
|
+
const seed = (0, stateless_js_1.deriveAddressSeedV2)([constants_1.AUTHORITY_SEED, owner.toBytes(), label]);
|
|
25
|
+
return (0, stateless_js_1.deriveAddressV2)(seed, new web3_js_1.PublicKey(stateless_js_1.batchAddressTree), programId);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Derive the compressed-PDA address of a VrfProofCommit.
|
|
29
|
+
*
|
|
30
|
+
* Seeds: ["vrf_proof", authority_pubkey, memo_hash]
|
|
31
|
+
*/
|
|
32
|
+
function deriveProofCommitAddress(authority, memoHash, programId) {
|
|
33
|
+
if (memoHash.length !== 32) {
|
|
34
|
+
throw new Error("memoHash must be exactly 32 bytes");
|
|
35
|
+
}
|
|
36
|
+
const seed = (0, stateless_js_1.deriveAddressSeedV2)([
|
|
37
|
+
constants_1.PROOF_COMMIT_SEED,
|
|
38
|
+
authority.toBytes(),
|
|
39
|
+
memoHash,
|
|
40
|
+
]);
|
|
41
|
+
return (0, stateless_js_1.deriveAddressV2)(seed, new web3_js_1.PublicKey(stateless_js_1.batchAddressTree), programId);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Derive the compressed-PDA address of a VrfProofCommitWithBeta. Uses a
|
|
45
|
+
* same seed prefix as regular VrfProofCommit records. This makes registry
|
|
46
|
+
* mode and registry+beta mutually exclusive for a given (authority, memo).
|
|
47
|
+
*
|
|
48
|
+
* Seeds: ["vrf_proof", authority_pubkey, memo_hash]
|
|
49
|
+
*/
|
|
50
|
+
function deriveProofCommitWithBetaAddress(authority, memoHash, programId) {
|
|
51
|
+
if (memoHash.length !== 32) {
|
|
52
|
+
throw new Error("memoHash must be exactly 32 bytes");
|
|
53
|
+
}
|
|
54
|
+
const seed = (0, stateless_js_1.deriveAddressSeedV2)([
|
|
55
|
+
constants_1.PROOF_COMMIT_WITH_BETA_SEED,
|
|
56
|
+
authority.toBytes(),
|
|
57
|
+
memoHash,
|
|
58
|
+
]);
|
|
59
|
+
return (0, stateless_js_1.deriveAddressV2)(seed, new web3_js_1.PublicKey(stateless_js_1.batchAddressTree), programId);
|
|
60
|
+
}
|
|
61
|
+
/** Convenience: SHA-256 a UTF-8 memo string. */
|
|
62
|
+
function memoHash(memo) {
|
|
63
|
+
const input = typeof memo === "string" ? new TextEncoder().encode(memo) : memo;
|
|
64
|
+
return (0, sha2_js_1.sha256)(input);
|
|
65
|
+
}
|
|
66
|
+
/** Convenience: SHA-256 the alpha bytes. */
|
|
67
|
+
function alphaHash(alpha) {
|
|
68
|
+
return (0, sha2_js_1.sha256)(alpha);
|
|
69
|
+
}
|
|
70
|
+
/** Convenience: SHA-256 the proof bytes. */
|
|
71
|
+
function proofHash(proof) {
|
|
72
|
+
return (0, sha2_js_1.sha256)(proof);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Pad a short utf-8 label to 32 bytes (right-padded with zeroes). Useful for
|
|
76
|
+
* human-readable labels like "gacha" or "lottery".
|
|
77
|
+
*/
|
|
78
|
+
function encodeLabel(label) {
|
|
79
|
+
const bytes = new TextEncoder().encode(label);
|
|
80
|
+
if (bytes.length > 32) {
|
|
81
|
+
throw new Error(`label "${label}" exceeds 32 bytes encoded`);
|
|
82
|
+
}
|
|
83
|
+
const padded = new Uint8Array(32);
|
|
84
|
+
padded.set(bytes, 0);
|
|
85
|
+
return padded;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=addresses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addresses.js","sourceRoot":"","sources":["../src/addresses.ts"],"names":[],"mappings":";;AAmBA,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AmB,EAAC;QAC/B,uCAA2B;QAC3B,SAAS,CAAC,OAAO,EAAE;QACnB,QAAQ;KACT,CAAC,CAAC;IACH,OAAO,IAAA,8BAAe,EAAC,IAAI,EAAE,IAAI,mBAAS,CAAC,+BAAgB,CAAC,EAAE,SAAS,CAAC,CAAC;AAC3E,CAAC;AAED,gDAAgD;AAChD,SAAgB,QAAQ,CAAC,IAAyB;IAChD,MAAM,KAAK,GACT,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,OAAO,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,4CAA4C;AAC5C,SAAgB,SAAS,CAAC,KAAiB;IACzC,OAAO,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,4CAA4C;AAC5C,SAAgB,SAAS,CAAC,KAAiB;IACzC,OAAO,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,SAAgB,WAAW,CAAC,KAAa;IACvC,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,UAAU,KAAK,4BAA4B,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAClC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACrB,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Default mainnet program ID (renounced upgrade authority post-deploy).
|
|
4
|
+
* Override via `new VrfClient({ programId })` for devnet/local testing.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CC_VRF_PROGRAM_ID: PublicKey;
|
|
7
|
+
export declare const AUTHORITY_SEED: NodeJS.NonSharedUint8Array;
|
|
8
|
+
export declare const PROOF_COMMIT_SEED: NodeJS.NonSharedUint8Array;
|
|
9
|
+
export declare const PROOF_COMMIT_WITH_BETA_SEED: NodeJS.NonSharedUint8Array;
|
|
10
|
+
/** RFC 9381 §7.5 IANA suite identifier. */
|
|
11
|
+
export declare const SUITE_EDWARDS25519_SHA512_TAI = 3;
|
|
12
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,WAE7B,CAAC;AAEF,eAAO,MAAM,cAAc,4BAA4C,CAAC;AACxE,eAAO,MAAM,iBAAiB,4BAAwC,CAAC;AACvE,eAAO,MAAM,2BAA2B,4BAAoB,CAAC;AAE7D,2CAA2C;AAC3C,eAAO,MAAM,6BAA6B,IAAO,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUITE_EDWARDS25519_SHA512_TAI = exports.PROOF_COMMIT_WITH_BETA_SEED = exports.PROOF_COMMIT_SEED = exports.AUTHORITY_SEED = exports.CC_VRF_PROGRAM_ID = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
/**
|
|
6
|
+
* Default mainnet program ID (renounced upgrade authority post-deploy).
|
|
7
|
+
* Override via `new VrfClient({ programId })` for devnet/local testing.
|
|
8
|
+
*/
|
|
9
|
+
exports.CC_VRF_PROGRAM_ID = new web3_js_1.PublicKey("ccvrfu3fSpbnPLiUqdWAt85Zn9nq96ekwGTbHqGtdgQ");
|
|
10
|
+
exports.AUTHORITY_SEED = new TextEncoder().encode("vrf_authority");
|
|
11
|
+
exports.PROOF_COMMIT_SEED = new TextEncoder().encode("vrf_proof");
|
|
12
|
+
exports.PROOF_COMMIT_WITH_BETA_SEED = exports.PROOF_COMMIT_SEED;
|
|
13
|
+
/** RFC 9381 §7.5 IANA suite identifier. */
|
|
14
|
+
exports.SUITE_EDWARDS25519_SHA512_TAI = 0x03;
|
|
15
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C;;;GAGG;AACU,QAAA,iBAAiB,GAAG,IAAI,mBAAS,CAC5C,6CAA6C,CAC9C,CAAC;AAEW,QAAA,cAAc,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;AAC3D,QAAA,iBAAiB,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC1D,QAAA,2BAA2B,GAAG,yBAAiB,CAAC;AAE7D,2CAA2C;AAC9B,QAAA,6BAA6B,GAAG,IAAI,CAAC"}
|