Skip to content

Latest commit

 

History

History
139 lines (102 loc) · 6.48 KB

DOCS.md

File metadata and controls

139 lines (102 loc) · 6.48 KB

Modules

SilkeySDK
JwtPayload

SilkeySDK

SilkeySDK~messageToSign(data) ⇒ string

Generates message to sign based on plain object data (keys and values)

Kind: inner method of SilkeySDK

Param Type
data Object

Example

messageToSign({ssoRedirectUrl: 'http://silkey.io', ssoRefId: 1});
// returns 'ssoRedirectUrl=http://silkey.io::ssoRefId=1'

SilkeySDK~generateSSORequestParams(privateKey, params) ⇒ Object

Generates all needed parameters (including signature) for requesting Silkey SSO

Kind: inner method of SilkeySDK
Throws:

  • on missing required data
Param Type Description
privateKey string this should be private key of domain owner
params SSOParamsI | KeyValueI Object with data: {ssoRedirectUrl*, .ssoRedirectMethod, ssoCancelUrl*, ssoRefId, ssoScope, ssoTimestamp} marked with * are required by Silkey SSO

Example

// returns {ssoSignature, ssoTimestamp, ssoRedirectUrl, ssoRefId, ssoScope, ssoRedirectMethod}
await generateSSORequestParams(domainOwnerPrivateKey, {ssoRedirectUrl: 'http://silkey.io', ssoRefId: 1});

SilkeySDK~fetchSilkeyEthAddress(providerUri, registryAddress) ⇒ Promise.<string>

Fetches public ethereum Silkey address directly from blockchain

Kind: inner method of SilkeySDK
Returns: Promise.<string> - public ethereum address of Silkey signer

Param Type Description
providerUri string ie: 'https://infura.io/v3/:infuraId' register to infura.io to get id
registryAddress string address of silkey smart contract registry, see list of addresses in README#registryAddress

SilkeySDK~tokenPayloadVerifier(token, callbackParams, websiteOwnerAddress, silkeyEthAddress, tokenExpirationTime) ⇒ JwtPayload | null

Verifies JWT token payload

Kind: inner method of SilkeySDK
Returns: JwtPayload | null - null when signatures are invalid, otherwise token payload
Throws:

  • when token is invalid or data are corrupted

See: https://jwt.io/ for details about token payload data

Param Type Default Description
token string secret JWT token returned by Silkey, this token CAN NOT BE SHARED as it is like user password they are all returned back to you when user being authenticated
callbackParams
websiteOwnerAddress
silkeyEthAddress string public ethereum address of Silkey
tokenExpirationTime number 30 max age of token in seconds, same token can be used to sign in many times, however from security perspective we should not allow for that case, because when somebody else steal token, he can access user account. That's why we should set expiration time. By deefault it iss set to 30 sec. When you pass 0 token will be always accepted.

Example

// returns {JwtPayload}
tokenPayloadVerifier('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0
 IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c');

JwtPayload

JwtPayload~JwtPayload : object

Kind: inner typedef of JwtPayload
Properties

Name Type Description
email string verified email of the user, IMPORTANT: if email in user profile is different, you should always update it with this one.
address string ID of the user, this is also valid ethereum address, use this to identify user
userSignature string proof that request came from the user
userSignatureTimestamp number time when signature was crated
silkeySignature string proof that Silkey verified the email
silkeySignatureTimestamp number time when signature was crated
scope string
migration boolean if user started migration to Silkey, this will be true

jwtPayload.messageToSignByUser() ⇒ string

Creates message that's need to be sign by user

Kind: instance method of JwtPayload

jwtPayload.messageToSignBySilkey() ⇒ string

Creates message that's need to be sign by Silkey

Kind: instance method of JwtPayload