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

error: invalid version byte. expected 48, got 16 trying to authorizeEntry #1020

Open
kalepail opened this issue Jul 24, 2024 · 0 comments
Open
Assignees
Labels

Comments

@kalepail
Copy link
Contributor

kalepail commented Jul 24, 2024

Describe the bug

When trying to authorizeEntry I'm getting an error:

356 |   var expectedVersion = versionBytes[versionByteName];
357 |   if (expectedVersion === undefined) {
358 |     throw new Error("".concat(versionByteName, " is not a valid version byte name. ") + "Expected one of ".concat(Object.keys(versionBytes).join(', ')));
359 |   }
360 |   if (versionByte !== expectedVersion) {
361 |     throw new Error("invalid version byte. expected ".concat(expectedVersion, ", got ").concat(versionByte));
                ^
error: invalid version byte. expected 48, got 16
      at decodeCheck (/Users/tylervanderhoeven/Desktop/check-auth-puzzle/bun_tests/node_modules/@stellar/stellar-base/lib/strkey.js:361:11)
      at decodeEd25519PublicKey (/Users/tylervanderhoeven/Desktop/check-auth-puzzle/bun_tests/node_modules/@stellar/stellar-base/lib/strkey.js:77:14)
      at fromPublicKey (/Users/tylervanderhoeven/Desktop/check-auth-puzzle/bun_tests/node_modules/@stellar/stellar-base/lib/keypair.js:286:19)
      at _callee$ (/Users/tylervanderhoeven/Desktop/check-auth-puzzle/bun_tests/node_modules/@stellar/stellar-base/lib/auth.js:199:15)
      at tryCatch (/Users/tylervanderhoeven/Desktop/check-auth-puzzle/bun_tests/node_modules/@stellar/stellar-base/lib/auth.js:17:1060)
      at /Users/tylervanderhoeven/Desktop/check-auth-puzzle/bun_tests/node_modules/@stellar/stellar-base/lib/auth.js:17:3008
      at /Users/tylervanderhoeven/Desktop/check-auth-puzzle/bun_tests/node_modules/@stellar/stellar-base/lib/auth.js:17:1694
      at asyncGeneratorStep (/Users/tylervanderhoeven/Desktop/check-auth-puzzle/bun_tests/node_modules/@stellar/stellar-base/lib/auth.js:18:66)
      at _next (/Users/tylervanderhoeven/Desktop/check-auth-puzzle/bun_tests/node_modules/@stellar/stellar-base/lib/auth.js:19:163)

Bun v1.1.8 (macOS arm64)

What version are you on?

"@stellar/stellar-sdk": "^12.2.0",

Expected behavior

The auth entry should get signed

Additional context

My code

import { SorobanRpc, Networks, Keypair, xdr, hash, Address, Operation, Transaction, authorizeEntry } from '@stellar/stellar-sdk'
import { basicNodeSigner, DEFAULT_TIMEOUT } from '@stellar/stellar-sdk/contract';
import { Client, networks } from 'puzzle-sdk'

const keypair = Keypair.fromSecret('<SK>');
const publicKey = keypair.publicKey()

const puzzleSAC = 'CDGOXJBEKI3MQDB3J477NN3HAQBDCNK5YYB2ZKAG24US53RXW44QIF6Z'
const puzzleId = 'CCPYY3EQZQ6SQE2XRHCU5VVH4DCR3ZCNRHIS5ITCSMBK2WOPMN56LEAV'
const solverId = 'CD3QSVJ2FLC4XMRHPVS3NM2TFFKXNTGINP3A55W5P5FKZR5YHS6PABT2'

const rpcUrl = 'https://soroban-testnet.stellar.org'
const rpc = new SorobanRpc.Server(rpcUrl)

const networkPassphrase = Networks.TESTNET

const contract = new Client({
    ...networks.testnet,
    ...basicNodeSigner(keypair, networkPassphrase),
    networkPassphrase,
    contractId: solverId,
    publicKey,
    rpcUrl,
})

const { built, simulationData } = await contract.call({
    puzzle: puzzleId,
    sac: puzzleSAC
})

const lastLedger = await rpc.getLatestLedger().then(({ sequence }) => sequence);

const entry = await authorizeEntry( // <- breaks here
    simulationData.result.auth[0],
    keypair,
    lastLedger + DEFAULT_TIMEOUT, 
    networkPassphrase
)

const op = built?.operations[0] as Operation.InvokeHostFunction

op.auth?.splice(0, 1, entry)

console.log('\n', built?.toXDR(), '\n');

const sim = await rpc.simulateTransaction(built!)

if (SorobanRpc.Api.isSimulationError(sim)) 
    throw sim.error

if (SorobanRpc.Api.isSimulationRestore(sim))
    throw 'Restore required'

const txn = SorobanRpc.assembleTransaction(new Transaction(built!.toXDR(), networkPassphrase), sim).build()

txn.sign(keypair)

console.log('\n', txn.toXDR(), '\n');

const res = await rpc.sendTransaction(txn)

console.log(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo (Ready for Dev)
Status: To Do
Development

No branches or pull requests

3 participants