{"id":19423199,"url":"https://github.com/make-software/casper-wallet-sdk","last_synced_at":"2025-08-24T11:17:10.721Z","repository":{"id":66061422,"uuid":"599655893","full_name":"make-software/casper-wallet-sdk","owner":"make-software","description":"SDK to simplify integration of Casper Wallet with your amazing web app!","archived":false,"fork":false,"pushed_at":"2024-05-16T14:53:32.000Z","size":44,"stargazers_count":7,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-25T04:32:24.604Z","etag":null,"topics":["blockchain","casper-network","crypto-wallet","hacktoberfest","sdk"],"latest_commit_sha":null,"homepage":"https://casperwallet.io","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/make-software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-09T15:50:56.000Z","updated_at":"2024-08-03T01:08:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"967dc045-eb0f-4594-ac64-84afbc6d2329","html_url":"https://github.com/make-software/casper-wallet-sdk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/make-software/casper-wallet-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/make-software%2Fcasper-wallet-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/make-software%2Fcasper-wallet-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/make-software%2Fcasper-wallet-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/make-software%2Fcasper-wallet-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/make-software","download_url":"https://codeload.github.com/make-software/casper-wallet-sdk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/make-software%2Fcasper-wallet-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271852035,"owners_count":24834079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","casper-network","crypto-wallet","hacktoberfest","sdk"],"created_at":"2024-11-10T13:37:11.223Z","updated_at":"2025-08-24T11:17:10.710Z","avatar_url":"https://github.com/make-software.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Casper Wallet SDK\n\nSDK to simplify integration of [Casper Wallet](https://github.com/make-software/casper-wallet) with your amazing web app!\n\n**Please note that the recommended way of integrating Casper Wallet into your app is now through [CSPR.click](https://CSPR.click), which provides a combined integration of major wallets in the Casper ecosystem, all at once, without the burden of maintaining multiple integrations at the same time. Please head over to [the CSPR.click documentation](https://docs.cspr.click) to start.**\n\n## Installation\n\n\u003e In the near future we're planning to publish an SDK library as a npm package, so you can use it as a dependency in your JS/TS project, offering all the supplementary TypeScript types and other helpful utilities to further streamline maintenance of the wallet integration when we add new features.\n\nFor now, the SDK is injected into the global scope of your website window by the Casper Wallet extension content script, and you can access provider class and event types as below:\n\n```ts\nconst CasperWalletProvider = window.CasperWalletProvider;\nconst CasperWalletEventTypes = window.CasperWalletEventTypes;\n```\n\n## CasperWalletProvider\n\nThe `CasperWalletProvider` class serves as the main interface for interacting with the Casper Wallet extension. It provides a collection of methods that enable developers to easily request connections, switch accounts, sign transactions, sign messages, and manage wallet events. By using this class, developers can seamlessly integrate the Casper Wallet into their web applications, ensuring a smooth user experience.\n\n### Usage\n\nNOTE: be aware that `window.CasperWalletProvider` will be available asynchronously, because extension has to load in the browser.\n\n```ts\nconst CasperWalletProvider = window.CasperWalletProvider;\n\nconst provider = CasperWalletProvider();\n```\n\n### Constructor\n\n```ts\nconstructor(options?: CasperWalletProviderOptions);\n```\n\n#### Constructor Options\n\n```ts\ntype CasperWalletProviderOptions = {\n  // timeout (in ms) for requests to the extension [DEFAULT: 30 min]\n  timeout: number;\n};\n```\n\n### Methods\n\n#### Request the connect interface with the Casper Wallet extension. Will not show UI for already connected accounts and return true immediately\n\n```ts\nrequestConnection(): Promise\u003cboolean\u003e\n```\n\n- returns `true` value when connection request is accepted by the user or when account is already connected, `false` otherwise.\n\n- emits event of type `Connected` when successfully connected.\n\n#### Request the switch account interface with the Casper Wallet extension\n\n```ts\nrequestSwitchAccount(): Promise\u003cboolean\u003e\n```\n\n- returns `true` value when successfully switched account, `false` otherwise.\n\n- emits event of type `ActiveKeyChanged` when successfully switched account.\n\n#### Request the sign transaction interface with the Casper Wallet extension\n\n```ts\nsign(transactionJson: string, signingPublicKeyHex: string): Promise\u003cSignatureResponse\u003e\n```\n\n- `transactionJson` - stringified json of a transaction (use `toJSON` method of `Transaction` instance from `casper-js-sdk` and `JSON.stringify`)\n\n- `signingPublicKeyHex` - public key hash (in hex format)\n\n- returns a payload response when user responded to transaction request, it will contain `signature` if approved, or `cancelled === true` flag when rejected.\n\nExample:\n\n```ts\nconst transaction = Transaction.fromTransactionV1(...);\nconst transactionJson = transaction.toJSON();\n\nprovider\n  .sign(JSON.stringify(transactionJson), accountPublicKey)\n  .then(res =\u003e {\n    if (res.cancelled) {\n      alert('Sign cancelled');\n    } else {\n      const signedTransaction = transaction.setSignature(\n        res.signature,\n        CLPublicKey.fromHex(accountPublicKey)\n      );\n      alert('Sign successful: ' + JSON.stringify(signedTransaction, null, 2));\n    }\n  })\n  .catch(err =\u003e {\n    alert('Error: ' + err);\n  });\n```\n\n#### Request the sign message interface with the Casper Wallet extension\n\n```ts\nsignMessage(message: string, signingPublicKeyHex: string): Promise\u003cSignatureResponse\u003e\n```\n\n- `message` - message to sign as string\n\n- `signingPublicKeyHex` - public key hash (in hex format)\n\n- returns a payload response when user responded to transaction request, it will contain `signature` if approved, or `cancelled === true` flag when rejected.\n\nExample:\n\n```ts\nprovider\n  .signMessage(message, accountPublicKey)\n  .then(res =\u003e {\n    if (res.cancelled) {\n      alert('Sign cancelled');\n    } else {\n      alert('Sign successful: ' + JSON.stringify(res.signature, null, 2));\n    }\n  })\n  .catch(err =\u003e {\n    alert('Error: ' + err);\n  });\n```\n\n#### Disconnect the Casper Wallet extension\n\n```ts\ndisconnectFromSite(): Promise\u003cboolean\u003e\n```\n\n- returns `true` value when successfully disconnected, `false` otherwise.\n\n- emits event of type `Disconnected` when successfully disconnected.\n\n#### Get the connection status of the Casper Wallet extension\n\n```ts\nisConnected(): Promise\u003cboolean\u003e\n```\n\n- returns `true` value when currently connected at least one account, `false` otherwise.\n- throws when wallet is locked (err.code: 1)\n\n#### Get the active public key of the Casper Wallet extension\n\n```ts\ngetActivePublicKey(): Promise\u003cstring\u003e\n```\n\n- returns hex hash of the active public key.\n- throws when wallet is locked (err.code: 1)\n- throws when active account not approved to connect with the site (err.code: 2)\n\n#### Get a list of features that the active public key supports.\nIt can be `CasperWalletSupports` (`sign-deploy`, `sign-transactionv1` and `signMessage`)\n\n```ts\ngetActivePublicKeySupports(): Promise\u003cstring[]\u003e\n```\n\n- returns array of features that supports the active public key.\n- throws when wallet is locked (err.code: 1)\n- throws when active account not approved to connect with the site (err.code: 2)\n\n\n#### Get version of the Casper Wallet extension\n\n```ts\ngetVersion(): Promise\u003cstring\u003e;\n```\n\n- returns version of the installed wallet extension.\n\n## Events\n\nCasper Wallet extension is emitting events in the browser window of a connected site when the user interacts with the wallet extension.\nYou should set listeners to those events to keep the UI of your application in sync with the wallet extension state.\n\n### CasperWalletState\n\nEach event will contain a `json string` payload in the `event.detail` property. This payload contains the Casper Wallet extension internal state so you can keep you application UI in sync.\n\n```ts\nexport type CasperWalletState = {\n  /** contain wallet is locked flag */\n  isLocked: boolean;\n  /** if unlocked contain connected status flag of active key otherwise undefined */\n  isConnected: boolean | undefined;\n  /** if unlocked and connected contain active key otherwise undefined */\n  activeKey: string | undefined;\n  /** if unlocked and connected, contain a list of supported features for the current active key otherwise `undefined` */\n  activeKeySupports: CasperWalletSupports[] | undefined;\n};\n\nconst handleEvent = (event: { detail: string }) =\u003e {\n  try {\n    const state: CasperWalletState = JSON.parse(event.detail);\n    console.log(state.activeKey);\n  }\n};\n```\n\n### CasperWalletEventType\n\nEvent types emitted by the Casper Wallet extension.\nEvents like (connected \u0026 disconnected \u0026 tabChanged) are relevant only to the currently active connected site that triggered the call so events will emit only to these tabs containing the same origin to not impact different opened sites.\nOther events are emitted to all active tabs in all opened browser windows because they are triggered by the wallet state change and should be received by all opened sites to keep in sync.\n\nEmitted when account was successfully connected (only to active site):\n\n- Connected: \"casper-wallet:connected\"\n\nEmitted when account was successfully disconnected (only to active site):\n\n- Disconnected: \"casper-wallet:disconnected\"\n\nEmitted when browser tab was changed to one containing a connected site (only to active site)::\n\n- TabChanged: \"casper-wallet:tabChanged\"\n\nEmitted when active key was changed in the wallet extension:\n\n- ActiveKeyChanged: \"casper-wallet:activeKeyChanged\"\n\nEmitted when the wallet extension was locked:\n\n- Locked: \"casper-wallet:locked\"\n\nEmitted when the wallet extension was unlocked:\n\n- Unlocked: \"casper-wallet:unlocked\"\n\nThe active key was changed using the Wallet interface:\n\n- ActiveKeySupportsChanged: casper-wallet:activeKeySupportsChanged\n\n### Events Usage\n\n```ts\nuseEffect(() =\u003e {\n  const handleConnected = (event: any) =\u003e {\n    try {\n      const state: CasperWalletState = JSON.parse(event.detail);\n      if (state.activeKey) {\n        setActivePublicKey(state.activeKey);\n      }\n    } catch (err) {\n      handleError(err);\n    }\n  };\n\n  window.addEventListener(CasperWalletEventTypes.Connected, handleConnected);\n\n  return () =\u003e {\n    window.removeEventListener(\n      CasperWalletEventTypes.Connected,\n      handleConnected\n    );\n  };\n}, [setActivePublicKey]);\n```\n\n## Types\n\nHelper types for type safety and awesome developer experience.\n\n```ts\nenum CasperWalletSupports {\n  signDeploy = 'sign-deploy',\n  signTransactionV1 = 'sign-transactionv1',\n  signMessage = 'sign-message'\n}\n```\n\n### SignatureResponse\n\n```ts\ntype SignatureResponse =\n  | {\n      cancelled: true; // if sign was cancelled\n    }\n  | {\n      cancelled: false; // if sign was successfull\n      signatureHex: string; // signature as hex hash\n      signature: Uint8Array; // signature as byte array\n    };\n```\n\nUsage:\n\n```ts\nfunction handleResponse(res: SignatureResponse) {\n  if (res.cancelled) {\n    alert('Cancelled');\n  } else {\n    console.log(res.signatureHex);\n  }\n}\n```\n\n## Error Handling\n\nEach promise will return an error if something unexpected happens so you should always catch errors from each SDK call and handle them accordingly.\n\n```ts\nsignMessage(message, accountPublicKey)\n  .then((res) =\u003e { ... })\n  .catch((err) =\u003e {\n    handleError(err);\n  });\n```\n\n## Contributing\n\nWe welcome contributions from the community to help improve the Casper Wallet SDK. If you're interested in contributing, please read our [contribution guidelines](CONTRIBUTING.md) to get started.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmake-software%2Fcasper-wallet-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmake-software%2Fcasper-wallet-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmake-software%2Fcasper-wallet-sdk/lists"}