lens-api
v1.0.0
Published
Lens request creation, and lens access for 3rd parties
Downloads
3
Readme
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;