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 " } ) ;
lensApi . request ( {
redirectURL : " https://www.mywebsite.com/get-user-information " ,
target : LensRequestTargetType . Self ,
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 " } ) ;
const lens : LensRef = lensApi . endRequest ( ) ;
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 ;