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

@dscvr-one/canvas-client-sdk

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dscvr-one/canvas-client-sdk

SDK for iframes apps to connect to dscvr host using postMessage rpc

  • 1.0.0
  • unpublished
  • npm
  • Socket score

Version published
Weekly downloads
61
decreased by-53.79%
Maintainers
0
Weekly downloads
 
Created
Source

@dscvr-one/canvas-client-sdk

canvas-client-sdkxx is a small typescript library that can be used by iframe Apps to communicate with DSCVR's canvas hosts.

The library provides a CanvasClient class with methods to establish communication with DSCVR to get the current context (user and content) as well as to execute wallet transactions.

Installation

You can install Frames Adapter via npm:

npm install @dscvr-one/canvas-client-sdk

yarn

yarn add @dscvr-one/canvas-client-sdk

Usage

To use the CanvasClient, simply import it into your typescript project:

import { CanvasInterface, CanvasClient } from '@dscvr-one/canvas-client-sdk';

Then, instantiate CanvasClient

const canvasClient = new CanvasClient();

Use CanvasInterface to access the communication messages types and schemas.

const user: CanvasInterface.Handshake.User = response.untrusted.user;
const content: CanvasInterface.Handshake.Content = response.untrusted.content;

Example

import {
  CanvasInterface,
  CanvasClient,
} from '@dscvr-one/canvas-client-sdk';

const canvasClient = new CanvasClient();

const startHandshake = async () => {
  const response = await canvasClient.ready();
  // make sure to validate response.trustedBytes using @dscvr-one/canvas-server-sdk so the app is not used by platforms other than DSCVR
  if (response) {
    const user: CanvasInterface.Handshake.User = response.untrusted.user;
    const content: CanvasInterface.Handshake.Content = response.untrusted.content;
    // ...
  }
};

// Open an external link on DSCVR host
const openLink = () => {
  const url = 'https://...';
  canvasClient.openLink(url);
};

// Execute a wallet transaction
const createTx = async (response: CanvasInterface.User.ConnectWalletResponseMessage) => {
  if (!response.success) {
    console.error('Failed to connect wallet')
    return
  }
  // make sure to validate response.trustedBytes using @dscvr-one/canvas-server-sdk so the app is not used by platforms other than DSCVR
  const unsignedTx = // ...
  return unsignedTx;
}

const sendTransaction = async () => {
  const response = await canvasClient.connectWalletAndSignTransaction(
    'solana:101',
    createTx
  );
  if (!response) {
    console.error('Transaction not created');
    return;
  }
  // make sure to validate response.trustedBytes using @dscvr-one/canvas-server-sdk so the app is not used by platforms other than DSCVR
  if (response.untrusted.success) {
    const signedTx = response.untrusted.signedTx;
    // ....
  } else {
    console.error('Transaction failed', response);
  }
}

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, feel free to open an issue or submit a pull request.

Note:

  1. Please contribute using GitHub Flow
  2. Commits & PRs will be allowed only if the commit messages & PR titles follow the conventional commit standard, read more about it here
  3. PS. Ensure your commits are signed. Read why

Keywords

FAQs

Package last updated on 15 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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