Releases: solana-foundation/solana-web3.js
v1.92.0
v1.91.9
v1.91.8
The New web3.js – Technology Preview 3
tp3 (2024-04-25)
The next version of the @solana/web3.js Technology Preview brings a major change to how signed transactions are represented, in response to user feedback.
To install the third Technology Preview:
npm install --save @solana/web3.js@tp3Most notably, all *Transaction*() helpers have been renamed to *TransactionMessage*() to reflect what is actually being built when you build a transaction: the transaction message.
Before
const tx = pipe(
    createTransaction({ version: 0 }),
    tx => addTransactionFeePayer(payerAddress, tx),
    /* ... */
);After
const txMessage = pipe(
    createTransactionMessage({ version: 0 }),
    m => addTransactionMessageFeePayer(payerAddress, m),
    /* ... */
);We've introduced a new type to represent signed and partially signed messages. This type encapsulates the bytes of a transaction message – however they were serialized – and the ordered map of signer addresses to signatures. Reducing a transaction message to just those two things after the first signature is applied will make it harder for a subsequent signer to invalidate the existing signatures by _re_serializing the transaction message in such a way that the bytes or the order of signer addresses changes.
Try a demo of Technology Preview 3 in your browser at CodeSandbox.
Changelog since Technology Preview 2
- 
#2434
31916aeThanks @lorisleiva! - RenamedmapCodectotransformCodec - 
#2411
2e5af9fThanks @lorisleiva! - RenamedfixCodectofixCodecSize - 
#2352
125fc15Thanks @steveluscher! -SubtleCryptoassertion methods that can make their assertions synchronously are now synchronous, for performance. - 
#2329
478443fThanks @luu-alex! -createKeyPairFromBytes()now validates that the public key imported is the one that would be derived from the private key imported - 
#2383
ce1be3fThanks @lorisleiva! -getScalarEnumCodecis now calledgetEnumCodec - 
#2382
7e86583Thanks @lorisleiva! -getDataEnumCodecis now calledgetDiscriminatedUnionCodec - 
#2397
a548de2Thanks @lorisleiva! - Added a newaddCodecSizePrefixprimitiveconst codec = addCodecSizePrefix(getBase58Codec(), getU32Codec()); codec.encode("hello world"); // 0x0b00000068656c6c6f20776f726c64 // | └-- Our encoded base-58 string. // └-- Our encoded u32 size prefix.
 - 
#2419
89f399dThanks @lorisleiva! - Added newaddCodecSentinelprimitiveThe
addCodecSentinelfunction provides a new way of delimiting the size of a codec. It allows us to add a sentinel to the end of the encoded data and to read until that sentinel is found when decoding. It accepts any codec and aUint8Arraysentinel responsible for delimiting the encoded data.const codec = addCodecSentinel(getUtf8Codec(), new Uint8Array([255, 255])); codec.encode("hello"); // 0x68656c6c6fffff // | └-- Our sentinel. // └-- Our encoded string.
 - 
#2400
ebb03cdThanks @lorisleiva! - Added newcontainsBytesandgetConstantCodechelpersThe
containsByteshelper checks if aUint8Arraycontains anotherUint8Arrayat a given offset.containsBytes(new Uint8Array([1, 2, 3, 4]), new Uint8Array([2, 3]), 1); // true containsBytes(new Uint8Array([1, 2, 3, 4]), new Uint8Array([2, 3]), 2); // false
The
getConstantCodecfunction accepts anyUint8Arrayand returns aCodec<void>. When encoding, it will set the providedUint8Arrayas-is. When decoding, it will assert that the next bytes contain the providedUint8Arrayand move the offset forward.const codec = getConstantCodec(new Uint8Array([1, 2, 3])); codec.encode(undefined); // 0x010203 codec.decode(new Uint8Array([1, 2, 3])); // undefined codec.decode(new Uint8Array([1, 2, 4])); // Throws an error.
 - 
#2344
deb7b80Thanks @lorisleiva! - ImprovegetTupleCodectype inferences and performanceThe tuple codec now infers its encoded/decoded type from the provided codec array and uses the new
DrainOuterGenerichelper to reduce the number of TypeScript instantiations. - 
#2322
6dcf548Thanks @lorisleiva! - UseDrainOuterGenerichelper on codec type mappingsThis significantly reduces the number of TypeScript instantiations on object mappings,
which increases TypeScript performance and prevents "Type instantiation is excessively deep and possibly infinite" errors. - 
#2381
49a764cThanks [@lorisleiva](ht...