Comment on page
Decentralized Authentication SDK
The last release date: August 1, 2023.
SDK Release Note: https://github.com/DAuth-Network/dauth/releases/tag/v0.2.0
Integrate the DAuth SDK into your platform to provide your users with a decentralized, verifiable social authentication experience. DAuth includes One-Time Password (OTP) methods through Email and SMS, and OAuth protocols via platforms such as Google and Github.
The authentication result comes in two modes:
proof
and jwt
. Proof is concise, suitable for on-chain verification, while JWT is OIDC compatible, suitable for off-chain verification, typically used during login. Users can choose different modes according to different scenarios.
- Seamless integration with the DAuth Network.
- Establish an encrypted channel for every data transfer, ensuring user data remains hidden from DAuth Nodes.
- Securely receive and verify OTP codes through a private channel.
- Procure idtoken via OAuth flow and generate ZK proof based on the token.
- Designed for ease of use and implementation.
The simplest method to install DAuth is via npm:
yarn add @dauth/core
After installing the package, import it into your project and begin to utilize it:
import DAuth from "@dauth/core";
const dauth = new DAuth({
baseURL: "https://demo-api.dauth.network/dauth/sdk/v1.1/",
clientID: "demo",
});
- 1.Use the
sendOtp
method to deliver an OTP code to the user. This method requires three parameters:
account
, which refers to the user's Google account, email address, or phone number. It is hexlike string without "0x".id_type
, which can bemailto
,tel
;request_id
is client-provided, and could be a string containing a unique transaction/bundle/userOp ID. It is string or hexlike string without "0x".
// account, account_type, request_id
await dauth.service.sendOtp({
account: account,
id_type: "mailto",
request_id: "request_id", // request_id: 'The id related to the TX or userOp'
});
- 2.The
authOtpConfirm
method can be used to verify an OTP code and obtain the DAuth proof.
enum ESignMode {
JWT = "jwt",
PROOF = "proof",
JWT_FIREBASE = "jwtdb",
BOTH = "both"
}
// code,
// request_id
// mode: ESignMode
// id_type: "mailto" | "tel"
const result = await dauth.service.authOtpConfirm({
code: emailOtp,
request_id: requestId,
mode: ESignMode.JWT,
id_type: 'mailto',
withPlainAccount: true // boolean, If true will return real email account
})
/* example return
{
"mode": "proof",
"data": {
"auth": {
"acc_and_type_hash": "c5056aae3e4b528500f5e19b0e**********c916766cdb226",
"request_id": "test",
"account_plain": "[email protected]"
},
"signature": "578be12beb6cb5702c0c14e5b48b1599387225c96dba2cb8ce55001508******613532c5bfc2766ecd778f86d3057c81ed47a1c"
}
}
or
{
"mode": "jwt",
"data": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhbGciOiJSUz*****vPdVzvmySt9dRlJ7IKH2VFP_7tKsndgLQxqXeDrEavdA3sptb7H6KdG4P57B3YDkXCkYo32Ts5PGgwxh3ayfjGC46WToWASL_p3XkFsDBiX6CW8Ko3ohqERwB1s6yBO4B-ox4r6591jnzy1AIstnEFmt673yqJLQ"
}
or
{
"mode": "both",
"data": {
"jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhbGciOiJSU*****6ImRhdXRoLm5ldHdvcmsiLCJhdWQiOiJkZW1vIiwiaWF0IjoxNjkwMjc1ODU0LCJleHAiOjE2OTAyNzk0NTR9.dSJXkq2dh816Sg31drUjwR0Wt1ih1SNtx_XFAzyVMKdzAQNKwlXIsFrh3mhicyHy0f6S2M7d1rUvj1OSloOTMInMe9WTc0ODBowo9B2UffqXZILZpRfA1rLlhpP1bzIK-MkarIK2npcbxpvpUkxzPivNrq_XZbidxoascxJs_4M94I8uMlL4XcjtGIi28Bgr3eqoAOE_lO9lby-L_X9XMMo6urlu5g0kR8UlGM3BeQA5hXIpBCJjLN35C29n9S9tc0vsuKfk2etWlWGG6brnUfmYI-ntKkPD8rSXJzNuWd3yCHadKcS93Rofz952PcCoWAYEiG3mkOw5K5v_dV9VNb6gq_29mWfIBgkkpBQosRSrjZ9hXj2r6IeMjJn6ffGMG8xbmtN1q_lUFKb1ZAVYR2gtvG2WYwKZC1m3Qa4rcQwK6KT3-rcqWbg-GhWEay-I5wW4Lr9ULD69cQccsnuiCwt50x4KZyAXYLgTF92OFuwgteZCO3n1uzL6y5hsX0Th",
"proof": {
"auth": {
"acc_and_type_hash": "c5056aae3e4b528500f5e19b0e**********c916766cdb226",
"request_id": "test",
"account_plain": "[email protected]"
},
"signature": "578be12beb6cb5702c0c14e5b4******c226e0cfbb454613532c5bfc2766ecd778f86d3057c81ed47a1c"
}
}
}
*/
Successful One-Time Password (OTP) verification via DAuth Network results in the generation of a signature, functioning as DAuth proof. This allows anyone to validate the user's identity. The proof can also be verified on-chain. Consequently, contract wallets can bypass all centralized verifications, triggering user transactions in a decentralized manner directly.
- 1.Retrieve authorization code from Google.
- 2.Upon receiving the authorization code, the
authOAuth
method can be used to procure the DAuth proof.
// code,
// request_id,
// id_type
// mode: jwt | proof
const result = await dauth.service.authOauth({
token: authorization_code,
request_id: "test",
id_type: "google",
mode: ESignMode.JWT
});
/* example return
{
"mode": "proof",
"data": {
"auth": {
"acc_and_type_hash": "c5056aae3e4b528500f5e19b0e**********c916766cdb226",
"request_id": "test",
"account_plain": "[email protected]"
},
"signature": "a5186118ad83eb466e60b37******47efd65dd387e1226052c3253aa60ac2c63fd1c"
}
}
or
{
"mode": "jwt",
"data": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhbGciOiJSUz*****vPdVzvmySt9dRlJ7IKH2VFP_7tKsndgLQxqXeDrEavdA3sptb7H6KdG4********jGC46WToWASL_p3XkFsDBiX6CW8Ko3ohqERwB1s6yBO4B-ox4r6591jnzy1AIstnEFmt673yqJLQ"
}
*/
- 1.Retrieve authorization code from Apple.
- 2.Upon receiving the authorization code, the
authOAuth
method can be used to procure the DAuth proof.
// code,
// request_id,
// id_type
// mode: ESignMode
const result = await dauth.service.authOauth({
token: authorization_code,
request_id: "test",
id_type: "apple",
mode: ESignMode.JWT
});
/* example return
{
"mode": "proof",
"data": {
"auth": {
"acc_and_type_hash": "c5056aae3e4b528500f5e19b0e**********c916766cdb226",
"request_id": "test",
"account_plain": "[email protected]"
},
"signature": "a5186118ad83eb466e60b37******47efd65dd387e1226052c3253aa60ac2c63fd1c"
}
}
or
{
"mode": "jwt",
"data": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhbGciOiJSUz*****vPdVzvmySt9dRlJ7IKH2VFP_7tKsndgLQxqXeDrEavdA3sptb7H6KdG4P57B3YDkXCkYo32Ts5PGgwxh3ayfjGC46WToWASL_p3XkFsDBiX6CW8Ko3ohqERwB1s6yBO4B-ox4r6591jnzy1AIstnEFmt673yqJLQ"
}
*/
- 1.Retrieve authorization code from Twitter Oauth2.
- 2.Upon receiving the authorization code, the
authOAuth
method can be used to procure the DAuth proof.
// code,
// request_id,
// id_type
// mode: ESignMode
const result = await dauth.service.authOauth({
token: authorization_code,
request_id: "test",
id_type: "twitter",
mode: ESignMode.JWT
});
/* example return
{
"mode": "proof",
"data": {
"auth": {
"acc_and_type_hash": "c5056aae3e4b528500f5e19b0e**********c916766cdb226",
"request_id": "test",
"account_plain": "[email protected]"
},
"signature": "a5186118ad83eb466e60b37******47efd65dd387e1226052c3253aa60ac2c63fd1c"
}
}
or
{
"mode": "jwt",
"data": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhbGciOiJSUz*****vPdVzvmySt9dRlJ7IKH2VFP_7tKsndgLQxqXeDrEavdA3sptb7H6KdG4P57B3YDkXCkYo32Ts5PGgwxh3ayfjGC46WToWASL_p3XkFsDBiX6CW8Ko3ohqERwB1s6yBO4B-ox4r6591jnzy1AIstnEFmt673yqJLQ"
}
*/
Last modified 3mo ago