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

Is it a BUG? when #228

Open
xgocn opened this issue May 3, 2024 · 3 comments
Open

Is it a BUG? when #228

xgocn opened this issue May 3, 2024 · 3 comments

Comments

@xgocn
Copy link

xgocn commented May 3, 2024

when I run this method:

async function connectArConnect(arweave) {
    try {
        const fileInput = document.getElementById('walletFileInput');
        const walletFile = fileInput.files[0];
        const walletJson = await readFileAsText(walletFile);
        const wallet = JSON.parse(walletJson);
        console.log('Wallet JSON:', walletJson);
        console.log('Wallet:', wallet);
        const arweaveWallet = await arweave.wallets.jwkToAddress(wallet);
        const address = await arweave.wallets.getAddress(arweaveWallet);
        console.log('Connected to wallet:', address);
    } catch (error) {
        console.error('Error connecting to wallet:', error);
        alert('Error connecting to wallet. Check console for more details.');
    }
}

and I got correct response through console.log('Wallet:', wallet);

but const address = await arweave.wallets.getAddress(arweaveWallet);
gave out an error like

    b64UrlDecode utils.js:58
    b64UrlToBuffer utils.js:39
    ownerToAddress wallets.js:64
    getAddress wallets.js:60

I met the error several times before in other project , so I doubt if it's a BUG or not, hope your help.

It's important to note that this issue does not occur in normal mode; it only occurs in ANS-104 mode.

@xgocn
Copy link
Author

xgocn commented May 3, 2024

the utils.js:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.b64UrlDecode = exports.b64UrlEncode = exports.bufferTob64Url = exports.bufferTob64 = exports.b64UrlToBuffer = exports.stringToB64Url = exports.stringToBuffer = exports.bufferToString = exports.b64UrlToString = exports.concatBuffers = void 0;
const B64js = require("base64-js");
function concatBuffers(buffers) {
    let total_length = 0;
    for (let i = 0; i < buffers.length; i++) {
        total_length += buffers[i].byteLength;
    }
    let temp = new Uint8Array(total_length);
    let offset = 0;
    temp.set(new Uint8Array(buffers[0]), offset);
    offset += buffers[0].byteLength;
    for (let i = 1; i < buffers.length; i++) {
        temp.set(new Uint8Array(buffers[i]), offset);
        offset += buffers[i].byteLength;
    }
    return temp;
}
exports.concatBuffers = concatBuffers;
function b64UrlToString(b64UrlString) {
    let buffer = b64UrlToBuffer(b64UrlString);
    return bufferToString(buffer);
}
exports.b64UrlToString = b64UrlToString;
function bufferToString(buffer) {
    return new TextDecoder("utf-8", { fatal: true }).decode(buffer);
}
exports.bufferToString = bufferToString;
function stringToBuffer(string) {
    return new TextEncoder().encode(string);
}
exports.stringToBuffer = stringToBuffer;
function stringToB64Url(string) {
    return bufferTob64Url(stringToBuffer(string));
}
exports.stringToB64Url = stringToB64Url;
function b64UrlToBuffer(b64UrlString) {
    return new Uint8Array(B64js.toByteArray(b64UrlDecode(b64UrlString)));
}
exports.b64UrlToBuffer = b64UrlToBuffer;
function bufferTob64(buffer) {
    return B64js.fromByteArray(new Uint8Array(buffer));
}
exports.bufferTob64 = bufferTob64;
function bufferTob64Url(buffer) {
    return b64UrlEncode(bufferTob64(buffer));
}
exports.bufferTob64Url = bufferTob64Url;
function b64UrlEncode(b64UrlString) {
    return b64UrlString
        .replace(/\+/g, "-")
        .replace(/\//g, "_")
        .replace(/\=/g, "");
}
exports.b64UrlEncode = b64UrlEncode;
function b64UrlDecode(b64UrlString) {
    b64UrlString = b64UrlString.replace(/\-/g, "+").replace(/\_/g, "/");
    let padding;
    b64UrlString.length % 4 == 0
        ? (padding = 0)
        : (padding = 4 - (b64UrlString.length % 4));
    return b64UrlString.concat("=".repeat(padding));
}
exports.b64UrlDecode = b64UrlDecode;

@rosmcmahon
Copy link
Member

rosmcmahon commented May 4, 2024

you are correct, it's not a bug, just a confusing error message.

in case you didn't figure it out, it's these lines here:

 const arweaveWallet = await arweave.wallets.jwkToAddress(wallet); //this gives the address
 const address = await arweave.wallets.getAddress(arweaveWallet); //error: attempts to get address from address

should be:

const address = arweave.wallets.jwkToAddress(wallet);

@rosmcmahon
Copy link
Member

i've merged the PR you referenced, but that will just give a new message about something not being a string. not too helpful an error message either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants