Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ecclib not initalised #60

Open
DaBors opened this issue Jul 3, 2024 · 3 comments
Open

Ecclib not initalised #60

DaBors opened this issue Jul 3, 2024 · 3 comments
Labels
enhancement New feature or request low

Comments

@DaBors
Copy link

DaBors commented Jul 3, 2024

I was getting an "Invalid change address" error when I tried to create a stakingTransaction, after some investigation the issue was the following: 'No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance', I think it would be nice to show the underlying issue why the address validation failed.

export const isValidBitcoinAddress = (

I fixed the issue by calling the initEccLib() function, but as far as I understand it shouldn't be called from external sources (I couldn't find a call in the simple-staking repo). I'm using dynamic import for the btc-staking-ts not sure if that's might be the issue why the the Ecclib init wasn't called properly

Our tsconfig:

{
    "compilerOptions": {
        "target": "ESNext",
        "module": "Node16",
        "lib": [
            "dom",
            "dom.iterable",
            "esnext"
        ],
        "moduleResolution": "Node16",
        "sourceMap": true,
        "declaration": true,
        "declarationMap": true,
        "strict": true,
        "noUnusedLocals": true,
        "noImplicitReturns": true,
        "noImplicitOverride": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "importsNotUsedAsValues": "remove",
        "outDir": "dist",
        "rootDir": "src",
        "composite": true,
        "resolveJsonModule": true
    },
    "include": [
        "src/**/*.ts",
    ],
    "exclude": [
        "*.test.ts",
        "lib",
        "node_modules"
    ]
}
@jrwbabylonlab
Copy link
Contributor

hi @DaBors The initBTCCurve function is called in the simple-staking project: https://github.com/babylonchain/simple-staking/blob/dev/src/app/page.tsx#L201.

I don't think this issue is related to your tsconfig setup. The ECC library simply needs to be initialized for it to work. While it would be ideal not to expose the initialization method publicly, bitcoinjs-lib does not provide a straightforward way to check if ECC has already been initialized.

We might need to introduce a workaround if we still want to initialize the BTC curve within the library. Alternatively, we could refactor the code to make it a class with a constructor. However, for now, the best approach is to call the initialization function at the application layer.

@jrwbabylonlab jrwbabylonlab added the question Further information is requested label Jul 4, 2024
@DaBors
Copy link
Author

DaBors commented Jul 5, 2024

Oh missed that initialisation, my bad. I found this method getEccLib in the bitcoinjs-lib that gets you the ECC if it was initialises and otherwise throws an error and it's exported so it should be possible to use that to check if we have the ECC initialised or not.

In any case while the manual initialisation via initBTCCurve is required I think it would be nice to add it to the readme/docs. Also it might make sense to reraise this error on the isValidBitcoinAddress function instead of returning false as it's not that the address is invalid, but the setup is not properly initialised.

@jrwbabylonlab
Copy link
Contributor

make sense to me. but seems the priority is low atm. we will try pick it up later on

@jrwbabylonlab jrwbabylonlab added enhancement New feature or request low and removed question Further information is requested labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low
Projects
None yet
Development

No branches or pull requests

2 participants