@solana/web3.js 1.26.1 → 1.27.1
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/lib/index.browser.esm.js +94 -1
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +94 -0
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +45 -0
- package/lib/index.esm.js +94 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +94 -0
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +52 -0
- package/package.json +4 -3
- package/src/ed25519-program.ts +140 -0
- package/src/index.ts +1 -0
- package/src/publickey.ts +8 -2
- package/src/transaction.ts +2 -2
package/lib/index.cjs.js
CHANGED
|
@@ -106,6 +106,9 @@ const SOLANA_SCHEMA = new Map();
|
|
|
106
106
|
*/
|
|
107
107
|
|
|
108
108
|
const MAX_SEED_LENGTH = 32;
|
|
109
|
+
/**
|
|
110
|
+
* Value to be converted into public key
|
|
111
|
+
*/
|
|
109
112
|
|
|
110
113
|
function isPublicKeyData(value) {
|
|
111
114
|
return value._bn !== undefined;
|
|
@@ -5687,6 +5690,96 @@ class Keypair {
|
|
|
5687
5690
|
|
|
5688
5691
|
}
|
|
5689
5692
|
|
|
5693
|
+
const PRIVATE_KEY_BYTES$1 = 64;
|
|
5694
|
+
const PUBLIC_KEY_BYTES$1 = 32;
|
|
5695
|
+
const SIGNATURE_BYTES = 64;
|
|
5696
|
+
/**
|
|
5697
|
+
* Params for creating an ed25519 instruction using a public key
|
|
5698
|
+
*/
|
|
5699
|
+
|
|
5700
|
+
const ED25519_INSTRUCTION_LAYOUT = BufferLayout__namespace.struct([BufferLayout__namespace.u8('numSignatures'), BufferLayout__namespace.u8('padding'), BufferLayout__namespace.u16('signatureOffset'), BufferLayout__namespace.u16('signatureInstructionIndex'), BufferLayout__namespace.u16('publicKeyOffset'), BufferLayout__namespace.u16('publicKeyInstructionIndex'), BufferLayout__namespace.u16('messageDataOffset'), BufferLayout__namespace.u16('messageDataSize'), BufferLayout__namespace.u16('messageInstructionIndex')]);
|
|
5701
|
+
class Ed25519Program {
|
|
5702
|
+
/**
|
|
5703
|
+
* @internal
|
|
5704
|
+
*/
|
|
5705
|
+
constructor() {}
|
|
5706
|
+
/**
|
|
5707
|
+
* Public key that identifies the ed25519 program
|
|
5708
|
+
*/
|
|
5709
|
+
|
|
5710
|
+
|
|
5711
|
+
/**
|
|
5712
|
+
* Create an ed25519 instruction with a public key and signature. The
|
|
5713
|
+
* public key must be a buffer that is 32 bytes long, and the signature
|
|
5714
|
+
* must be a buffer of 64 bytes.
|
|
5715
|
+
*/
|
|
5716
|
+
static createInstructionWithPublicKey(params) {
|
|
5717
|
+
const {
|
|
5718
|
+
publicKey,
|
|
5719
|
+
message,
|
|
5720
|
+
signature,
|
|
5721
|
+
instructionIndex
|
|
5722
|
+
} = params;
|
|
5723
|
+
assert(publicKey.length === PUBLIC_KEY_BYTES$1, `Public Key must be ${PUBLIC_KEY_BYTES$1} bytes but received ${publicKey.length} bytes`);
|
|
5724
|
+
assert(signature.length === SIGNATURE_BYTES, `Signature must be ${SIGNATURE_BYTES} bytes but received ${signature.length} bytes`);
|
|
5725
|
+
const publicKeyOffset = ED25519_INSTRUCTION_LAYOUT.span;
|
|
5726
|
+
const signatureOffset = publicKeyOffset + publicKey.length;
|
|
5727
|
+
const messageDataOffset = signatureOffset + signature.length;
|
|
5728
|
+
const numSignatures = 1;
|
|
5729
|
+
const instructionData = buffer.Buffer.alloc(messageDataOffset + message.length);
|
|
5730
|
+
ED25519_INSTRUCTION_LAYOUT.encode({
|
|
5731
|
+
numSignatures,
|
|
5732
|
+
padding: 0,
|
|
5733
|
+
signatureOffset,
|
|
5734
|
+
signatureInstructionIndex: instructionIndex,
|
|
5735
|
+
publicKeyOffset,
|
|
5736
|
+
publicKeyInstructionIndex: instructionIndex,
|
|
5737
|
+
messageDataOffset,
|
|
5738
|
+
messageDataSize: message.length,
|
|
5739
|
+
messageInstructionIndex: instructionIndex
|
|
5740
|
+
}, instructionData);
|
|
5741
|
+
instructionData.fill(publicKey, publicKeyOffset);
|
|
5742
|
+
instructionData.fill(signature, signatureOffset);
|
|
5743
|
+
instructionData.fill(message, messageDataOffset);
|
|
5744
|
+
return new TransactionInstruction({
|
|
5745
|
+
keys: [],
|
|
5746
|
+
programId: Ed25519Program.programId,
|
|
5747
|
+
data: instructionData
|
|
5748
|
+
});
|
|
5749
|
+
}
|
|
5750
|
+
/**
|
|
5751
|
+
* Create an ed25519 instruction with a private key. The private key
|
|
5752
|
+
* must be a buffer that is 64 bytes long.
|
|
5753
|
+
*/
|
|
5754
|
+
|
|
5755
|
+
|
|
5756
|
+
static createInstructionWithPrivateKey(params) {
|
|
5757
|
+
const {
|
|
5758
|
+
privateKey,
|
|
5759
|
+
message,
|
|
5760
|
+
instructionIndex
|
|
5761
|
+
} = params;
|
|
5762
|
+
assert(privateKey.length === PRIVATE_KEY_BYTES$1, `Private key must be ${PRIVATE_KEY_BYTES$1} bytes but received ${privateKey.length} bytes`);
|
|
5763
|
+
|
|
5764
|
+
try {
|
|
5765
|
+
const keypair = Keypair.fromSecretKey(privateKey);
|
|
5766
|
+
const publicKey = keypair.publicKey.toBytes();
|
|
5767
|
+
const signature = nacl__default['default'].sign.detached(message, keypair.secretKey);
|
|
5768
|
+
return this.createInstructionWithPublicKey({
|
|
5769
|
+
publicKey,
|
|
5770
|
+
message,
|
|
5771
|
+
signature,
|
|
5772
|
+
instructionIndex
|
|
5773
|
+
});
|
|
5774
|
+
} catch (error) {
|
|
5775
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
5776
|
+
}
|
|
5777
|
+
}
|
|
5778
|
+
|
|
5779
|
+
}
|
|
5780
|
+
|
|
5781
|
+
_defineProperty__default['default'](Ed25519Program, "programId", new PublicKey('Ed25519SigVerify111111111111111111111111111'));
|
|
5782
|
+
|
|
5690
5783
|
/**
|
|
5691
5784
|
* Address of the stake config account which configures the rate
|
|
5692
5785
|
* of stake warmup and cooldown as well as the slashing penalty.
|
|
@@ -6824,6 +6917,7 @@ exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
|
|
|
6824
6917
|
exports.BPF_LOADER_PROGRAM_ID = BPF_LOADER_PROGRAM_ID;
|
|
6825
6918
|
exports.BpfLoader = BpfLoader;
|
|
6826
6919
|
exports.Connection = Connection;
|
|
6920
|
+
exports.Ed25519Program = Ed25519Program;
|
|
6827
6921
|
exports.Enum = Enum;
|
|
6828
6922
|
exports.EpochSchedule = EpochSchedule;
|
|
6829
6923
|
exports.FeeCalculatorLayout = FeeCalculatorLayout;
|