@5ive-tech/sdk 1.1.13 → 1.1.15
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/README.md +22 -0
- package/dist/FiveSDK.d.ts +43 -1
- package/dist/FiveSDK.js +6 -0
- package/dist/accounts/index.d.ts +10 -28
- package/dist/accounts/index.js +33 -61
- package/dist/assets/vm/five_vm_wasm.d.ts +8 -0
- package/dist/assets/vm/five_vm_wasm.js +25 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm +0 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm.d.ts +3 -0
- package/dist/bin/gen-types.js +0 -0
- package/dist/compiler/BytecodeCompiler.js +10 -6
- package/dist/compiler/source-normalization.d.ts +1 -0
- package/dist/compiler/source-normalization.js +67 -0
- package/dist/config/ProgramIdResolver.js +6 -2
- package/dist/constants/headers.d.ts +2 -0
- package/dist/constants/headers.js +2 -0
- package/dist/crypto/index.d.ts +8 -1
- package/dist/crypto/index.js +27 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/modules/accounts.js +1 -1
- package/dist/modules/deploy.js +167 -98
- package/dist/modules/execute.d.ts +5 -0
- package/dist/modules/execute.js +109 -50
- package/dist/modules/fees.js +2 -2
- package/dist/modules/namespaces.d.ts +11 -0
- package/dist/modules/namespaces.js +64 -0
- package/dist/program/FiveProgram.js +4 -3
- package/dist/program/TypeGenerator.js +8 -1
- package/dist/project/config.js +113 -1
- package/dist/project/workspace.d.ts +5 -0
- package/dist/testing/AccountTestFixture.js +3 -3
- package/dist/testing/TestDiscovery.d.ts +1 -0
- package/dist/testing/TestDiscovery.js +18 -2
- package/dist/testing/TestRunner.js +4 -1
- package/dist/types.d.ts +17 -6
- package/dist/types.js +2 -1
- package/dist/utils/abi.js +33 -10
- package/dist/utils/transaction.d.ts +16 -0
- package/dist/utils/transaction.js +81 -5
- package/dist/wasm/compiler/CompilationLogic.js +3 -3
- package/dist/wasm/vm.d.ts +2 -2
- package/dist/wasm/vm.js +10 -11
- package/package.json +1 -1
package/dist/crypto/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Five SDK crypto utilities.
|
|
3
3
|
*/
|
|
4
4
|
import bs58 from 'bs58';
|
|
5
|
-
import { randomBytes } from 'crypto';
|
|
5
|
+
import { createHash, randomBytes } from 'crypto';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
|
7
7
|
/**
|
|
8
8
|
* Program Derived Address (PDA) utilities - pure implementation
|
|
@@ -11,21 +11,20 @@ export class PDAUtils {
|
|
|
11
11
|
/**
|
|
12
12
|
* Derive script account using seed-based derivation compatible with SystemProgram.createAccountWithSeed
|
|
13
13
|
* @param bytecode - The bytecode to derive address for
|
|
14
|
+
* @param basePublicKey - The deployer/base public key used for createWithSeed
|
|
14
15
|
* @param programId - The Five VM program ID (required - no default to enforce explicit configuration)
|
|
15
16
|
*/
|
|
16
|
-
static async deriveScriptAccount(bytecode, programId) {
|
|
17
|
+
static async deriveScriptAccount(bytecode, basePublicKey, programId) {
|
|
17
18
|
try {
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// Use simplified approach; requires deployer's pubkey
|
|
26
|
-
// Return seed-based result that's compatible with System Program
|
|
19
|
+
const deployerKey = new PublicKey(basePublicKey);
|
|
20
|
+
const programKey = new PublicKey(programId);
|
|
21
|
+
const seed = createHash('sha256')
|
|
22
|
+
.update(Buffer.from(bytecode))
|
|
23
|
+
.digest('hex')
|
|
24
|
+
.slice(0, 32);
|
|
25
|
+
const address = await PublicKey.createWithSeed(deployerKey, seed, programKey);
|
|
27
26
|
return {
|
|
28
|
-
address:
|
|
27
|
+
address: address.toBase58(),
|
|
29
28
|
bump: 0, // Seed-based accounts don't use bumps
|
|
30
29
|
seed: seed
|
|
31
30
|
};
|
|
@@ -40,8 +39,8 @@ export class PDAUtils {
|
|
|
40
39
|
static async findProgramAddress(seeds, programId) {
|
|
41
40
|
const crypto = await import('crypto');
|
|
42
41
|
const programIdBytes = Base58Utils.decode(programId);
|
|
43
|
-
// Try bump
|
|
44
|
-
for (let bump = 255; bump >=
|
|
42
|
+
// Try the full Solana bump range from 255 down to 0.
|
|
43
|
+
for (let bump = 255; bump >= 0; bump--) {
|
|
45
44
|
const seedsWithBump = [...seeds, Buffer.from([bump])];
|
|
46
45
|
// Create the hash input
|
|
47
46
|
let hashInput = Buffer.alloc(0);
|
|
@@ -270,6 +269,20 @@ export class RentCalculator {
|
|
|
270
269
|
const rentExemption = Math.ceil((rentPerYear * this.RENT_EXEMPTION_THRESHOLD) / (365 * 24 * 60 * 60));
|
|
271
270
|
return rentExemption;
|
|
272
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Query rent from RPC when possible and fall back to local estimation otherwise.
|
|
274
|
+
*/
|
|
275
|
+
static async calculateRentExemptionWithConnection(accountSize, connection) {
|
|
276
|
+
if (connection?.getMinimumBalanceForRentExemption) {
|
|
277
|
+
try {
|
|
278
|
+
return await connection.getMinimumBalanceForRentExemption(accountSize);
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
// Fall back to local estimation below.
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return this.calculateRentExemption(accountSize);
|
|
285
|
+
}
|
|
273
286
|
/**
|
|
274
287
|
* Get estimated rent for script account based on bytecode size
|
|
275
288
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './wasm/vm.js';
|
|
|
15
15
|
export * from './wasm/compiler/index.js';
|
|
16
16
|
export * from './wasm/loader.js';
|
|
17
17
|
export * from './testing/index.js';
|
|
18
|
+
export * from './utils/abi.js';
|
|
18
19
|
export * from './program/index.js';
|
|
19
20
|
export * from './modules/namespaces.js';
|
|
20
21
|
export { ProgramIdResolver } from './config/ProgramIdResolver.js';
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export * from './wasm/vm.js';
|
|
|
17
17
|
export * from './wasm/compiler/index.js';
|
|
18
18
|
export * from './wasm/loader.js';
|
|
19
19
|
export * from './testing/index.js';
|
|
20
|
+
export * from './utils/abi.js';
|
|
20
21
|
// ==================== FiveProgram High-Level API ====================
|
|
21
22
|
export * from './program/index.js';
|
|
22
23
|
export * from './modules/namespaces.js';
|
package/dist/modules/accounts.js
CHANGED
|
@@ -255,7 +255,7 @@ export async function validateBytecodeEncoding(bytecode, debug = false) {
|
|
|
255
255
|
error: 'Invalid Five VM magic bytes (expected "5IVE")',
|
|
256
256
|
};
|
|
257
257
|
}
|
|
258
|
-
//
|
|
258
|
+
// ScriptBytecodeHeaderV1:
|
|
259
259
|
// 0-3: Magic
|
|
260
260
|
// 4-7: Features (u32 LE)
|
|
261
261
|
// 8: Public Function Count (u8)
|