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

"The publicKey was not registered" after calling object.uploadObject #564

Open
lokendrasoni opened this issue Sep 7, 2024 · 3 comments
Open

Comments

@lokendrasoni
Copy link

SDK version: 2.1.1

Environment:

  • OS (e.g. from /etc/os-release): Windows
  • Install tools: yarn
  • Others:

What happened:
Tried uploading a file using object.uploadObject method but the method failed with this error:

{
    "code": "20019",
    "message": "The publicKey was not registered",
    "statusCode": 400
}

I am not sure if that is the wallet's public key or the public key generated by genOffChainAuthKeyPairAndUpload method. If that's the wallet's public key, it is registered and if it isn't then I am not sure as the method's key is generated randomly as per the code.

What you expected to happen:
I expected it to upload the file and return the id

Have you tried the latest version: yes

How to reproduce it (as minimally and precisely as possible):
I called the uploadObject method after createObject method.

createObject code:

const tx = await client.object.createObject({
    bucketName: "spark",
    objectName: name,
    creator: address
    visibility: VisibilityType.VISIBILITY_TYPE_PRIVATE,
    contentType: file.type,
    redundancyType: RedundancyType.REDUNDANCY_EC_TYPE,
    payloadSize: Long.fromInt(file.size),
    expectChecksums: expectCheckSums.map(x => bytesFromBase64(x)),
});
const simulateInfo = await tx.simulate({
    denom: "BNB",
});
const broadcastRes = await tx.broadcast({
    denom: "BNB",
    gasLimit: Number(simulateInfo.gasLimit),
    gasPrice: simulateInfo.gasPrice,
    payer: address,
    granter: "",
});

uploadObject code:

const offChainData = await getOffchainAuthKeys();

const uploadRes = await client.object.uploadObject(
    {
        bucketName: "spark",
        objectName: name,
        body: file,
        txnHash: broadcastRes.transactionHash,
    },
    {
        type: "EDDSA",
        domain: window.location.origin,
        seed: offChainData.seedString,
        address: address
    },
);
console.log({ uploadRes });

getOffchainAuthKeys method:

const getOffchainAuthKeys = async () => {
    const storageResStr = localStorage.getItem(address);

    if (storageResStr) {
        const storageRes = JSON.parse(storageResStr);
        if (storageRes.expirationTime < Date.now()) {
            alert("Your auth key has expired, please generate a new one");
            localStorage.removeItem(address);
            return;
        }

        return storageRes;
    }

    const allSps = await getAllSps();
    const offchainAuthRes = await client.offchainauth.genOffChainAuthKeyPairAndUpload(
        {
            sps: allSps,
            chainId: 5600,
            expirationMs: 5 * 24 * 60 * 60 * 1000,
            domain: window.location.origin,
            address,
        },
        provider,
    );

    const { code, body: offChainData } = offchainAuthRes;
    if (code !== 0 || !offChainData) {
        throw offchainAuthRes;
    }

    localStorage.setItem(address, JSON.stringify(offChainData));
    return offChainData;
};

Logs (paste a small part showing an error (< 10 lines) or link a pastebin, gist, etc. containing more of the log file):

{
    "code": "20019",
    "message": "The publicKey was not registered",
    "statusCode": 400
}

Config (you can paste only the changes you've made):

node command runtime flags:

Anything else we need to know:

@lokendrasoni lokendrasoni changed the title "The publicKey was not registered" which calling object.uploadObject "The publicKey was not registered" after calling object.uploadObject Sep 7, 2024
@STdevK
Copy link

STdevK commented Sep 19, 2024

let me test it out

@lokendrasoni
Copy link
Author

Any updates? @STdevK

@rrr523
Copy link
Collaborator

rrr523 commented Oct 10, 2024

@lokendrasoni

Hi, your getOffchainAuthKeys code looks right.

Which step did the error occur? createObject or uploadObject?

And now the SDK already supports delegateUploadObject (You don't have to createObject and then uploadObject, just one step). demo code

If it still doesn’t work, you can view a complete online example at playground

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

4 participants
@rrr523 @lokendrasoni @STdevK and others