Skip to content

Commit

Permalink
fix: blobert image url in getProfileData returns an error (#34)
Browse files Browse the repository at this point in the history
* fix: profilePicture url for blobert

* test: profile_mainnet tests

* fix: use sepolia instead of goerli in tests

* fix: add parseBase64Image function
  • Loading branch information
irisdv authored Apr 10, 2024
1 parent b739d9e commit 55e340d
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starknetid.js",
"version": "3.0.4",
"version": "3.0.5",
"description": "JavaScript library for Starknet ID",
"private": false,
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/__test__/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe("test starknetid.js sdk", () => {
shortString.encodeShortString("NFT"),
shortString.encodeShortString("NFT"),
[
shortString.encodeShortString("https://goerli.api.starknet.qu"),
shortString.encodeShortString("https://sepolia.api.starknet.qu"),
shortString.encodeShortString("est/quests/uri?level="),
],
],
Expand Down Expand Up @@ -285,7 +285,7 @@ describe("test starknetid.js sdk", () => {
discord: "123",
proofOfPersonhood: false,
profilePicture:
"https://goerli.starknet.quest/starkfighter/level1.webp",
"https://sepolia.starknet.quest/starkfighter/level1.webp",
};
expect(profile).toStrictEqual(expectedProfile);
});
Expand Down
78 changes: 78 additions & 0 deletions packages/core/__test__/profile_mainnet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { constants, Provider } from "starknet";
import { StarknetIdNavigator } from "../src";

describe("test starknetid.js sdk on mainnet", () => {
jest.setTimeout(90000000);
const provider = new Provider({
rpc: {
nodeUrl: "https://rpc.starknet.lava.build",
},
});

describe("getProfileData for a profile with a blobert pfp", () => {
test("getProfileData should return an undefined profile picture url", async () => {
const starknetIdNavigator = new StarknetIdNavigator(
provider,
constants.StarknetChainId.SN_MAIN,
);
expect(starknetIdNavigator).toBeInstanceOf(StarknetIdNavigator);
const profile = await starknetIdNavigator.getProfileData(
"0x06fb5e4e650bb6ceb80923c008e81122129092efc7e6d6f3f5c9ac4eead25355",
false,
);
const expectedProfile = {
name: "rmz.stark",
twitter: "302521256",
github: undefined,
discord: undefined,
proofOfPersonhood: false,
profilePicture:
"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaW5ZTWluIG1lZXQiIHN0eWxlPSJpbWFnZS1yZW5kZXJpbmc6IHBpeGVsYXRlZCIgdmlld0JveD0iMCAwIDM1MCAzNTAiPjxpbWFnZSBocmVmPSJkYXRhOmltYWdlL3BuZztiYXNlNjQsaVZCT1J3MEtHZ29BQUFBTlNVaEVVZ0FBQURBQUFBQXdCQU1BQUFDbExPUzBBQUFBTFZCTVZFWFU0cmpRbWZmcVl2K0p4L3Vqbi83eGUvVDdqZUNiL01DNDg3SDZwZEx4eE1MUnlNeU02ZUd0LzZ1cGEra0gzelJpQUFBREtFbEVRVlE0eTAzUnNZdlRZQmdHOE5kRjJtYng2N1dpZHZMejdDaG9BZzZHdzE3aVpCRmFta0tkN0VFQ3VVbFJ5SEFWTW41VWhDQTBrTGpFNWJqRzVUcmMwU05qQ3pjWTV5NW1PZThQOGZsU1JETzBoQjk5bi9kNVM2eS8yL1dPc2k4Y3p4c0tEM1pWWFZVNzkxSmFzRWVHZDZTYzhmdWNqK2o0Z0t1cWhJUytzL3IxMDdjQVZ1ZHRxanJjK0FzTDF0RGZLdWVjc1hvN0lJYy9BSmdzcFRSanJIdTBCUjdJRUlBbVFWbXduUitVV1Qxem54L1NUWVJzSWFhTU5aNlZZQ0s5aGhCQUp5YVhGTWFlblNxMmhIWkNZZis2VEtkaFFJeTlQRldhRWg0R05MZDNqUklleG5TRE5US2FXUUNFVk8xSEFQTXVYYmtTWHBaUTV5NWgxbStFM0tZbm80Ull3NlF6cTJIc2M3d2N5NFcxRjdTSFZvQlRDVTg0WHFvMk4wcmdNYUg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RkZiRHJDSFpVd0tGRkJKY0VGWFVJRGtZSkpWd1NETGdrbUFWeHhJY3lEZ2xXTTBFQjdOR1I2SUxWRWxVemtRNUhJYXdhZ0JJZ0xaZ1NKUjN1V0NYU0JWMEVDMG1TU0JRRUFxd1NMdVV1Z3FUb0FQckRCZVlQVEMwS1dLTURDQmdHR0FBQThmd1d4NjB2SXpRQUFBQUFTVVZPUks1Q1lJST0iIHg9IjAiIHk9IjAiIHdpZHRoPSIzNTBweCIgaGVpZ2h0PSIzNTBweCIgLz48L3N2Zz4=",
};
expect(profile).toStrictEqual(expectedProfile);
});

test("getProfileData with a starkurabu pfp", async () => {
const starknetIdNavigator = new StarknetIdNavigator(
provider,
constants.StarknetChainId.SN_MAIN,
);
expect(starknetIdNavigator).toBeInstanceOf(StarknetIdNavigator);
const profile = await starknetIdNavigator.getProfileData(
"0x061b6c0a78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3",
false,
);
const expectedProfile = {
name: "fricoben.stark",
twitter: "1255853529866145794",
github: "78437165",
discord: "662387807901188096",
proofOfPersonhood: true,
profilePicture:
"https://img.starkurabu.com/41538374869489910341448844649168906.png",
};
expect(profile).toStrictEqual(expectedProfile);
});

test("getProfileData with a duck pfp", async () => {
const starknetIdNavigator = new StarknetIdNavigator(
provider,
constants.StarknetChainId.SN_MAIN,
);
expect(starknetIdNavigator).toBeInstanceOf(StarknetIdNavigator);
const profile = await starknetIdNavigator.getProfileData(
"0x029b96adaefdb4299be95cdee599bff6bcca26c4e85a4d8ace79231f4618017f",
);
const expectedProfile = {
name: "iris.stark",
twitter: undefined,
github: undefined,
discord: undefined,
proofOfPersonhood: false,
profilePicture:
"https://api.briq.construction/v1/preview/starknet-mainnet-dojo/0x6cff01dd5d1e2ec5e792d66bd6edae386bd022b4ffd993c76c08cd000000003.png",
};
expect(profile).toStrictEqual(expectedProfile);
});
});
});
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starknetid.js",
"version": "3.0.4",
"version": "3.0.5",
"keywords": [
"starknet",
"starknetid",
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/starknetIdNavigator/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ export class StarknetIdNavigator implements StarknetIdNavigatorInterface {

// extract nft_image from profile data
const profilePicture = profilePictureMetadata
? await this.fetchImageUrl(profilePictureMetadata)
? profilePictureMetadata.includes("base64")
? this.parseBase64Image(profilePictureMetadata)
: await this.fetchImageUrl(profilePictureMetadata)
: useDefaultPfp
? `https://starknet.id/api/identicons/${data[1][0].toString()}`
: undefined;
Expand Down Expand Up @@ -681,4 +683,8 @@ export class StarknetIdNavigator implements StarknetIdNavigatorInterface {
return "Error fetching data";
}
}

private parseBase64Image(metadata: string): string {
return JSON.parse(atob(metadata.split(",")[1].slice(0, -1))).image;
}
}

0 comments on commit 55e340d

Please sign in to comment.