@masa-finance/masa-sdk
Advanced tools
Comparing version 0.2.6 to 0.3.0
{ | ||
"name": "@masa-finance/masa-sdk", | ||
"version": "0.2.6", | ||
"version": "0.3.0", | ||
"description": "Brand new masa SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
import { BigNumber } from "ethers"; | ||
import Masa from "../masa"; | ||
export declare const twofa: (masa: Masa) => { | ||
mint: (address: string, phoneNumber: string, signature: string) => Promise<{ | ||
mint: (address: string, phoneNumber: string, code: string, signature: string) => Promise<{ | ||
tokenId: string | BigNumber; | ||
@@ -9,3 +9,8 @@ success: boolean; | ||
} | undefined>; | ||
create: (phoneNumber: string) => Promise<{ | ||
generate: (phoneNumber: string) => Promise<{ | ||
success: boolean; | ||
status: string; | ||
message: string; | ||
} | undefined>; | ||
create: (phoneNumber: string, code: string) => Promise<{ | ||
tokenId: string | BigNumber; | ||
@@ -19,3 +24,3 @@ success: boolean; | ||
tokenUri: string; | ||
metadata: import("..").I2fa; | ||
metadata: import("..").I2FA; | ||
}[] | undefined>; | ||
@@ -25,4 +30,4 @@ load: (identityId: BigNumber) => Promise<{ | ||
tokenUri: string; | ||
metadata: import("..").I2fa; | ||
metadata: import("..").I2FA; | ||
}[]>; | ||
}; |
@@ -8,9 +8,10 @@ "use strict"; | ||
const twofa = (masa) => ({ | ||
mint: (address, phoneNumber, signature) => masa.client.twofaMint(address, phoneNumber, signature), | ||
create: (phoneNumber) => (0, create_1.create2fa)(masa, phoneNumber), | ||
mint: (address, phoneNumber, code, signature) => masa.client.twoFAMint(address, phoneNumber, code, signature), | ||
generate: (phoneNumber) => masa.client.twoFAGenerate(phoneNumber), | ||
create: (phoneNumber, code) => (0, create_1.create2fa)(masa, phoneNumber, code), | ||
burn: (twofaId) => (0, burn_1.burn2fa)(masa, twofaId), | ||
list: (address) => (0, list_1.list2fas)(masa, address), | ||
load: (identityId) => (0, list_1.load2faByIdentityId)(masa, identityId), | ||
load: (identityId) => (0, list_1.load2fasByIdentityId)(masa, identityId), | ||
}); | ||
exports.twofa = twofa; | ||
//# sourceMappingURL=2fa.js.map |
@@ -22,3 +22,3 @@ "use strict"; | ||
catch (err) { | ||
console.error(`Burning of 2fa Failed! '${err.message}'`); | ||
console.error(`Burning of 2FA Failed! '${err.message}'`); | ||
} | ||
@@ -34,6 +34,6 @@ return false; | ||
return success; | ||
console.log(`Burning 2fa with id '${twofaId}'!`); | ||
console.log(`Burning 2FA with id '${twofaId}'!`); | ||
success = yield (0, exports.burn2faById)(masa, twofaId); | ||
if (success) { | ||
console.log(`Burned 2fa with id '${twofaId}'!`); | ||
console.log(`Burned 2FA with id '${twofaId}'!`); | ||
} | ||
@@ -40,0 +40,0 @@ } |
import Masa from "../masa"; | ||
import { BigNumber } from "ethers"; | ||
export declare const get2faTemplate: (phoneNumber: string) => string; | ||
export declare const create2fa: (masa: Masa, phoneNumber: string) => Promise<{ | ||
export declare const get2faTemplate: (phoneNumber: string, code: string) => string; | ||
export declare const create2fa: (masa: Masa, phoneNumber: string, code: string) => Promise<{ | ||
tokenId: string | BigNumber; | ||
@@ -6,0 +6,0 @@ success: boolean; |
@@ -13,5 +13,5 @@ "use strict"; | ||
exports.create2fa = exports.get2faTemplate = void 0; | ||
const get2faTemplate = (phoneNumber) => `Phone Number: ${phoneNumber}`; | ||
const get2faTemplate = (phoneNumber, code) => `Phone Number: ${phoneNumber} Code: ${code}`; | ||
exports.get2faTemplate = get2faTemplate; | ||
const create2fa = (masa, phoneNumber) => __awaiter(void 0, void 0, void 0, function* () { | ||
const create2fa = (masa, phoneNumber, code) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (yield masa.session.checkLogin()) { | ||
@@ -22,3 +22,3 @@ const address = yield masa.config.wallet.getAddress(); | ||
return; | ||
const msg = (0, exports.get2faTemplate)(phoneNumber); | ||
const msg = (0, exports.get2faTemplate)(phoneNumber, code); | ||
console.log(`Signer Address: '${address}'`); | ||
@@ -29,11 +29,9 @@ console.log(`Signing: \n'${msg}'\n`); | ||
console.log(`Signature: '${signature}'`); | ||
// 2. mint 2fa | ||
console.log("\nCreating 2fa"); | ||
const storeMetadataData = yield masa.twofa.mint(address, phoneNumber, signature); | ||
if (storeMetadataData) { | ||
const { success, message, tokenId } = storeMetadataData; | ||
if (!success) { | ||
console.error(`Creating 2fa failed! '${message}'`); | ||
} | ||
else { | ||
// 2. mint 2FA | ||
console.log("\nCreating 2FA"); | ||
const mint2FAData = yield masa.twofa.mint(address, phoneNumber, code, signature); | ||
if (mint2FAData) { | ||
const { success, message, tokenId } = mint2FAData; | ||
if (success) { | ||
console.log("2FA Created", tokenId); | ||
return { | ||
@@ -45,2 +43,5 @@ tokenId, | ||
} | ||
else { | ||
console.error(`Creating 2FA failed! '${message}'`); | ||
} | ||
} | ||
@@ -47,0 +48,0 @@ } |
import { BigNumber } from "ethers"; | ||
import Masa from "../masa"; | ||
import { I2fa } from "../interface"; | ||
export declare const load2faByIdentityId: (masa: Masa, twofaId: BigNumber) => Promise<{ | ||
import { I2FA } from "../interface"; | ||
export declare const load2fasByIdentityId: (masa: Masa, identityId: BigNumber) => Promise<{ | ||
tokenId: BigNumber; | ||
tokenUri: string; | ||
metadata: I2fa; | ||
metadata: I2FA; | ||
}[]>; | ||
@@ -12,3 +12,3 @@ export declare const list2fas: (masa: Masa, address?: string) => Promise<{ | ||
tokenUri: string; | ||
metadata: I2fa; | ||
metadata: I2FA; | ||
}[] | undefined>; |
@@ -12,13 +12,12 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.list2fas = exports.load2faByIdentityId = void 0; | ||
exports.list2fas = exports.load2fasByIdentityId = void 0; | ||
const helpers_1 = require("../helpers"); | ||
const load2faByIdentityId = (masa, twofaId) => __awaiter(void 0, void 0, void 0, function* () { | ||
const twofas = []; | ||
const load2fasByIdentityId = (masa, identityId) => __awaiter(void 0, void 0, void 0, function* () { | ||
const twoFAs = []; | ||
const identityContracts = yield masa.contracts.loadIdentityContracts(); | ||
const twofaIds = yield identityContracts.SoulLinkerContract["getSBTLinks(uint256,address)"](twofaId, identityContracts.Soulbound2FA.address); | ||
const twofaIds = yield identityContracts.SoulLinkerContract["getSBTLinks(uint256,address)"](identityId, identityContracts.Soulbound2FA.address); | ||
for (const tokenId of twofaIds) { | ||
const tokenUri = (0, helpers_1.patchMetadataUrl)(masa, yield identityContracts.Soulbound2FA.tokenURI(tokenId)); | ||
console.log(`Metadata Url: ${tokenUri}`); | ||
const metadata = (yield masa.metadata.retrieve(tokenUri)); | ||
twofas.push({ | ||
twoFAs.push({ | ||
tokenId, | ||
@@ -29,24 +28,22 @@ tokenUri, | ||
} | ||
return twofas; | ||
return twoFAs; | ||
}); | ||
exports.load2faByIdentityId = load2faByIdentityId; | ||
exports.load2fasByIdentityId = load2fasByIdentityId; | ||
const list2fas = (masa, address) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (yield masa.session.checkLogin()) { | ||
address = address || (yield masa.config.wallet.getAddress()); | ||
const identityId = yield masa.identity.load(address); | ||
if (!identityId) | ||
return; | ||
const twofas = yield (0, exports.load2faByIdentityId)(masa, identityId); | ||
if (twofas.length === 0) | ||
console.log("No 2fas found"); | ||
for (const twofa of twofas) { | ||
console.log(`Metadata: ${JSON.stringify(twofa.metadata, null, 2)}`); | ||
} | ||
return twofas; | ||
address = address || (yield masa.config.wallet.getAddress()); | ||
const identityId = yield masa.identity.load(address); | ||
if (!identityId) | ||
return; | ||
const twofas = yield (0, exports.load2fasByIdentityId)(masa, identityId); | ||
if (twofas.length === 0) | ||
console.log("No 2FAs found"); | ||
let i = 1; | ||
for (const twofa of twofas) { | ||
console.log(`Token: ${i}`); | ||
i++; | ||
console.log(`Metadata: ${JSON.stringify(twofa.metadata, null, 2)}`); | ||
} | ||
else { | ||
console.log("Not logged in please login first"); | ||
} | ||
return twofas; | ||
}); | ||
exports.list2fas = list2fas; | ||
//# sourceMappingURL=list.js.map |
@@ -32,20 +32,15 @@ "use strict"; | ||
const listCreditReports = (masa, address) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (yield masa.session.checkLogin()) { | ||
address = address || (yield masa.config.wallet.getAddress()); | ||
const identityId = yield masa.identity.load(address); | ||
if (!identityId) | ||
return; | ||
const creditReports = yield (0, exports.loadCreditScoresByIdentityId)(masa, identityId); | ||
if (creditReports.length === 0) | ||
console.log("No Credit Reports found"); | ||
for (const creditReport of creditReports) { | ||
console.log(`Metadata: ${JSON.stringify(creditReport.metadata, null, 2)}`); | ||
} | ||
return creditReports; | ||
address = address || (yield masa.config.wallet.getAddress()); | ||
const identityId = yield masa.identity.load(address); | ||
if (!identityId) | ||
return; | ||
const creditReports = yield (0, exports.loadCreditScoresByIdentityId)(masa, identityId); | ||
if (creditReports.length === 0) | ||
console.log("No Credit Reports found"); | ||
for (const creditReport of creditReports) { | ||
console.log(`Metadata: ${JSON.stringify(creditReport.metadata, null, 2)}`); | ||
} | ||
else { | ||
console.log("Not logged in please login first"); | ||
} | ||
return creditReports; | ||
}); | ||
exports.listCreditReports = listCreditReports; | ||
//# sourceMappingURL=list.js.map |
@@ -1,4 +0,4 @@ | ||
export interface I2fa { | ||
export interface I2FA { | ||
name: "Masa Soulbound 2FA v1.0.0"; | ||
description: "A decentralized 2fa"; | ||
description: "A decentralized 2FA"; | ||
image: "https://metadata.masa.finance/v1.0/2fa/2fa.png"; | ||
@@ -5,0 +5,0 @@ properties: { |
@@ -99,3 +99,3 @@ import { MasaClient } from "./utils"; | ||
twofa: { | ||
mint: (address: string, phoneNumber: string, signature: string) => Promise<{ | ||
mint: (address: string, phoneNumber: string, code: string, signature: string) => Promise<{ | ||
tokenId: string | import("ethers").BigNumber; | ||
@@ -105,3 +105,8 @@ success: boolean; | ||
} | undefined>; | ||
create: (phoneNumber: string) => Promise<{ | ||
generate: (phoneNumber: string) => Promise<{ | ||
success: boolean; | ||
status: string; | ||
message: string; | ||
} | undefined>; | ||
create: (phoneNumber: string, code: string) => Promise<{ | ||
tokenId: string | import("ethers").BigNumber; | ||
@@ -115,3 +120,3 @@ success: boolean; | ||
tokenUri: string; | ||
metadata: import("./interface").I2fa; | ||
metadata: import("./interface").I2FA; | ||
}[] | undefined>; | ||
@@ -121,3 +126,3 @@ load: (identityId: import("ethers").BigNumber) => Promise<{ | ||
tokenUri: string; | ||
metadata: import("./interface").I2fa; | ||
metadata: import("./interface").I2FA; | ||
}[]>; | ||
@@ -140,3 +145,3 @@ }; | ||
} | undefined>; | ||
retrieve: (url: string) => Promise<import("./interface").ICreditReport | import("./interface").IIdentity | import("./interface").I2fa | undefined>; | ||
retrieve: (url: string) => Promise<import("./interface").ICreditReport | import("./interface").IIdentity | import("./interface").I2FA | undefined>; | ||
}; | ||
@@ -143,0 +148,0 @@ utils: { |
@@ -16,3 +16,3 @@ import Masa from "../masa"; | ||
}[]>; | ||
export declare const listSoulnames: (masa: Masa, address?: string) => Promise<{ | ||
export declare const listSoulNames: (masa: Masa, address?: string) => Promise<{ | ||
index: string; | ||
@@ -19,0 +19,0 @@ tokenUri: string; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.listSoulnames = exports.loadSoulNamesByIdentityId = void 0; | ||
exports.listSoulNames = exports.loadSoulNamesByIdentityId = void 0; | ||
const loadSoulNamesByIdentityId = (masa, identityId) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -47,29 +47,23 @@ const soulNameDetails = []; | ||
exports.loadSoulNamesByIdentityId = loadSoulNamesByIdentityId; | ||
const listSoulnames = (masa, address) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (yield masa.session.checkLogin()) { | ||
address = address || (yield masa.config.wallet.getAddress()); | ||
// load identity | ||
const identityId = yield masa.identity.load(address); | ||
if (!identityId) | ||
return; | ||
const soulNames = yield (0, exports.loadSoulNamesByIdentityId)(masa, identityId); | ||
for (const soulName of soulNames) { | ||
console.log(`\nToken: ${parseInt(soulName.index) + 1}`); | ||
console.log(`Name: ${soulName.tokenDetails.sbtName}`); | ||
console.log(`Token ID: ${soulName.tokenDetails.tokenId.toNumber()}`); | ||
console.log(`Identity ID: ${soulName.tokenDetails.identityId.toNumber()}`); | ||
console.log(`Active: ${soulName.tokenDetails.active}`); | ||
console.log(`Metadata Uri: ${soulName.tokenUri}`); | ||
if (soulName.metadata) | ||
console.log(`Metadata: ${JSON.stringify(soulName.metadata, null, 2)}`); | ||
console.log(`Expiry Date: ${new Date(soulName.tokenDetails.expirationDate.toNumber() * 1000).toUTCString()}`); | ||
} | ||
return soulNames; | ||
const listSoulNames = (masa, address) => __awaiter(void 0, void 0, void 0, function* () { | ||
address = address || (yield masa.config.wallet.getAddress()); | ||
// load identity | ||
const identityId = yield masa.identity.load(address); | ||
if (!identityId) | ||
return; | ||
const soulNames = yield (0, exports.loadSoulNamesByIdentityId)(masa, identityId); | ||
for (const soulName of soulNames) { | ||
console.log(`\nToken: ${parseInt(soulName.index) + 1}`); | ||
console.log(`Name: ${soulName.tokenDetails.sbtName}`); | ||
console.log(`Token ID: ${soulName.tokenDetails.tokenId.toNumber()}`); | ||
console.log(`Identity ID: ${soulName.tokenDetails.identityId.toNumber()}`); | ||
console.log(`Active: ${soulName.tokenDetails.active}`); | ||
console.log(`Metadata Uri: ${soulName.tokenUri}`); | ||
if (soulName.metadata) | ||
console.log(`Metadata: ${JSON.stringify(soulName.metadata, null, 2)}`); | ||
console.log(`Expiry Date: ${new Date(soulName.tokenDetails.expirationDate.toNumber() * 1000).toUTCString()}`); | ||
} | ||
else { | ||
console.log("Not logged in please login first"); | ||
return []; | ||
} | ||
return soulNames; | ||
}); | ||
exports.listSoulnames = listSoulnames; | ||
exports.listSoulNames = listSoulNames; | ||
//# sourceMappingURL=list.js.map |
@@ -9,3 +9,3 @@ "use strict"; | ||
getRegistrationPrice: (soulName, duration, paymentMethod) => (0, create_1.getRegistrationPrice)(masa, soulName, duration, paymentMethod), | ||
list: (address) => (0, list_1.listSoulnames)(masa, address), | ||
list: (address) => (0, list_1.listSoulNames)(masa, address), | ||
loadSoulNamesByIdentityId: (identityId) => (0, list_1.loadSoulNamesByIdentityId)(masa, identityId), | ||
@@ -12,0 +12,0 @@ create: (soulName, duration, paymentMethod) => (0, create_1.createSoulName)(masa, soulName, duration, paymentMethod), |
@@ -1,2 +0,2 @@ | ||
import { I2fa, ICreditReport, IIdentity } from "../../interface"; | ||
import { I2FA, ICreditReport, IIdentity } from "../../interface"; | ||
import { BigNumber } from "ethers"; | ||
@@ -12,3 +12,3 @@ import Transaction from "arweave/node/lib/transaction"; | ||
sessionCheck: () => Promise<any | undefined>; | ||
getMetadata: (uri: string) => Promise<IIdentity | ICreditReport | I2fa | undefined>; | ||
getMetadata: (uri: string) => Promise<IIdentity | ICreditReport | I2FA | undefined>; | ||
storeMetadata: (soulName: string) => Promise<{ | ||
@@ -35,3 +35,3 @@ imageTransaction: Transaction; | ||
} | undefined>; | ||
twofaMint: (address: string, phoneNumber: string, signature: string) => Promise<{ | ||
twoFAMint: (address: string, phoneNumber: string, code: string, signature: string) => Promise<{ | ||
tokenId: string | BigNumber; | ||
@@ -41,2 +41,7 @@ success: boolean; | ||
} | undefined>; | ||
twoFAGenerate: (phoneNumber: string) => Promise<{ | ||
success: boolean; | ||
status: string; | ||
message: string; | ||
} | undefined>; | ||
sessionLogout: () => Promise<{ | ||
@@ -43,0 +48,0 @@ status: string; |
@@ -121,7 +121,8 @@ "use strict"; | ||
}); | ||
this.twofaMint = (address, phoneNumber, signature) => __awaiter(this, void 0, void 0, function* () { | ||
this.twoFAMint = (address, phoneNumber, code, signature) => __awaiter(this, void 0, void 0, function* () { | ||
const storeMetadataResponse = yield this.middlewareClient | ||
.post(`/contracts/2fa/mint`, { | ||
.post(`/2fa/mint`, { | ||
address, | ||
phoneNumber, | ||
code, | ||
signature, | ||
@@ -134,3 +135,3 @@ }, { | ||
.catch((err) => { | ||
console.error("Minting 2fa failed!", err.message); | ||
console.error("Minting 2FA failed!", err.message); | ||
}); | ||
@@ -146,2 +147,23 @@ if (storeMetadataResponse) { | ||
}); | ||
this.twoFAGenerate = (phoneNumber) => __awaiter(this, void 0, void 0, function* () { | ||
const storeMetadataResponse = yield this.middlewareClient | ||
.post(`/2fa/generate`, { | ||
phoneNumber, | ||
}, { | ||
headers: { | ||
cookie: this.cookie ? [this.cookie] : undefined, | ||
}, | ||
}) | ||
.catch((err) => { | ||
console.error("Generating 2FA failed!", err.message); | ||
}); | ||
if (storeMetadataResponse) { | ||
const { data: { success, message, status }, } = storeMetadataResponse; | ||
return { | ||
success, | ||
status, | ||
message, | ||
}; | ||
} | ||
}); | ||
this.sessionLogout = () => __awaiter(this, void 0, void 0, function* () { | ||
@@ -148,0 +170,0 @@ const logoutResponse = yield this.middlewareClient |
{ | ||
"name": "@masa-finance/masa-sdk", | ||
"version": "0.2.6", | ||
"version": "0.3.0", | ||
"description": "Brand new masa SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
159279
2372