Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-wasps-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/serializer": patch
---

Add `deserializeBox` function
5 changes: 5 additions & 0 deletions .changeset/eleven-horses-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/serializer": patch
---

Add `deserializeTransaction` function
5 changes: 5 additions & 0 deletions .changeset/floppy-wings-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/common": patch
---

Add offset support to `startsWith`
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4
Expand All @@ -35,6 +37,9 @@ jobs:
format:
name: Format
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4

Expand All @@ -53,6 +58,9 @@ jobs:
build-and-test-node:
name: "[node] build and test"
runs-on: ubuntu-latest
permissions:
contents: read

timeout-minutes: 20
strategy:
fail-fast: false
Expand All @@ -78,6 +86,8 @@ jobs:
build-and-test-bun:
name: "[bun] build and test"
runs-on: ubuntu-latest
permissions:
contents: read
timeout-minutes: 20
strategy:
fail-fast: false
Expand All @@ -102,6 +112,8 @@ jobs:
build-and-test-other-envs:
name: "[happy-dom, edge-runtime] test"
runs-on: ubuntu-latest
permissions:
contents: read
timeout-minutes: 20
strategy:
fail-fast: false
Expand Down Expand Up @@ -130,6 +142,8 @@ jobs:
publish-preview:
name: "Publish preview"
runs-on: ubuntu-latest
permissions:
pull-requests: write # to be able to comment on the pull requests
needs: build-and-test-node
if: success()
timeout-minutes: 20
Expand Down
100 changes: 100 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Advanced"

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
schedule:
- cron: "27 9 * * 1"

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
- language: javascript-typescript
build-mode: none
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Add any setup steps before running the `github/codeql-action/init` action.
# This includes steps like installing compilers or runtimes (`actions/setup-node`
# or others). This is typically only required for manual builds.
# - name: Setup runtime (example)
# uses: actions/setup-example@v1

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
2 changes: 2 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:

jobs:
coverage:
permissions:
contents: read
name: Check and submit
runs-on: ubuntu-latest
steps:
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@changesets/cli": "^2.29.2",
"@changesets/cli": "^2.29.3",
"@edge-runtime/vm": "^5.0.0",
"@fleet-sdk/common": "workspace:^",
"@fleet-sdk/crypto": "workspace:^",
"@types/diff": "^7.0.2",
"@vitest/coverage-v8": "^3.1.1",
"@vitest/coverage-v8": "^3.1.3",
"ergo-lib-wasm-nodejs": "^0.28.0",
"fast-check": "^4.1.1",
"happy-dom": "^17.4.4",
"happy-dom": "^17.4.6",
"npm-run-all": "^4.1.5",
"open-cli": "^8.0.0",
"sigmastate-js": "0.4.6",
"tsup": "^8.4.0",
"type-fest": "^4.40.0",
"type-fest": "^4.41.0",
"typescript": "^5.8.3",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^3.1.1"
"vitest": "^3.1.3"
},
"engines": {
"node": ">=18",
Expand All @@ -50,6 +50,9 @@
"pnpm": {
"requiredScripts": [
"build"
],
"onlyBuiltDependencies": [
"esbuild"
]
}
}
3 changes: 3 additions & 0 deletions packages/common/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const FEE_CONTRACT =
"1005040004000e36100204a00b08cd0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ea02d192a39a8cc7a701730073011001020402d19683030193a38cc7b2a57300000193c2b2a57301007473027303830108cdeeac93b1a57304";
export const RECOMMENDED_MIN_FEE_VALUE = BigInt(1100000);
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./utils";
export * from "./types";
export * from "./models/collection";
export * from "./error";
export * from "./constants";
11 changes: 11 additions & 0 deletions packages/common/src/utils/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,17 @@ describe("startsWith()", () => {
expect(startsWith(array, array)).toBeTruthy();
});

it("Should return true if starts with target with offset", () => {
// index: 0, 1, 2, 3, 4, 5, 6, 7
const array = [1, 2, 4, 5, 6, 7, 8, 9];

expect(startsWith(array, [2, 4], 1)).toBeTruthy();
expect(startsWith(array, [6, 7], 4)).toBeTruthy();
expect(startsWith(array, [9, 10], 7)).toBeFalsy();
expect(startsWith(array, [1], 0)).toBeTruthy();
expect(startsWith(array, array)).toBeTruthy();
});

it("Should return false for not starts with target", () => {
const array = [1, 2, 4, 5, 0];

Expand Down
29 changes: 10 additions & 19 deletions packages/common/src/utils/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,16 @@ export function areEqualBy<T>(
* startsWith(array, target2); // false
* ```
*/
export function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {
if (array === target) {
return true;
}

if (target.length > array.length) {
return false;
}
export function startsWith<T>(
array: ArrayLike<T>,
target: ArrayLike<T>,
offset = 0
): boolean {
if (array === target) return true;
if (target.length > array.length) return false;

for (let i = 0; i < target.length; i++) {
if (target[i] !== array[i]) {
return false;
}
if (target[i] !== array[i + offset]) return false;
}

return true;
Expand All @@ -239,16 +236,10 @@ export function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolea
* ```
*/
export function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {
if (array === target) {
return true;
}

if (target.length > array.length) {
return false;
}
if (array === target) return true;
if (target.length > array.length) return false;

const offset = array.length - target.length;

for (let i = target.length - 1; i >= 0; i--) {
if (target[i] !== array[i + offset]) {
return false;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/builder/pluginContext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import { NotAllowedTokenBurning } from "../errors";
import { OutputBuilder } from "./outputBuilder";
import { createPluginContext, type FleetPluginContext } from "./pluginContext";
import { RECOMMENDED_MIN_FEE_VALUE, TransactionBuilder } from "./transactionBuilder";
import { TransactionBuilder } from "./transactionBuilder";
import { RECOMMENDED_MIN_FEE_VALUE } from "@fleet-sdk/common";

describe("Plugin context", () => {
const creationHeight = 894169;
Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/builder/transactionBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ import {
OutputBuilder,
SAFE_MIN_BOX_VALUE
} from "./outputBuilder";
import {
FEE_CONTRACT,
RECOMMENDED_MIN_FEE_VALUE,
TransactionBuilder
} from "./transactionBuilder";
import { TransactionBuilder } from "./transactionBuilder";
import { mockUTxO } from "packages/mock-chain/src";
import { FEE_CONTRACT, RECOMMENDED_MIN_FEE_VALUE } from "@fleet-sdk/common";

const height = 844540;
const a1 = {
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/builder/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import {
byteSizeOf,
chunk,
ensureBigInt,
FEE_CONTRACT,
first,
isDefined,
isHex,
isUndefined,
Network,
RECOMMENDED_MIN_FEE_VALUE,
some,
utxoDiff,
utxoSum
Expand Down Expand Up @@ -46,10 +48,6 @@ export type SelectorCallback = (selector: SelectorSettings) => void;
export type FleetPlugin = (context: FleetPluginContext) => void;
export type CollectionLike<T> = { toArray(): T[] };

export const RECOMMENDED_MIN_FEE_VALUE = BigInt(1100000);
export const FEE_CONTRACT =
"1005040004000e36100204a00b08cd0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ea02d192a39a8cc7a701730073011001020402d19683030193a38cc7b2a57300000193c2b2a57301007473027303830108cdeeac93b1a57304";

type EjectorContext = {
inputs: InputsCollection;
dataInputs: InputsCollection;
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ export * from "./builder";
export * from "./models";
export * from "./errors";
export * from "./constantSerializer";
export { AddressType, Network } from "@fleet-sdk/common";
export {
AddressType,
Network,
RECOMMENDED_MIN_FEE_VALUE,
FEE_CONTRACT
} from "@fleet-sdk/common";
export type { Box, Amount, TokenAmount } from "@fleet-sdk/common";
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { first } from "@fleet-sdk/common";
import { first, RECOMMENDED_MIN_FEE_VALUE } from "@fleet-sdk/common";
import { describe, expect, it } from "vitest";
import { OutputBuilder, SAFE_MIN_BOX_VALUE } from "../../builder/outputBuilder";
import { RECOMMENDED_MIN_FEE_VALUE } from "../../builder/transactionBuilder";
import { NotFoundError } from "../../errors";
import { OutputsCollection } from "./outputsCollection";

Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/models/ergoAddress.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AddressType, Network } from "@fleet-sdk/common";
import { AddressType, Network, FEE_CONTRACT } from "@fleet-sdk/common";
import { blake2b256, hex } from "@fleet-sdk/crypto";
import { describe, expect, it, test } from "vitest";
import { FEE_CONTRACT } from "../builder";
import {
ergoTsTestVectors,
FEE_MAINNET_ADDRESS_TV,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/models/ergoAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {
const P2PK_ERGOTREE_PREFIX = hex.decode("0008cd");
const P2PK_ERGOTREE_LENGTH = 36;

const P2SH_ERGOTREE_SUFFIX = hex.decode("d40801");
const P2SH_ERGOTREE_PREFIX = hex.decode("00ea02d193b4cbe4e3010e040004300e18");
const P2SH_ERGOTREE_SUFFIX = hex.decode("d40801");
const P2SH_ERGOTREE_LENGTH = 44;
const P2SH_HASH_LENGTH = 24;

Expand Down
Loading