lens-api
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Lens API

Here, you access Lens.

Request a new lens

import LensAPI from 'lens';
 
const lensApi = new LensAPI({ blockstackId: "MY_BLOCKSTACK_ID", publicKey: "MY_PUBLIC_KEY" });
 
// Will redirect to mylens.io to complete the request, and then back to 
// the specified redirectURL
// Will be redirected to (for example) https://app.mylens.io/request?clientId=MY_BLOCKSTACK_ID&redirectUrl=https://www.mywebsite.com/get-user-information...
lensApi.request({ 
    redirectURL: "https://www.mywebsite.com/get-user-information",
    target: LensRequestTargetType.Self, // Optional
    data: [{
        name: "firstName",
        type: "Text",
        value: "Nathan",
    }]
});
 

Return from requesting a new lens

import LensAPI, { LensRef } from 'lens';
 
const lensApi = new LensAPI({ blockstackId: "MY_BLOCKSTACK_ID", publicKey: "MY_PUBLIC_KEY" });
 
// As long as we are a valid redirect (which wasn't canceled) this will
// succeed. Otherwise it should throw.
const lens: LensRef = lensApi.endRequest(); // Or '.completeRequest'
// Access to these properties may depend on if the request was anonymous
// if accessing clientside.
const lensUrl : string = lens.url;
const lensKey : string = lens.key;

Obtain information about a lens (serverside, using private key)

import LensAPI, { Lens } from 'lens';
 
const lensApi = new LensAPI({ blockstackId: "MY_BLOCKSTACK_ID", publicKey: "MY_PUBLIC_KEY", privateKey: "MY_PRIVATE_KEY" });
 
const lensUrl: string = "https://hub.blockstack.org/store/15Bg8gbLKYfmJiEsRjdnmo5rUXQLF1Th39/lens-user-shares/47b199cf-99cb-4077-a3d1-2fa85725ad73.json";
 
const lens: Lens = await lensApi.resolve({ url: lensUrl });
const firstName : string = lens.data.filter(d => d.name == 'firstName')[0].value;
 

Obtain information about an anonymous lens (clientside, using symmetric key)

import LensAPI, { Lens } from 'lens';
 
const lensApi = new LensAPI({ blockstackId: "MY_BLOCKSTACK_ID", publicKey: "MY_PUBLIC_KEY" });
 
const lensUrl: string = "https://hub.blockstack.org/store/15Bg8gbLKYfmJiEsRjdnmo5rUXQLF1Th39/non-lens-user-shares/47b199cf-99cb-4077-a3d1-2fa85725ad73.json";
const lensKey: string = "3263216305a7021356a2b523fa1e29e908f98124c279d5783ab18f2320e1d4e2"
 
const lens: Lens = await lensApi.resolve({ url: lensUrl, key: lensKey });
const firstName : string = lens.data.filter(d => d.name == 'firstName')[0].value;
 

Readme

Keywords

none

Package Sidebar

Install

npm i lens-api

Weekly Downloads

2

Version

1.0.0

License

ISC

Unpacked Size

23 kB

Total Files

17

Last publish

Collaborators

  • acidleroy