Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cartridge/controller

Package Overview
Dependencies
Maintainers
2
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cartridge/controller - npm Package Compare versions

Comparing version 0.3.25 to 0.3.26

8

dist/device.d.ts

@@ -1,2 +0,2 @@

import { Account, Abi, Call, EstimateFeeDetails, Signature, InvokeFunctionResponse, EstimateFee, DeclareContractPayload, RpcProvider, TypedData, InvocationsDetails, constants } from "starknet";
import { Account, Abi, Call, EstimateFeeDetails, Signature, InvokeFunctionResponse, EstimateFee, DeclareContractPayload, TypedData, InvocationsDetails } from "starknet";
import { Keychain, Modal } from "./types";

@@ -8,3 +8,3 @@ import { AsyncMethodReturns } from "@cartridge/penpal";

private modal;
constructor(provider: RpcProvider, address: string, keychain: AsyncMethodReturns<Keychain>, modal: Modal);
constructor(rpcUrl: string, address: string, keychain: AsyncMethodReturns<Keychain>, modal: Modal);
/**

@@ -35,5 +35,3 @@ * Estimate Fee for a method on starknet

*/
execute(calls: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails & {
chainId?: constants.StarknetChainId;
}): Promise<InvokeFunctionResponse>;
execute(calls: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
/**

@@ -40,0 +38,0 @@ * Sign an JSON object for off-chain usage with the starknet private key and return the signature

@@ -1,7 +0,7 @@

import { Account, } from "starknet";
import { Account, RpcProvider, } from "starknet";
import { ResponseCodes } from "./types";
import { Signer } from "./signer";
class DeviceAccount extends Account {
constructor(provider, address, keychain, modal) {
super(provider, address, new Signer(keychain, modal));
constructor(rpcUrl, address, keychain, modal) {
super(new RpcProvider({ nodeUrl: rpcUrl }), address, new Signer(keychain, modal));
this.address = address;

@@ -25,3 +25,2 @@ this.keychain = keychain;

...details,
chainId: await this.getChainId(),
});

@@ -32,3 +31,2 @@ }

...details,
chainId: await this.getChainId(),
});

@@ -35,0 +33,0 @@ }

@@ -1,22 +0,16 @@

/// <reference types="node" />
export * from "./types";
export { defaultPresets } from "./presets";
import { AccountInterface, constants, RpcProvider } from "starknet";
import { AccountInterface } from "starknet";
import { AsyncMethodReturns } from "@cartridge/penpal";
import { Session, Keychain, Policy, ControllerOptions } from "./types";
export declare const providers: {
[key: string]: RpcProvider;
};
import { Keychain, Policy, ControllerOptions } from "./types";
declare class Controller {
private url;
private policies;
private connection?;
private modal?;
keychain?: AsyncMethodReturns<Keychain>;
private policies;
private url;
chainId: constants.StarknetChainId;
accounts?: {
[key: string]: AccountInterface;
};
private modal?;
rpc: URL;
chainId: string;
account?: AccountInterface;
constructor(policies?: Policy[], options?: ControllerOptions);
get account(): AccountInterface | undefined;
private setTheme;

@@ -26,17 +20,5 @@ private setColorMode;

probe(): Promise<true | null | undefined>;
switchChain(chainId: constants.StarknetChainId): Promise<void>;
login(address: string, credentialId: string, options: {
rpId?: string;
challengeExt?: Buffer;
}): Promise<{
assertion: import("./types").Assertion;
} | null>;
issueStarterPack(id: string): Promise<{
transaction_hash: string;
}>;
showQuests(gameId: string): Promise<void>;
connect(): Promise<AccountInterface | undefined>;
disconnect(): Promise<void>;
revoke(origin: string, _policy: Policy[]): Promise<void> | null;
approvals(origin: string): Promise<Session | undefined>;
username(): Promise<string> | undefined;

@@ -47,3 +29,2 @@ }

export { computeAddress, split, verifyMessageHash } from "./utils";
export { injectController } from "./inject";
export default Controller;
export * from "./types";
export { defaultPresets } from "./presets";
import { addAddressPadding, constants, RpcProvider, } from "starknet";
import { addAddressPadding, constants } from "starknet";
import { connectToChild, } from "@cartridge/penpal";

@@ -10,17 +10,8 @@ import DeviceAccount from "./device";

import { NotReadyToConnect } from "./errors";
// @dev override url to local sequencer for local dev
// http://localhost:8000/x/starknet/mainnet
export const providers = {
[constants.StarknetChainId.SN_MAIN]: new RpcProvider({
nodeUrl: "https://api.cartridge.gg/x/starknet/mainnet",
}),
[constants.StarknetChainId.SN_SEPOLIA]: new RpcProvider({
nodeUrl: "https://api.cartridge.gg/x/starknet/sepolia",
}),
};
class Controller {
// private starterPackId?: string;
constructor(policies, options) {
this.url = new URL("https://x.cartridge.gg");
this.policies = [];
this.url = "https://x.cartridge.gg";
this.rpc = new URL("https://api.cartridge.gg/x/starknet/sepolia");
this.chainId = constants.StarknetChainId.SN_SEPOLIA;

@@ -35,8 +26,8 @@ if (policies) {

}
if (options?.chainId) {
this.chainId = options.chainId;
}
if (options?.url) {
this.url = options.url;
this.url = new URL(options.url);
}
if (options?.rpc) {
this.rpc = new URL(options.rpc);
}
this.setTheme(options?.theme, options?.config?.presets);

@@ -49,3 +40,3 @@ if (options?.colorMode) {

}
this.modal = createModal(this.url, () => {
this.modal = createModal(this.url.toString(), () => {
this.keychain?.reset();

@@ -64,2 +55,7 @@ });

iframe: this.modal.element.children[0],
methods: {
close: () => {
this.modal?.close();
},
},
});

@@ -70,18 +66,8 @@ this.connection.promise

}
get account() {
if (!this.accounts) {
return;
}
return this.accounts[this.chainId];
}
setTheme(id = "cartridge", presets = defaultPresets) {
const theme = presets[id] ?? defaultPresets.cartridge;
const url = new URL(this.url);
url.searchParams.set("theme", encodeURIComponent(JSON.stringify(theme)));
this.url = url.toString();
this.url.searchParams.set("theme", encodeURIComponent(JSON.stringify(theme)));
}
setColorMode(colorMode) {
const url = new URL(this.url);
url.searchParams.set("colorMode", colorMode);
this.url = url.toString();
this.url.searchParams.set("colorMode", colorMode);
}

@@ -104,6 +90,3 @@ ready() {

const { address } = res;
this.accounts = {
[constants.StarknetChainId.SN_MAIN]: new DeviceAccount(providers[constants.StarknetChainId.SN_MAIN], address, this.keychain, this.modal), // Note: workaround for execute type mismatch error
[constants.StarknetChainId.SN_SEPOLIA]: new DeviceAccount(providers[constants.StarknetChainId.SN_SEPOLIA], address, this.keychain, this.modal),
};
this.account = new DeviceAccount(this.rpc.toString(), address, this.keychain, this.modal);
}

@@ -114,60 +97,7 @@ catch (e) {

}
return !!this.accounts?.[this.chainId];
return !!this.account;
}
async switchChain(chainId) {
if (this.chainId === chainId) {
return;
}
this.chainId = chainId;
}
async login(address, credentialId, options) {
if (!this.keychain) {
console.error(new NotReadyToConnect().message);
return null;
}
return this.keychain.login(address, credentialId, options);
}
async issueStarterPack(id) {
if (!this.keychain || !this.modal) {
const err = new NotReadyToConnect();
console.error(err.message);
return Promise.reject(err.message);
}
this.modal.open();
try {
if (!this.account) {
let response = await this.keychain.connect(this.policies, undefined, this.chainId);
if (response.code !== ResponseCodes.SUCCESS) {
throw new Error(response.message);
}
}
return await this.keychain.issueStarterPack(id);
}
catch (e) {
console.log(e);
return Promise.reject(e);
}
finally {
this.modal.close();
}
}
async showQuests(gameId) {
if (!this.keychain || !this.modal) {
console.error(new NotReadyToConnect().message);
return;
}
this.modal.open();
try {
return await this.keychain.showQuests(gameId);
}
catch (e) {
console.error(e);
}
finally {
this.modal.close();
}
}
async connect() {
if (this.accounts) {
return this.accounts[this.chainId];
if (this.account) {
return this.account;
}

@@ -186,3 +116,3 @@ if (!this.keychain || !this.modal) {

try {
let response = await this.keychain.connect(this.policies, undefined, this.chainId);
let response = await this.keychain.connect(this.policies, this.rpc.toString());
if (response.code !== ResponseCodes.SUCCESS) {

@@ -192,7 +122,4 @@ throw new Error(response.message);

response = response;
this.accounts = {
[constants.StarknetChainId.SN_MAIN]: new DeviceAccount(providers[constants.StarknetChainId.SN_MAIN], response.address, this.keychain, this.modal),
[constants.StarknetChainId.SN_SEPOLIA]: new DeviceAccount(providers[constants.StarknetChainId.SN_SEPOLIA], response.address, this.keychain, this.modal),
};
return this.accounts[this.chainId];
this.account = new DeviceAccount(this.rpc.toString(), response.address, this.keychain, this.modal);
return this.account;
}

@@ -217,3 +144,3 @@ catch (e) {

}
this.accounts = undefined;
this.account = undefined;
return this.keychain.disconnect();

@@ -228,9 +155,2 @@ }

}
async approvals(origin) {
if (!this.keychain) {
console.error(new NotReadyToConnect().message);
return;
}
return this.keychain.approvals(origin);
}
username() {

@@ -247,4 +167,3 @@ if (!this.keychain) {

export { computeAddress, split, verifyMessageHash } from "./utils";
export { injectController } from "./inject";
export default Controller;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import { constants } from "starknet";
import { RpcProvider } from "starknet";
import { AccountInterface, ProviderInterface } from "starknet";

@@ -57,3 +57,3 @@ import { Policy } from "./types";

icon: string;
provider: import("starknet").Provider;
provider: RpcProvider;
isConnected: boolean;

@@ -66,5 +66,5 @@ account?: AccountInterface | undefined;

url?: string;
rpc?: string;
origin?: string;
starterPackId?: string;
chainId?: constants.StarknetChainId;
});

@@ -79,6 +79,6 @@ request: (_call: Omit<RpcMessage, "result">) => Promise<RpcMessage["result"]>;

url?: string;
rpc?: string;
origin?: string;
starterPackId?: string;
chainId?: constants.StarknetChainId;
}): void;
export { injectController };

@@ -1,3 +0,3 @@

import { constants } from "starknet";
import Controller, { providers } from ".";
import { RpcProvider } from "starknet";
import Controller from ".";
export class InjectedController {

@@ -9,3 +9,3 @@ constructor(policies, options) {

this.icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjkiIGhlaWdodD0iNTciIHZpZXdCb3g9IjAgMCA2OSA1NyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0yMy41NTEzIDAuMDM5MDYyNUg0NC42Mjc4TDQ0LjcwMTIgMC4wNDE3NTc4QzQ2LjI2MjQgMC4wOTkwOTkyIDQ3Ljc5NDggMC40NzQ3OTUgNDkuMjA0OSAxLjE0NTA5TDYzLjUyMjcgNy4xODc5NUw2My42NTIyIDcuMjU0MDRDNjUuMDExOCA3Ljk0ODEyIDY2LjE0NzggOS4wMTA3NyA2Ni45MzE2IDEwLjMxOTNDNjcuNzA4MSAxMS42MTU3IDY4LjEwODUgMTMuMTAyMSA2OC4wODg5IDE0LjYxMj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5NSA0MC4xOTAxIDU3LjMyODMgNDAuMTkwMUg0Ni4zNDM2TDQ2LjMzNzcgNDYuMjA2OUw1Ni41NzcxIDQ2LjIxNDdDNTcuNTE1NiA0Ni4yMTQ3IDU4LjA3OTUgNDYuMjE0NyA1OC44MzA3IDQ1LjQ2MTZMNjMuMzM3NyA0MC45NDMyQzY0LjA4ODkgNDAuMTkwMSA2NC4wODg5IDM5LjQzNzEgNjQuMDg4OSAzOC42ODRWMTQuNTgyQzY0LjEwMyAxMy44MDU1IDYzLjg5OSAxMy4wNDA2IDYzLjUwMDEgMTIuMzc0OEM2My4xMDEzIDExLjcwOSA2Mi41MjM4IDExLjE2OTEgNjEuODMzNCAxMC44MTY3WiIgZmlsbD0iI0ZCQ0I0QSIvPgo8L3N2Zz4K";
this.provider = providers[constants.StarknetChainId.SN_MAIN];
this.provider = new RpcProvider({ nodeUrl: "https://api.cartridge.gg/x/starknet/sepolia" });
this.isConnected = false;

@@ -21,3 +21,3 @@ this.subscriptions = [];

}
this.provider = providers[this.controller.chainId];
this.provider = new RpcProvider({ nodeUrl: this.controller.rpc.toString() });
this.isConnected = true;

@@ -65,3 +65,3 @@ return [this.account.address];

this.account = this.controller.account;
this.provider = providers[this.controller.chainId];
this.provider = new RpcProvider({ nodeUrl: this.controller.rpc.toString() });
this.selectedAddress = this.account.address;

@@ -68,0 +68,0 @@ }

@@ -1,2 +0,1 @@

/// <reference types="node" />
import { constants, Abi, Call, InvocationsDetails, TypedData, InvokeFunctionResponse, Signature, EstimateFeeDetails, EstimateFee, DeclareContractPayload, BigNumberish, InvocationsSignerDetails, DeployAccountSignerDetails, DeclareSignerDetails } from "starknet";

@@ -27,2 +26,3 @@ export type Assertion = {

method?: string;
description?: string;
};

@@ -35,3 +35,3 @@ export declare enum ResponseCodes {

}
export type Error = {
export type ConnectError = {
code: ResponseCodes;

@@ -54,23 +54,10 @@ message: string;

export interface Keychain {
probe(): Promise<ProbeReply | Error>;
connect(policies: Policy[], starterPackId?: string, chainId?: constants.StarknetChainId): Promise<ConnectReply | Error>;
probe(): Promise<ProbeReply | ConnectError>;
connect(policies: Policy[], rpcUrl: string): Promise<ConnectReply | ConnectError>;
disconnect(): void;
reset(): void;
revoke(origin: string): void;
approvals(origin: string): Promise<Session | undefined>;
estimateDeclareFee(payload: DeclareContractPayload, details?: EstimateFeeDetails & {
chainId: constants.StarknetChainId;
}): Promise<EstimateFee>;
estimateInvokeFee(calls: Call | Call[], estimateFeeDetails?: EstimateFeeDetails & {
chainId: constants.StarknetChainId;
}): Promise<EstimateFee>;
execute(calls: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails & {
chainId?: constants.StarknetChainId;
}, sync?: boolean): Promise<ExecuteReply | Error>;
login(address: string, credentialId: string, options: {
rpId?: string;
challengeExt?: Buffer;
}): Promise<{
assertion: Assertion;
}>;
estimateDeclareFee(payload: DeclareContractPayload, details?: EstimateFeeDetails): Promise<EstimateFee>;
estimateInvokeFee(calls: Call | Call[], estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFee>;
execute(calls: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails, sync?: boolean): Promise<ExecuteReply | ConnectError>;
logout(): Promise<void>;

@@ -81,8 +68,6 @@ session(): Promise<Session>;

}>;
signMessage(typedData: TypedData, account: string): Promise<Signature | Error>;
signMessage(typedData: TypedData, account: string): Promise<Signature | ConnectError>;
signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
signDeployAccountTransaction(transaction: DeployAccountSignerDetails): Promise<Signature>;
signDeclareTransaction(transaction: DeclareSignerDetails): Promise<Signature>;
issueStarterPack(id: string): Promise<InvokeFunctionResponse>;
showQuests(gameId: string): Promise<void>;
username(): string;

@@ -99,3 +84,3 @@ }

starterPackId?: string;
chainId?: constants.StarknetChainId;
rpc?: string;
theme?: string;

@@ -102,0 +87,0 @@ colorMode?: ColorMode;

{
"name": "@cartridge/controller",
"version": "0.3.25",
"version": "0.3.26",
"description": "Cartridge Controller",

@@ -22,3 +22,3 @@ "module": "dist/index.js",

"typescript": "^5.4.5",
"@cartridge/tsconfig": "^0.3.25"
"@cartridge/tsconfig": "^0.3.26"
},

@@ -25,0 +25,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc