SHA256
ESP32 wallet RPC, browser wallet provider, and side panel
This commit is contained in:
@@ -75,6 +75,22 @@ export class ShineApiClient {
|
||||
return Array.isArray(response?.payload?.sessions) ? response.payload.sessions : [];
|
||||
}
|
||||
|
||||
async callSignalToSession({ toLogin, targetSessionId, callId, type, data = '' }) {
|
||||
const response = await this.ws.request('CallSignalToSession', {
|
||||
toLogin: String(toLogin || '').trim(),
|
||||
targetSessionId: String(targetSessionId || '').trim(),
|
||||
callId: String(callId || '').trim(),
|
||||
type: Number(type) || 0,
|
||||
data: String(data || ''),
|
||||
});
|
||||
if (response.status !== 200) throw opError('CallSignalToSession', response);
|
||||
return response.payload || {};
|
||||
}
|
||||
|
||||
onEvent(op, handler) {
|
||||
return this.ws.on(op, handler);
|
||||
}
|
||||
|
||||
async resumeSession(sessionRecord) {
|
||||
const login = String(sessionRecord?.login || '').trim();
|
||||
const sessionId = String(sessionRecord?.sessionId || '').trim();
|
||||
|
||||
@@ -12136,8 +12136,8 @@ function weierstrass(curveDef) {
|
||||
return drbg(seed, k2sig);
|
||||
}
|
||||
Point2.BASE._setWindowSize(8);
|
||||
function verify2(signature, msgHash, publicKey2, opts = defaultVerOpts) {
|
||||
const sg = signature;
|
||||
function verify2(signature2, msgHash, publicKey2, opts = defaultVerOpts) {
|
||||
const sg = signature2;
|
||||
msgHash = ensureBytes("msgHash", msgHash);
|
||||
publicKey2 = ensureBytes("publicKey", publicKey2);
|
||||
if ("strict" in opts)
|
||||
@@ -12515,30 +12515,30 @@ var PACKET_DATA_SIZE = 1280 - 40 - 8;
|
||||
var VERSION_PREFIX_MASK = 127;
|
||||
var SIGNATURE_LENGTH_IN_BYTES = 64;
|
||||
var TransactionExpiredBlockheightExceededError = class extends Error {
|
||||
constructor(signature) {
|
||||
super(`Signature ${signature} has expired: block height exceeded.`);
|
||||
constructor(signature2) {
|
||||
super(`Signature ${signature2} has expired: block height exceeded.`);
|
||||
this.signature = void 0;
|
||||
this.signature = signature;
|
||||
this.signature = signature2;
|
||||
}
|
||||
};
|
||||
Object.defineProperty(TransactionExpiredBlockheightExceededError.prototype, "name", {
|
||||
value: "TransactionExpiredBlockheightExceededError"
|
||||
});
|
||||
var TransactionExpiredTimeoutError = class extends Error {
|
||||
constructor(signature, timeoutSeconds) {
|
||||
super(`Transaction was not confirmed in ${timeoutSeconds.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`);
|
||||
constructor(signature2, timeoutSeconds) {
|
||||
super(`Transaction was not confirmed in ${timeoutSeconds.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature2} using the Solana Explorer or CLI tools.`);
|
||||
this.signature = void 0;
|
||||
this.signature = signature;
|
||||
this.signature = signature2;
|
||||
}
|
||||
};
|
||||
Object.defineProperty(TransactionExpiredTimeoutError.prototype, "name", {
|
||||
value: "TransactionExpiredTimeoutError"
|
||||
});
|
||||
var TransactionExpiredNonceInvalidError = class extends Error {
|
||||
constructor(signature) {
|
||||
super(`Signature ${signature} has expired: the nonce is no longer valid.`);
|
||||
constructor(signature2) {
|
||||
super(`Signature ${signature2} has expired: the nonce is no longer valid.`);
|
||||
this.signature = void 0;
|
||||
this.signature = signature;
|
||||
this.signature = signature2;
|
||||
}
|
||||
};
|
||||
Object.defineProperty(TransactionExpiredNonceInvalidError.prototype, "name", {
|
||||
@@ -12598,6 +12598,9 @@ var MessageAccountKeys = class {
|
||||
var publicKey = (property = "publicKey") => {
|
||||
return BufferLayout.blob(32, property);
|
||||
};
|
||||
var signature = (property = "signature") => {
|
||||
return BufferLayout.blob(64, property);
|
||||
};
|
||||
var rustString = (property = "string") => {
|
||||
const rsl = BufferLayout.struct([BufferLayout.u32("length"), BufferLayout.u32("lengthPadding"), BufferLayout.blob(BufferLayout.offset(BufferLayout.u32(), -8), "chars")], property);
|
||||
const _decode = rsl.decode.bind(rsl);
|
||||
@@ -12954,6 +12957,260 @@ var Message = class _Message {
|
||||
return new _Message(messageArgs);
|
||||
}
|
||||
};
|
||||
var MessageV0 = class _MessageV0 {
|
||||
constructor(args) {
|
||||
this.header = void 0;
|
||||
this.staticAccountKeys = void 0;
|
||||
this.recentBlockhash = void 0;
|
||||
this.compiledInstructions = void 0;
|
||||
this.addressTableLookups = void 0;
|
||||
this.header = args.header;
|
||||
this.staticAccountKeys = args.staticAccountKeys;
|
||||
this.recentBlockhash = args.recentBlockhash;
|
||||
this.compiledInstructions = args.compiledInstructions;
|
||||
this.addressTableLookups = args.addressTableLookups;
|
||||
}
|
||||
get version() {
|
||||
return 0;
|
||||
}
|
||||
get numAccountKeysFromLookups() {
|
||||
let count = 0;
|
||||
for (const lookup of this.addressTableLookups) {
|
||||
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
getAccountKeys(args) {
|
||||
let accountKeysFromLookups;
|
||||
if (args && "accountKeysFromLookups" in args && args.accountKeysFromLookups) {
|
||||
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
||||
throw new Error("Failed to get account keys because of a mismatch in the number of account keys from lookups");
|
||||
}
|
||||
accountKeysFromLookups = args.accountKeysFromLookups;
|
||||
} else if (args && "addressLookupTableAccounts" in args && args.addressLookupTableAccounts) {
|
||||
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
||||
} else if (this.addressTableLookups.length > 0) {
|
||||
throw new Error("Failed to get account keys because address table lookups were not resolved");
|
||||
}
|
||||
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
||||
}
|
||||
isAccountSigner(index) {
|
||||
return index < this.header.numRequiredSignatures;
|
||||
}
|
||||
isAccountWritable(index) {
|
||||
const numSignedAccounts = this.header.numRequiredSignatures;
|
||||
const numStaticAccountKeys = this.staticAccountKeys.length;
|
||||
if (index >= numStaticAccountKeys) {
|
||||
const lookupAccountKeysIndex = index - numStaticAccountKeys;
|
||||
const numWritableLookupAccountKeys = this.addressTableLookups.reduce((count, lookup) => count + lookup.writableIndexes.length, 0);
|
||||
return lookupAccountKeysIndex < numWritableLookupAccountKeys;
|
||||
} else if (index >= this.header.numRequiredSignatures) {
|
||||
const unsignedAccountIndex = index - numSignedAccounts;
|
||||
const numUnsignedAccounts = numStaticAccountKeys - numSignedAccounts;
|
||||
const numWritableUnsignedAccounts = numUnsignedAccounts - this.header.numReadonlyUnsignedAccounts;
|
||||
return unsignedAccountIndex < numWritableUnsignedAccounts;
|
||||
} else {
|
||||
const numWritableSignedAccounts = numSignedAccounts - this.header.numReadonlySignedAccounts;
|
||||
return index < numWritableSignedAccounts;
|
||||
}
|
||||
}
|
||||
resolveAddressTableLookups(addressLookupTableAccounts) {
|
||||
const accountKeysFromLookups = {
|
||||
writable: [],
|
||||
readonly: []
|
||||
};
|
||||
for (const tableLookup of this.addressTableLookups) {
|
||||
const tableAccount = addressLookupTableAccounts.find((account) => account.key.equals(tableLookup.accountKey));
|
||||
if (!tableAccount) {
|
||||
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
||||
}
|
||||
for (const index of tableLookup.writableIndexes) {
|
||||
if (index < tableAccount.state.addresses.length) {
|
||||
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
||||
} else {
|
||||
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
||||
}
|
||||
}
|
||||
for (const index of tableLookup.readonlyIndexes) {
|
||||
if (index < tableAccount.state.addresses.length) {
|
||||
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
||||
} else {
|
||||
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return accountKeysFromLookups;
|
||||
}
|
||||
static compile(args) {
|
||||
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
||||
const addressTableLookups = new Array();
|
||||
const accountKeysFromLookups = {
|
||||
writable: new Array(),
|
||||
readonly: new Array()
|
||||
};
|
||||
const lookupTableAccounts = args.addressLookupTableAccounts || [];
|
||||
for (const lookupTable of lookupTableAccounts) {
|
||||
const extractResult = compiledKeys.extractTableLookup(lookupTable);
|
||||
if (extractResult !== void 0) {
|
||||
const [addressTableLookup, {
|
||||
writable,
|
||||
readonly
|
||||
}] = extractResult;
|
||||
addressTableLookups.push(addressTableLookup);
|
||||
accountKeysFromLookups.writable.push(...writable);
|
||||
accountKeysFromLookups.readonly.push(...readonly);
|
||||
}
|
||||
}
|
||||
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
||||
const accountKeys = new MessageAccountKeys(staticAccountKeys, accountKeysFromLookups);
|
||||
const compiledInstructions = accountKeys.compileInstructions(args.instructions);
|
||||
return new _MessageV0({
|
||||
header,
|
||||
staticAccountKeys,
|
||||
recentBlockhash: args.recentBlockhash,
|
||||
compiledInstructions,
|
||||
addressTableLookups
|
||||
});
|
||||
}
|
||||
serialize() {
|
||||
const encodedStaticAccountKeysLength = Array();
|
||||
encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
|
||||
const serializedInstructions = this.serializeInstructions();
|
||||
const encodedInstructionsLength = Array();
|
||||
encodeLength(encodedInstructionsLength, this.compiledInstructions.length);
|
||||
const serializedAddressTableLookups = this.serializeAddressTableLookups();
|
||||
const encodedAddressTableLookupsLength = Array();
|
||||
encodeLength(encodedAddressTableLookupsLength, this.addressTableLookups.length);
|
||||
const messageLayout = BufferLayout.struct([BufferLayout.u8("prefix"), BufferLayout.struct([BufferLayout.u8("numRequiredSignatures"), BufferLayout.u8("numReadonlySignedAccounts"), BufferLayout.u8("numReadonlyUnsignedAccounts")], "header"), BufferLayout.blob(encodedStaticAccountKeysLength.length, "staticAccountKeysLength"), BufferLayout.seq(publicKey(), this.staticAccountKeys.length, "staticAccountKeys"), publicKey("recentBlockhash"), BufferLayout.blob(encodedInstructionsLength.length, "instructionsLength"), BufferLayout.blob(serializedInstructions.length, "serializedInstructions"), BufferLayout.blob(encodedAddressTableLookupsLength.length, "addressTableLookupsLength"), BufferLayout.blob(serializedAddressTableLookups.length, "serializedAddressTableLookups")]);
|
||||
const serializedMessage = new Uint8Array(PACKET_DATA_SIZE);
|
||||
const MESSAGE_VERSION_0_PREFIX = 1 << 7;
|
||||
const serializedMessageLength = messageLayout.encode({
|
||||
prefix: MESSAGE_VERSION_0_PREFIX,
|
||||
header: this.header,
|
||||
staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
|
||||
staticAccountKeys: this.staticAccountKeys.map((key) => key.toBytes()),
|
||||
recentBlockhash: import_bs58.default.decode(this.recentBlockhash),
|
||||
instructionsLength: new Uint8Array(encodedInstructionsLength),
|
||||
serializedInstructions,
|
||||
addressTableLookupsLength: new Uint8Array(encodedAddressTableLookupsLength),
|
||||
serializedAddressTableLookups
|
||||
}, serializedMessage);
|
||||
return serializedMessage.slice(0, serializedMessageLength);
|
||||
}
|
||||
serializeInstructions() {
|
||||
let serializedLength = 0;
|
||||
const serializedInstructions = new Uint8Array(PACKET_DATA_SIZE);
|
||||
for (const instruction of this.compiledInstructions) {
|
||||
const encodedAccountKeyIndexesLength = Array();
|
||||
encodeLength(encodedAccountKeyIndexesLength, instruction.accountKeyIndexes.length);
|
||||
const encodedDataLength = Array();
|
||||
encodeLength(encodedDataLength, instruction.data.length);
|
||||
const instructionLayout = BufferLayout.struct([BufferLayout.u8("programIdIndex"), BufferLayout.blob(encodedAccountKeyIndexesLength.length, "encodedAccountKeyIndexesLength"), BufferLayout.seq(BufferLayout.u8(), instruction.accountKeyIndexes.length, "accountKeyIndexes"), BufferLayout.blob(encodedDataLength.length, "encodedDataLength"), BufferLayout.blob(instruction.data.length, "data")]);
|
||||
serializedLength += instructionLayout.encode({
|
||||
programIdIndex: instruction.programIdIndex,
|
||||
encodedAccountKeyIndexesLength: new Uint8Array(encodedAccountKeyIndexesLength),
|
||||
accountKeyIndexes: instruction.accountKeyIndexes,
|
||||
encodedDataLength: new Uint8Array(encodedDataLength),
|
||||
data: instruction.data
|
||||
}, serializedInstructions, serializedLength);
|
||||
}
|
||||
return serializedInstructions.slice(0, serializedLength);
|
||||
}
|
||||
serializeAddressTableLookups() {
|
||||
let serializedLength = 0;
|
||||
const serializedAddressTableLookups = new Uint8Array(PACKET_DATA_SIZE);
|
||||
for (const lookup of this.addressTableLookups) {
|
||||
const encodedWritableIndexesLength = Array();
|
||||
encodeLength(encodedWritableIndexesLength, lookup.writableIndexes.length);
|
||||
const encodedReadonlyIndexesLength = Array();
|
||||
encodeLength(encodedReadonlyIndexesLength, lookup.readonlyIndexes.length);
|
||||
const addressTableLookupLayout = BufferLayout.struct([publicKey("accountKey"), BufferLayout.blob(encodedWritableIndexesLength.length, "encodedWritableIndexesLength"), BufferLayout.seq(BufferLayout.u8(), lookup.writableIndexes.length, "writableIndexes"), BufferLayout.blob(encodedReadonlyIndexesLength.length, "encodedReadonlyIndexesLength"), BufferLayout.seq(BufferLayout.u8(), lookup.readonlyIndexes.length, "readonlyIndexes")]);
|
||||
serializedLength += addressTableLookupLayout.encode({
|
||||
accountKey: lookup.accountKey.toBytes(),
|
||||
encodedWritableIndexesLength: new Uint8Array(encodedWritableIndexesLength),
|
||||
writableIndexes: lookup.writableIndexes,
|
||||
encodedReadonlyIndexesLength: new Uint8Array(encodedReadonlyIndexesLength),
|
||||
readonlyIndexes: lookup.readonlyIndexes
|
||||
}, serializedAddressTableLookups, serializedLength);
|
||||
}
|
||||
return serializedAddressTableLookups.slice(0, serializedLength);
|
||||
}
|
||||
static deserialize(serializedMessage) {
|
||||
let byteArray = [...serializedMessage];
|
||||
const prefix = guardedShift(byteArray);
|
||||
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
||||
assert2(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
||||
const version2 = maskedPrefix;
|
||||
assert2(version2 === 0, `Expected versioned message with version 0 but found version ${version2}`);
|
||||
const header = {
|
||||
numRequiredSignatures: guardedShift(byteArray),
|
||||
numReadonlySignedAccounts: guardedShift(byteArray),
|
||||
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
||||
};
|
||||
const staticAccountKeys = [];
|
||||
const staticAccountKeysLength = decodeLength(byteArray);
|
||||
for (let i2 = 0; i2 < staticAccountKeysLength; i2++) {
|
||||
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
||||
}
|
||||
const recentBlockhash = import_bs58.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
||||
const instructionCount = decodeLength(byteArray);
|
||||
const compiledInstructions = [];
|
||||
for (let i2 = 0; i2 < instructionCount; i2++) {
|
||||
const programIdIndex = guardedShift(byteArray);
|
||||
const accountKeyIndexesLength = decodeLength(byteArray);
|
||||
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
||||
const dataLength = decodeLength(byteArray);
|
||||
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
||||
compiledInstructions.push({
|
||||
programIdIndex,
|
||||
accountKeyIndexes,
|
||||
data
|
||||
});
|
||||
}
|
||||
const addressTableLookupsCount = decodeLength(byteArray);
|
||||
const addressTableLookups = [];
|
||||
for (let i2 = 0; i2 < addressTableLookupsCount; i2++) {
|
||||
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
||||
const writableIndexesLength = decodeLength(byteArray);
|
||||
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
||||
const readonlyIndexesLength = decodeLength(byteArray);
|
||||
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
||||
addressTableLookups.push({
|
||||
accountKey,
|
||||
writableIndexes,
|
||||
readonlyIndexes
|
||||
});
|
||||
}
|
||||
return new _MessageV0({
|
||||
header,
|
||||
staticAccountKeys,
|
||||
recentBlockhash,
|
||||
compiledInstructions,
|
||||
addressTableLookups
|
||||
});
|
||||
}
|
||||
};
|
||||
var VersionedMessage = {
|
||||
deserializeMessageVersion(serializedMessage) {
|
||||
const prefix = serializedMessage[0];
|
||||
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
||||
if (maskedPrefix === prefix) {
|
||||
return "legacy";
|
||||
}
|
||||
return maskedPrefix;
|
||||
},
|
||||
deserialize: (serializedMessage) => {
|
||||
const version2 = VersionedMessage.deserializeMessageVersion(serializedMessage);
|
||||
if (version2 === "legacy") {
|
||||
return Message.from(serializedMessage);
|
||||
}
|
||||
if (version2 === 0) {
|
||||
return MessageV0.deserialize(serializedMessage);
|
||||
} else {
|
||||
throw new Error(`Transaction message version ${version2} deserialization is not supported`);
|
||||
}
|
||||
}
|
||||
};
|
||||
var DEFAULT_SIGNATURE = import_buffer2.Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
||||
var TransactionInstruction = class {
|
||||
constructor(opts) {
|
||||
@@ -13196,9 +13453,9 @@ var Transaction = class _Transaction {
|
||||
isWritable: true
|
||||
});
|
||||
}
|
||||
for (const signature of this.signatures) {
|
||||
for (const signature2 of this.signatures) {
|
||||
const uniqueIndex = uniqueMetas.findIndex((x) => {
|
||||
return x.pubkey.equals(signature.publicKey);
|
||||
return x.pubkey.equals(signature2.publicKey);
|
||||
});
|
||||
if (uniqueIndex > -1) {
|
||||
if (!uniqueMetas[uniqueIndex].isSigner) {
|
||||
@@ -13206,7 +13463,7 @@ var Transaction = class _Transaction {
|
||||
console.warn("Transaction references a signature that is unnecessary, only the fee payer and instruction signer accounts should sign a transaction. This behavior is deprecated and will throw an error in the next major version release.");
|
||||
}
|
||||
} else {
|
||||
throw new Error(`unknown signer: ${signature.publicKey.toString()}`);
|
||||
throw new Error(`unknown signer: ${signature2.publicKey.toString()}`);
|
||||
}
|
||||
}
|
||||
let numRequiredSignatures = 0;
|
||||
@@ -13392,8 +13649,8 @@ var Transaction = class _Transaction {
|
||||
_partialSign(message, ...signers) {
|
||||
const signData = message.serialize();
|
||||
signers.forEach((signer) => {
|
||||
const signature = sign(signData, signer.secretKey);
|
||||
this._addSignature(signer.publicKey, toBuffer(signature));
|
||||
const signature2 = sign(signData, signer.secretKey);
|
||||
this._addSignature(signer.publicKey, toBuffer(signature2));
|
||||
});
|
||||
}
|
||||
/**
|
||||
@@ -13404,20 +13661,20 @@ var Transaction = class _Transaction {
|
||||
* @param {PublicKey} pubkey Public key that will be added to the transaction.
|
||||
* @param {Buffer} signature An externally created signature to add to the transaction.
|
||||
*/
|
||||
addSignature(pubkey, signature) {
|
||||
addSignature(pubkey, signature2) {
|
||||
this._compile();
|
||||
this._addSignature(pubkey, signature);
|
||||
this._addSignature(pubkey, signature2);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_addSignature(pubkey, signature) {
|
||||
assert2(signature.length === 64);
|
||||
_addSignature(pubkey, signature2) {
|
||||
assert2(signature2.length === 64);
|
||||
const index = this.signatures.findIndex((sigpair) => pubkey.equals(sigpair.publicKey));
|
||||
if (index < 0) {
|
||||
throw new Error(`unknown signer: ${pubkey.toString()}`);
|
||||
}
|
||||
this.signatures[index].signature = import_buffer2.Buffer.from(signature);
|
||||
this.signatures[index].signature = import_buffer2.Buffer.from(signature2);
|
||||
}
|
||||
/**
|
||||
* Verify signatures of a Transaction
|
||||
@@ -13436,15 +13693,15 @@ var Transaction = class _Transaction {
|
||||
_getMessageSignednessErrors(message, requireAllSignatures) {
|
||||
const errors = {};
|
||||
for (const {
|
||||
signature,
|
||||
signature: signature2,
|
||||
publicKey: publicKey2
|
||||
} of this.signatures) {
|
||||
if (signature === null) {
|
||||
if (signature2 === null) {
|
||||
if (requireAllSignatures) {
|
||||
(errors.missing ||= []).push(publicKey2);
|
||||
}
|
||||
} else {
|
||||
if (!verify(signature, message, publicKey2.toBytes())) {
|
||||
if (!verify(signature2, message, publicKey2.toBytes())) {
|
||||
(errors.invalid ||= []).push(publicKey2);
|
||||
}
|
||||
}
|
||||
@@ -13498,11 +13755,11 @@ Missing signature for public key${sigErrors.missing.length === 1 ? "" : "(s)"} [
|
||||
assert2(signatures.length < 256);
|
||||
import_buffer2.Buffer.from(signatureCount).copy(wireTransaction, 0);
|
||||
signatures.forEach(({
|
||||
signature
|
||||
signature: signature2
|
||||
}, index) => {
|
||||
if (signature !== null) {
|
||||
assert2(signature.length === 64, `signature has invalid length`);
|
||||
import_buffer2.Buffer.from(signature).copy(wireTransaction, signatureCount.length + index * 64);
|
||||
if (signature2 !== null) {
|
||||
assert2(signature2.length === 64, `signature has invalid length`);
|
||||
import_buffer2.Buffer.from(signature2).copy(wireTransaction, signatureCount.length + index * 64);
|
||||
}
|
||||
});
|
||||
signData.copy(wireTransaction, signatureCount.length + signatures.length * 64);
|
||||
@@ -13545,8 +13802,8 @@ Missing signature for public key${sigErrors.missing.length === 1 ? "" : "(s)"} [
|
||||
const signatureCount = decodeLength(byteArray);
|
||||
let signatures = [];
|
||||
for (let i2 = 0; i2 < signatureCount; i2++) {
|
||||
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
||||
signatures.push(import_bs58.default.encode(import_buffer2.Buffer.from(signature)));
|
||||
const signature2 = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
||||
signatures.push(import_bs58.default.encode(import_buffer2.Buffer.from(signature2)));
|
||||
}
|
||||
return _Transaction.populate(Message.from(byteArray), signatures);
|
||||
}
|
||||
@@ -13564,9 +13821,9 @@ Missing signature for public key${sigErrors.missing.length === 1 ? "" : "(s)"} [
|
||||
if (message.header.numRequiredSignatures > 0) {
|
||||
transaction.feePayer = message.accountKeys[0];
|
||||
}
|
||||
signatures.forEach((signature, index) => {
|
||||
signatures.forEach((signature2, index) => {
|
||||
const sigPubkeyPair = {
|
||||
signature: signature == import_bs58.default.encode(DEFAULT_SIGNATURE) ? null : import_bs58.default.decode(signature),
|
||||
signature: signature2 == import_bs58.default.encode(DEFAULT_SIGNATURE) ? null : import_bs58.default.decode(signature2),
|
||||
publicKey: message.accountKeys[index]
|
||||
};
|
||||
transaction.signatures.push(sigPubkeyPair);
|
||||
@@ -13591,6 +13848,65 @@ Missing signature for public key${sigErrors.missing.length === 1 ? "" : "(s)"} [
|
||||
return transaction;
|
||||
}
|
||||
};
|
||||
var VersionedTransaction = class _VersionedTransaction {
|
||||
get version() {
|
||||
return this.message.version;
|
||||
}
|
||||
constructor(message, signatures) {
|
||||
this.signatures = void 0;
|
||||
this.message = void 0;
|
||||
if (signatures !== void 0) {
|
||||
assert2(signatures.length === message.header.numRequiredSignatures, "Expected signatures length to be equal to the number of required signatures");
|
||||
this.signatures = signatures;
|
||||
} else {
|
||||
const defaultSignatures = [];
|
||||
for (let i2 = 0; i2 < message.header.numRequiredSignatures; i2++) {
|
||||
defaultSignatures.push(new Uint8Array(SIGNATURE_LENGTH_IN_BYTES));
|
||||
}
|
||||
this.signatures = defaultSignatures;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
serialize() {
|
||||
const serializedMessage = this.message.serialize();
|
||||
const encodedSignaturesLength = Array();
|
||||
encodeLength(encodedSignaturesLength, this.signatures.length);
|
||||
const transactionLayout = BufferLayout.struct([BufferLayout.blob(encodedSignaturesLength.length, "encodedSignaturesLength"), BufferLayout.seq(signature(), this.signatures.length, "signatures"), BufferLayout.blob(serializedMessage.length, "serializedMessage")]);
|
||||
const serializedTransaction = new Uint8Array(2048);
|
||||
const serializedTransactionLength = transactionLayout.encode({
|
||||
encodedSignaturesLength: new Uint8Array(encodedSignaturesLength),
|
||||
signatures: this.signatures,
|
||||
serializedMessage
|
||||
}, serializedTransaction);
|
||||
return serializedTransaction.slice(0, serializedTransactionLength);
|
||||
}
|
||||
static deserialize(serializedTransaction) {
|
||||
let byteArray = [...serializedTransaction];
|
||||
const signatures = [];
|
||||
const signaturesLength = decodeLength(byteArray);
|
||||
for (let i2 = 0; i2 < signaturesLength; i2++) {
|
||||
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
||||
}
|
||||
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
||||
return new _VersionedTransaction(message, signatures);
|
||||
}
|
||||
sign(signers) {
|
||||
const messageData = this.message.serialize();
|
||||
const signerPubkeys = this.message.staticAccountKeys.slice(0, this.message.header.numRequiredSignatures);
|
||||
for (const signer of signers) {
|
||||
const signerIndex = signerPubkeys.findIndex((pubkey) => pubkey.equals(signer.publicKey));
|
||||
assert2(signerIndex >= 0, `Cannot sign with non signer key ${signer.publicKey.toBase58()}`);
|
||||
this.signatures[signerIndex] = sign(messageData, signer.secretKey);
|
||||
}
|
||||
}
|
||||
addSignature(publicKey2, signature2) {
|
||||
assert2(signature2.byteLength === 64, "Signature must be 64 bytes long");
|
||||
const signerPubkeys = this.message.staticAccountKeys.slice(0, this.message.header.numRequiredSignatures);
|
||||
const signerIndex = signerPubkeys.findIndex((pubkey) => pubkey.equals(publicKey2));
|
||||
assert2(signerIndex >= 0, `Can not add signature; \`${publicKey2.toBase58()}\` is not required to sign this transaction`);
|
||||
this.signatures[signerIndex] = signature2;
|
||||
}
|
||||
};
|
||||
var NUM_TICKS_PER_SECOND = 160;
|
||||
var DEFAULT_TICKS_PER_SLOT = 64;
|
||||
var NUM_SLOTS_PER_SECOND = NUM_TICKS_PER_SECOND / DEFAULT_TICKS_PER_SLOT;
|
||||
@@ -13607,7 +13923,7 @@ var SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey("SysvarStakeHistory1111111111111
|
||||
var SendTransactionError = class extends Error {
|
||||
constructor({
|
||||
action,
|
||||
signature,
|
||||
signature: signature2,
|
||||
transactionMessage,
|
||||
logs
|
||||
}) {
|
||||
@@ -13617,7 +13933,7 @@ ${JSON.stringify(logs.slice(-10), null, 2)}. ` : "";
|
||||
let message;
|
||||
switch (action) {
|
||||
case "send":
|
||||
message = `Transaction ${signature} resulted in an error.
|
||||
message = `Transaction ${signature2} resulted in an error.
|
||||
${transactionMessage}. ` + maybeLogsOutput + guideText;
|
||||
break;
|
||||
case "simulate":
|
||||
@@ -13633,7 +13949,7 @@ Message: ${transactionMessage}.
|
||||
this.signature = void 0;
|
||||
this.transactionMessage = void 0;
|
||||
this.transactionLogs = void 0;
|
||||
this.signature = signature;
|
||||
this.signature = signature2;
|
||||
this.transactionMessage = transactionMessage;
|
||||
this.transactionLogs = logs ? logs : void 0;
|
||||
}
|
||||
@@ -13675,12 +13991,12 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
||||
maxRetries: options.maxRetries,
|
||||
minContextSlot: options.minContextSlot
|
||||
};
|
||||
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
||||
const signature2 = await connection.sendTransaction(transaction, signers, sendOptions);
|
||||
let status;
|
||||
if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
|
||||
status = (await connection.confirmTransaction({
|
||||
abortSignal: options?.abortSignal,
|
||||
signature,
|
||||
signature: signature2,
|
||||
blockhash: transaction.recentBlockhash,
|
||||
lastValidBlockHeight: transaction.lastValidBlockHeight
|
||||
}, options && options.commitment)).value;
|
||||
@@ -13694,25 +14010,25 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
||||
minContextSlot: transaction.minNonceContextSlot,
|
||||
nonceAccountPubkey,
|
||||
nonceValue: transaction.nonceInfo.nonce,
|
||||
signature
|
||||
signature: signature2
|
||||
}, options && options.commitment)).value;
|
||||
} else {
|
||||
if (options?.abortSignal != null) {
|
||||
console.warn("sendAndConfirmTransaction(): A transaction with a deprecated confirmation strategy was supplied along with an `abortSignal`. Only transactions having `lastValidBlockHeight` or a combination of `nonceInfo` and `minNonceContextSlot` are abortable.");
|
||||
}
|
||||
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
||||
status = (await connection.confirmTransaction(signature2, options && options.commitment)).value;
|
||||
}
|
||||
if (status.err) {
|
||||
if (signature != null) {
|
||||
if (signature2 != null) {
|
||||
throw new SendTransactionError({
|
||||
action: "send",
|
||||
signature,
|
||||
signature: signature2,
|
||||
transactionMessage: `Status: (${JSON.stringify(status)})`
|
||||
});
|
||||
}
|
||||
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
||||
throw new Error(`Transaction ${signature2} failed (${JSON.stringify(status)})`);
|
||||
}
|
||||
return signature;
|
||||
return signature2;
|
||||
}
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
@@ -15218,14 +15534,14 @@ var Ed25519Program = class _Ed25519Program {
|
||||
const {
|
||||
publicKey: publicKey2,
|
||||
message,
|
||||
signature,
|
||||
signature: signature2,
|
||||
instructionIndex
|
||||
} = params;
|
||||
assert2(publicKey2.length === PUBLIC_KEY_BYTES$1, `Public Key must be ${PUBLIC_KEY_BYTES$1} bytes but received ${publicKey2.length} bytes`);
|
||||
assert2(signature.length === SIGNATURE_BYTES, `Signature must be ${SIGNATURE_BYTES} bytes but received ${signature.length} bytes`);
|
||||
assert2(signature2.length === SIGNATURE_BYTES, `Signature must be ${SIGNATURE_BYTES} bytes but received ${signature2.length} bytes`);
|
||||
const publicKeyOffset = ED25519_INSTRUCTION_LAYOUT.span;
|
||||
const signatureOffset = publicKeyOffset + publicKey2.length;
|
||||
const messageDataOffset = signatureOffset + signature.length;
|
||||
const messageDataOffset = signatureOffset + signature2.length;
|
||||
const numSignatures = 1;
|
||||
const instructionData = import_buffer2.Buffer.alloc(messageDataOffset + message.length);
|
||||
const index = instructionIndex == null ? 65535 : instructionIndex;
|
||||
@@ -15241,7 +15557,7 @@ var Ed25519Program = class _Ed25519Program {
|
||||
messageInstructionIndex: index
|
||||
}, instructionData);
|
||||
instructionData.fill(publicKey2, publicKeyOffset);
|
||||
instructionData.fill(signature, signatureOffset);
|
||||
instructionData.fill(signature2, signatureOffset);
|
||||
instructionData.fill(message, messageDataOffset);
|
||||
return new TransactionInstruction({
|
||||
keys: [],
|
||||
@@ -15263,11 +15579,11 @@ var Ed25519Program = class _Ed25519Program {
|
||||
try {
|
||||
const keypair = Keypair.fromSecretKey(privateKey);
|
||||
const publicKey2 = keypair.publicKey.toBytes();
|
||||
const signature = sign(message, keypair.secretKey);
|
||||
const signature2 = sign(message, keypair.secretKey);
|
||||
return this.createInstructionWithPublicKey({
|
||||
publicKey: publicKey2,
|
||||
message,
|
||||
signature,
|
||||
signature: signature2,
|
||||
instructionIndex
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -15277,8 +15593,8 @@ var Ed25519Program = class _Ed25519Program {
|
||||
};
|
||||
Ed25519Program.programId = new PublicKey("Ed25519SigVerify111111111111111111111111111");
|
||||
var ecdsaSign = (msgHash, privKey) => {
|
||||
const signature = secp256k1.sign(msgHash, privKey);
|
||||
return [signature.toCompactRawBytes(), signature.recovery];
|
||||
const signature2 = secp256k1.sign(msgHash, privKey);
|
||||
return [signature2.toCompactRawBytes(), signature2.recovery];
|
||||
};
|
||||
secp256k1.utils.isValidPrivateKey;
|
||||
var publicKeyCreate = secp256k1.getPublicKey;
|
||||
@@ -15316,14 +15632,14 @@ var Secp256k1Program = class _Secp256k1Program {
|
||||
const {
|
||||
publicKey: publicKey2,
|
||||
message,
|
||||
signature,
|
||||
signature: signature2,
|
||||
recoveryId,
|
||||
instructionIndex
|
||||
} = params;
|
||||
return _Secp256k1Program.createInstructionWithEthAddress({
|
||||
ethAddress: _Secp256k1Program.publicKeyToEthAddress(publicKey2),
|
||||
message,
|
||||
signature,
|
||||
signature: signature2,
|
||||
recoveryId,
|
||||
instructionIndex
|
||||
});
|
||||
@@ -15336,7 +15652,7 @@ var Secp256k1Program = class _Secp256k1Program {
|
||||
const {
|
||||
ethAddress: rawAddress,
|
||||
message,
|
||||
signature,
|
||||
signature: signature2,
|
||||
recoveryId,
|
||||
instructionIndex = 0
|
||||
} = params;
|
||||
@@ -15354,7 +15670,7 @@ var Secp256k1Program = class _Secp256k1Program {
|
||||
const dataStart = 1 + SIGNATURE_OFFSETS_SERIALIZED_SIZE;
|
||||
const ethAddressOffset = dataStart;
|
||||
const signatureOffset = dataStart + ethAddress.length;
|
||||
const messageDataOffset = signatureOffset + signature.length + 1;
|
||||
const messageDataOffset = signatureOffset + signature2.length + 1;
|
||||
const numSignatures = 1;
|
||||
const instructionData = import_buffer2.Buffer.alloc(SECP256K1_INSTRUCTION_LAYOUT.span + message.length);
|
||||
SECP256K1_INSTRUCTION_LAYOUT.encode({
|
||||
@@ -15366,7 +15682,7 @@ var Secp256k1Program = class _Secp256k1Program {
|
||||
messageDataOffset,
|
||||
messageDataSize: message.length,
|
||||
messageInstructionIndex: instructionIndex,
|
||||
signature: toBuffer(signature),
|
||||
signature: toBuffer(signature2),
|
||||
ethAddress: toBuffer(ethAddress),
|
||||
recoveryId
|
||||
}, instructionData);
|
||||
@@ -15396,11 +15712,11 @@ var Secp256k1Program = class _Secp256k1Program {
|
||||
/* isCompressed */
|
||||
).slice(1);
|
||||
const messageHash = import_buffer2.Buffer.from(keccak_256(toBuffer(message)));
|
||||
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
||||
const [signature2, recoveryId] = ecdsaSign(messageHash, privateKey);
|
||||
return this.createInstructionWithPublicKey({
|
||||
publicKey: publicKey2,
|
||||
message,
|
||||
signature,
|
||||
signature: signature2,
|
||||
recoveryId,
|
||||
instructionIndex
|
||||
});
|
||||
@@ -16179,7 +16495,9 @@ var VoteAccountLayout = BufferLayout.struct([
|
||||
BufferLayout.struct([BufferLayout.nu64("slot"), BufferLayout.nu64("timestamp")], "lastTimestamp")
|
||||
]);
|
||||
export {
|
||||
PublicKey
|
||||
PublicKey,
|
||||
Transaction,
|
||||
VersionedTransaction
|
||||
};
|
||||
/*! Bundled license information:
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { PublicKey } from '@solana/web3.js';
|
||||
import { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
|
||||
|
||||
export { PublicKey };
|
||||
export { PublicKey, Transaction, VersionedTransaction };
|
||||
|
||||
@@ -24,6 +24,7 @@ export class WsJsonClient {
|
||||
this.ws = null;
|
||||
this.openPromise = null;
|
||||
this.pending = new Map();
|
||||
this.listeners = new Map();
|
||||
}
|
||||
|
||||
async open() {
|
||||
@@ -78,14 +79,53 @@ export class WsJsonClient {
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (data?.event) {
|
||||
this.emit(String(data?.op || ''), data);
|
||||
return;
|
||||
}
|
||||
const requestId = data?.requestId;
|
||||
if (!requestId) return;
|
||||
if (!requestId) {
|
||||
this.emit(String(data?.op || ''), data);
|
||||
return;
|
||||
}
|
||||
const slot = this.pending.get(requestId);
|
||||
if (!slot) return;
|
||||
if (!slot) {
|
||||
this.emit(String(data?.op || ''), data);
|
||||
return;
|
||||
}
|
||||
this.pending.delete(requestId);
|
||||
slot.resolve(data);
|
||||
}
|
||||
|
||||
on(op, handler) {
|
||||
const key = String(op || '').trim();
|
||||
if (!key || typeof handler !== 'function') {
|
||||
return () => {};
|
||||
}
|
||||
if (!this.listeners.has(key)) {
|
||||
this.listeners.set(key, new Set());
|
||||
}
|
||||
this.listeners.get(key).add(handler);
|
||||
return () => {
|
||||
const bucket = this.listeners.get(key);
|
||||
if (!bucket) return;
|
||||
bucket.delete(handler);
|
||||
if (!bucket.size) {
|
||||
this.listeners.delete(key);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
emit(op, payload) {
|
||||
const bucket = this.listeners.get(String(op || '').trim());
|
||||
if (!bucket?.size) return;
|
||||
for (const handler of [...bucket]) {
|
||||
try {
|
||||
handler(payload);
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
failPending(message) {
|
||||
const error = new Error(message);
|
||||
for (const slot of this.pending.values()) slot.reject(error);
|
||||
|
||||
Reference in New Issue
Block a user