@citizenwallet/sdk
Version:
An sdk to easily work with citizen wallet.
68 lines • 3.17 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ethers_1 = require("ethers");
const config_1 = require("../config");
const index_1 = require("./index");
const path_1 = __importDefault(require("path"));
const fs_1 = require("fs");
// Create a minimal mock of CommunityConfig for testing
class MockCommunityConfig {
constructor() {
this.primaryRPCUrl = "https://mock-rpc.xyz";
this.primaryToken = {
address: "0x1234567890123456789012345678901234567890",
symbol: "MOCK",
decimals: 18,
standard: "ERC20",
name: "Mock Token",
chain_id: 1,
};
this.primaryAccountConfig = {
account_factory_address: "0x1234567890123456789012345678901234567890",
chain_id: 1,
entrypoint_address: "0x1234567890123456789012345678901234567890",
paymaster_address: "0x1234567890123456789012345678901234567890",
paymaster_type: "none",
};
}
}
describe("Connection flow", () => {
const baseUrl = "https://citizenwallet.xyz";
const config = (0, fs_1.readFileSync)(path_1.default.join(__dirname, "../../community.json"), "utf8");
const mockConfig = new config_1.CommunityConfig(JSON.parse(config));
it("should successfully connect with a valid signer", async () => {
// Create a random wallet
const wallet = ethers_1.Wallet.createRandom();
const accountAddress = wallet.address;
// Set expiry to 1 hour from now
const expiryTimeStamp = (Math.floor(Date.now() / 1000) + 3600).toString();
const redirectUrl = "https://app.example.com";
// Create connected URL
const connectedUrl = await (0, index_1.createConnectedUrl)(baseUrl, wallet, accountAddress, expiryTimeStamp, redirectUrl);
// Verify the connected URL
const verifiedAccount = await (0, index_1.verifyConnectedUrl)(mockConfig, {
url: connectedUrl,
});
expect(verifiedAccount).toBe(accountAddress);
});
it("should fail to connect with an invalid signature", async () => {
// Create two random wallets - one for signing, one for the account address
const signerWallet = ethers_1.Wallet.createRandom();
const accountWallet = ethers_1.Wallet.createRandom();
const expiryTimeStamp = (Math.floor(Date.now() / 1000) + 3600).toString();
const redirectUrl = "https://app.example.com";
// Create connected URL with mismatched signer and account
const connectedUrl = await (0, index_1.createConnectedUrl)(baseUrl, signerWallet, // Sign with different wallet
accountWallet.address, // But use different account address
expiryTimeStamp, redirectUrl);
// Verify should fail
const verifiedAccount = await (0, index_1.verifyConnectedUrl)(mockConfig, {
url: connectedUrl,
});
expect(verifiedAccount).toBeNull();
});
});
//# sourceMappingURL=index.test.js.map