A Library to Support Auth Requests fos Dash Platform Web Dapps.
This is an experimental project to explore methods of achieving a login flow with the Dash Platform.
The current specification can be found here.
This library contains the impementation of the server-side component. The client side component is the Dash Chrome Wallet.
npm i dashmachine-auth-request
Sample options module
exports.options = {
connection: {
apps: {
loginContract: {
contractId: '9GHRxvyYDmWz7pBKRjPnxjsJbbgKLngtejWWp3kEY1vB',
},
dpnsContract: {
contractId: '295xRRRMGYyAruG39XdAibaU9jMAzxhknkkAxFE7uVkW',
},
},
network: 'testnet',
seeds: { service: '34.215.175.142:3000' },
},
polling: {
responsePollingTimeout: 30000,
responsePollingFrequency: 5000,
reponsePollingDelay: 3000,
},
};
See the Examples below for possible usage.
Please note this library and documentation is experimental and in the early stages of development so should not be used in a production environment
The following sections are only of interest if you wish to develop this project.
git clone https://github.com/cloudwheels/dapp-auth-demo && cd dapp-auth-demo
It is recommended to install the npm nodemon package globally
npm i -g nodemon
The project can then be started in development mode using the following npm script:
npm run develop
Tests are configured using Jest and Supertest. The following scripts are available to run different sections of tests, optionally in watch
mode:
npm test
Single run of all tests
npm test:watch
Runs all tests in watch mode
npm test-unit:watch
Runs only unit tests in watch mode
npm test-routes:watch
Runs only route tests (using supertest) in watch mode
npm test-services:watch
Runs only route services in watch mode
The following is automatically generated from jsdoc annotaions in the code using the documentaion.js npm package.
You will need to install the documentation package globally:
npm i -g documentation
The run the npm scripts to generate the docs
docs-readme:lib
docs-readme:models
- AuthRequest
- findEnduser
- findVendor
- create
- submit
- mockReponse
- findResponses
- verify
- vendor
- enduser
- requestDoc
- responseDocType
- userResponses
- temp_timestamp
- entropy
- test_enduserPrivateKey
- test_enduserMnemonic
- DashAccount
- mnemonic
- DashConnection
- connect
- disconnect
- network
- mnemonic
- apps
- options
- client
- DashUser
- id
- name
- identityId
- identity
- publicKey
- privateKey
- find
- DashUser#toJSON
- DPNSDocument
- AuthRequestDocument
- DataDocument
- submit
- dataContractId
- id
- ownerId
- data
- find
- waitFor
- AuthResponseDocument
AuthRequest class - A request for authorisation
Note: the libarary has been updated so that the global connection object is no loger automatically connected & disconnected for each method. You must call the (undocumented) connect() and disconnect() methods before (and after) the other calls.
const AuthRequest = require('./lib/auth-request');
const Options = require('./options');
(async () => {
try {
const req = new AuthRequest(
1,
'bob',
'1234',
'alice',
'uniform analyst paper father soldier toe lesson fetch exhaust jazz swim response',
'Web dApp Sample',
Options.options,
'Tweets are greets',
);
req.vendor = {
name: 'alice',
id: 'Aobc5KKaA4ZqzP7unc6WawQXQEK2S3y6EwrmvJLLn1ui',
identityId: 'CheZBPQHztvLNqN67i4KxcTU1XmDz7qG85X1XeJbc7K5',
identity: {
id: 'CheZBPQHztvLNqN67i4KxcTU1XmDz7qG85X1XeJbc7K5',
publicKeys: [
{
id: 0,
type: 0,
data: 'A0/qSE6tis4l6BtQlTXB2PHW+WV+Iy0rpF5hAvX8hDRz',
isEnabled: true,
},
],
balance: 9686447,
},
publicKey: 'A0/qSE6tis4l6BtQlTXB2PHW+WV+Iy0rpF5hAvX8hDRz',
privateKey:
'40148175614f062fb0b4e5c519be7b6f57b872ebb55ea719376322fd12547bff',
};
let createdDoc,
submittedDoc,
mockResponse,
foundResponses,
verifiedRequest;
try {
createdDoc = await req.create();
console.log(`createdDoc:${JSON.stringify(createdDoc)}`);
} catch (e) {
console.log(`createdDoc ERROR:${e}`);
}
if (createdDoc.success) {
try {
submittedDoc = await req.submit();
console.log(`submittedDoc:${JSON.stringify(submittedDoc)}`);
} catch (e) {
console.log(`submittedDoc ERROR:${e}`);
}
}
if (submittedDoc.success) {
try {
req.test_enduserMnemonic =
'liar fee island situate deal exotic flat direct save bag fiscal news';
req.test_enduserPrivateKey =
'219c8a8f9376750cee9f06e0409718f2a1b88df4acc61bf9ed9cf252c8602768';
mockResponse = await req.mockReponse();
console.log(`mockResponse:${JSON.stringify(mockResponse)}`);
} catch (e) {
console.log(`mockResponse ERROR:${e}`);
}
}
if (mockResponse.success) {
try {
foundResponses = await req.findResponses();
console.log(
`foundResponses:${JSON.stringify(foundResponses)}`,
);
} catch (e) {
console.log(`foundResponses ERROR:${e}`);
}
}
if (foundResponses.success) {
try {
verifiedRequest = await req.verify();
console.log(
`verifiedRequest:${JSON.stringify(verifiedRequest)}`,
);
} catch (e) {
console.log(`verifiedRequest ERROR:${e}`);
}
}
} catch (e) {
console.log(`errors: ${e}`); ////
}
})();
if this._enduser==null looks up user details from the network using the supplied connection details //
Returns Object this._enduser
if this.vendor==null looks up user details from the network using the supplied connection details
Returns Object this._vendor
creates a request document of the required type if the username, pin and other options are valid ////
Returns Object the prepared request document
Submits the document set as the value of this._requestDoc returns this._submittedRequestDoc if successful
Returns any Promise<{ success: boolean; data: any; error?: undefined; message?: undefined; } | { error: boolean; message: any; success?: undefined; data?: undefined; }>
Mock Reponse with known user private keys
poll for responses matching criteria
Returns Object this._enduser
Verifies all found responses to deternine if loginis successful
newVendor
Object
newEnduser
newVendor
Object
newRequestDoc
Object
newResponseDocType
string
newTemp_timestamp
string
newEntropy
string
newTest_enduserPrivateKey
string
newTest_enduserMnemonic
string
DashAccount class - represents a Dash Platform Account
mnemonic
string The account mnemonic
newMnemonic
string
DashConnection class - represents a connection to Dash Platform
network
string Network to connect to i.e. 'testet' (default), mainnetmnemonic
string Account mnemonic to use for the connectionapps
Object named app identitiesseeds
Object additonal options, overrides other paramatersclient
Object the connection instance client
Intialises connection
Closes and disconnect the connection
newNetwork
newName
string
newMnemonic
string
newApps
Object
newSeeds
Object
newClient
any
DashUser class - represents a registered Dash Platform Username
id
string Unique id fopr the user record - the id of the DPNS document which registered the namename
string The registered usernameidentityId
string identityId associated with the usernameidentity
Object full identity object of the identityIdpublicKey
string private Key Associated wwith the user identityprivateKey
string private Key Associated wwith the user identity
newId
string
newName
string
newIdentityId
string
newIdentity
newIdentityId
Object
newPublicKey
string
newPrivateKey
string
Finds the registered username on the network
nameToFind
connection
Returns the DashUser instance in JSON format
Returns JSON
Extends DataDocument
DPNSDocument class - represents a anme registraion documents from Dash Platform Name Service
Extends DataDocument
AuthRequestDocument class - represents login documents sumitted to or retrieved from Dash Platform
DataDocument class - represents data docuemnts sumitted to or retrieved from Dash Platform
dataContractId
string dataContractId the document is validated againstownerId
string identityId of the owner / submitter of the documentdata
JSON actual data of the document represented as JSONsignature
string the signature on the document
submits the document instance using the passed in connection
connection
A DashJS client containing the account and keys for signing the doc
newContractId
string
newId
Object
newOwnerId
Object
newData
Object
finds one of more documents based on suplied query params
connection
string A DashJS connection, with options set for the locator of the docs to be retrievedlocator
string The document namequery
object Object containing array of query parameters
Returns Array array of found docuemnts
Calls find() over specified period at specifed frequency until result tis returned
connection
string A DashJS connection, with options set for the locator of the docs to be retrievedlocator
string The document namequery
Object Object containing array of query parameterstimeout
number Number of millseconds until rejecting as timed outfrequency
number Frequency of calls to find() in millisenconds
Returns Promise<Object> promise for JSON Object {success:true, data:array of found docuemnts} if resolved {error: true, message:[error message]} if rejected
Extends DataDocument
AuthResponseDocument class - represents auth response documents sumitted to or retrieved from Dash Platform
- DashAccount
- mnemonic
- DashUser
- id
- name
- identityId
- identity
- privateKey
- find
- DashUser#toJSON
- DataDocument
- submit
- dataContractId
- id
- ownerId
- data
- find
- waitFor
- DPNSDocument
- LoginDocument
- LoginResponseDocument
- Tweet
- username
- message
- date
DashAccount class - represents a Dash Platform Account
mnemonic
string The account mnemonic
newMnemonic
string
DashUser class - represents a registered Dash Platform Username
id
string Unique id fopr the user record - the id of the DPNS document which registered the namename
string The registered usernameidentityId
string identityId associated with the usernameidentity
Object full identity object of the identityIdprivateKey
string private Key Associated wwith the user identity
newId
string
newName
string
newIdentityId
string
newIdentity
newIdentityId
Object
newPrivateKey
string
Finds the registered username on the network
nameToFind
connection
Returns the DashUser instance in JSON format
Returns JSON
DataDocument class - represents data docuemnts sumitted to or retrieved from Dash Platform
dataContractId
string dataContractId the document is validated againstownerId
string identityId of the owner / submitter of the documentdata
JSON actual data of the document represented as JSONsignature
string the signature on the document
submits the document instance using the passed in connection
connection
A DashJS client containing the account and keys for signing the doc
newContractId
string
newId
Object
newOwnerId
Object
newData
Object
finds one of more documents based on suplied query params
connection
string A DashJS connection, with options set for the locator of the docs to be retrievedlocator
string The document namequery
object Object containing array of query parameters
Returns Array array of found docuemnts
Calls find() over specified period at specifed frequency until result tis returned
connection
string A DashJS connection, with options set for the locator of the docs to be retrievedlocator
string The document namequery
Object Object containing array of query parameterstimeout
number Number of millseconds until rejecting as timed outfrequency
number Frequency of calls to find() in millisenconds
Returns Promise<Object> promise for JSON Object {success:true, data:array of found docuemnts} if resolved {error: true, message:[error message]} if rejected
Extends DataDocument
DPNSDocument class - represents a anme registraion documents from Dash Platform Name Service
Extends DataDocument
LoginDocument class - represents login documents sumitted to or retrieved from Dash Platform
Extends DataDocument
LoginResponseDocument class - represents login documents sumitted to or retrieved from Dash Platform
Tweet class - represents a user tweet
newUsername
string
newMessage
string
newDate
string
DashConnection class - represents a connection to Dash Platform
network
string Network to connect to i.e. 'tesnet' (default), livenetaccount
Object An instance of the DashAccount class containing mnemonic etc to use for the connectionapps
Object named app identitiesoptions
Object additonal options, overrides other paramatersclient
Object the connection instance client
Intialises connection
Closes and disconnect the connection
newNetwork
newName
string
newAccount
Object
newApps
Object
newOptions
Object
newClient
any