@solana/web3.js 2.0.0-experimental.8c9cacd → 2.0.0-experimental.8ecb622
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.
|
@@ -913,6 +913,27 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
913
913
|
}
|
|
914
914
|
throw new Error("Unable to find a viable program address bump seed");
|
|
915
915
|
}
|
|
916
|
+
async function createAddressWithSeed({
|
|
917
|
+
baseAddress,
|
|
918
|
+
programAddress,
|
|
919
|
+
seed
|
|
920
|
+
}) {
|
|
921
|
+
const { serialize: serialize4, deserialize: deserialize2 } = getBase58EncodedAddressCodec();
|
|
922
|
+
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
923
|
+
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
924
|
+
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
925
|
+
}
|
|
926
|
+
const programAddressBytes = serialize4(programAddress);
|
|
927
|
+
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
928
|
+
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
929
|
+
}
|
|
930
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
931
|
+
"SHA-256",
|
|
932
|
+
new Uint8Array([...serialize4(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
933
|
+
);
|
|
934
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
935
|
+
return deserialize2(addressBytes)[0];
|
|
936
|
+
}
|
|
916
937
|
async function getAddressFromPublicKey(publicKey) {
|
|
917
938
|
await assertKeyExporterIsAvailable();
|
|
918
939
|
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
@@ -2245,6 +2266,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2245
2266
|
exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
|
|
2246
2267
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
2247
2268
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
2269
|
+
exports.createAddressWithSeed = createAddressWithSeed;
|
|
2248
2270
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
2249
2271
|
exports.createSolanaRpc = createSolanaRpc;
|
|
2250
2272
|
exports.createTransaction = createTransaction;
|