@tiplink/api
Advanced tools
Comparing version 0.1.9 to 0.1.11
@@ -7,3 +7,3 @@ import { PublicKey } from "@solana/web3.js"; | ||
export declare const ON_CHAIN_SYMBOL_CHAR_LIMIT = 10; | ||
type ArgT = string | number | boolean | string[] | number[]; | ||
declare type ArgT = string | number | boolean | string[] | number[]; | ||
export declare class TipLinkClient { | ||
@@ -24,3 +24,6 @@ apiKey: string; | ||
} | ||
interface CampaignCreateParams { | ||
interface Themeable { | ||
themeId?: number; | ||
} | ||
interface CampaignCreateParams extends Themeable { | ||
name: string; | ||
@@ -69,3 +72,3 @@ description: string; | ||
} | ||
interface CampaignConstructorParams { | ||
interface CampaignConstructorParams extends Themeable { | ||
client: TipLinkClient; | ||
@@ -89,2 +92,3 @@ id: number; | ||
addEntries(tiplinks: TipLink[]): Promise<boolean>; | ||
hideEntries(tiplinks: TipLink[] | PublicKey[]): Promise<boolean>; | ||
getEntries(params: GetEntriesParams): Promise<TipLink[] | null>; | ||
@@ -162,3 +166,3 @@ getAnalytics(): Promise<AnalyticsSummary>; | ||
} | ||
interface MintConstructorParams { | ||
interface MintConstructorParams extends Themeable { | ||
client: TipLinkClient; | ||
@@ -190,3 +194,3 @@ id: number; | ||
} | ||
interface MintCreateParams { | ||
interface MintCreateParams extends Themeable { | ||
campaignName: string; | ||
@@ -193,0 +197,0 @@ campaignDescription?: string; |
@@ -20,4 +20,3 @@ "use strict"; | ||
exports.ON_CHAIN_SYMBOL_CHAR_LIMIT = 10; | ||
const URL_BASE = "https://tiplink.io"; | ||
// const URL_BASE = "http://localhost:3000"; | ||
const URL_BASE = index_1.TIPLINK_ORIGIN; | ||
const API_URL_BASE = `${URL_BASE}/api`; | ||
@@ -109,2 +108,3 @@ const STEP = 100; | ||
const active = typeof (params) != "undefined" && typeof (params.active) != "undefined" ? params.active : true; | ||
const themeId = typeof (params) != "undefined" && typeof (params.themeId) != "undefined" ? params.themeId : null; | ||
const salt = (0, crypto_1.generateRandomSalt)(); | ||
@@ -118,5 +118,6 @@ const ck = yield (0, crypto_1.generateKey)(); | ||
active: active, | ||
theme_id: themeId, | ||
}; | ||
const res = yield this.client.fetch("campaigns", null, campaignData, "POST"); | ||
const campaign = new Campaign({ client: this.client, id: res['id'], name: res['name'], description: res['description'], imageUrl: res['image_url'], active: res['active'], }); | ||
const campaign = new Campaign({ client: this.client, id: res['id'], name: res['name'], description: res['description'], imageUrl: res['image_url'], active: res['active'], themeId: res['theme_id'] }); | ||
if (typeof (this.client.publicKey) === "undefined") { | ||
@@ -205,3 +206,3 @@ // TODO should we handle this differently | ||
encrypted_link: encryptedLink, | ||
funding_txn: "funded", // TODO should we count it as funded when using api? | ||
funding_txn: "funded", | ||
}; | ||
@@ -224,2 +225,20 @@ return result; | ||
} | ||
hideEntries(tiplinks) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const publicKeys = tiplinks.map((tp) => tp instanceof index_1.TipLink ? tp.keypair.publicKey : tp); | ||
const entries = { | ||
publicKeys, | ||
funding_txn: "", | ||
}; | ||
yield this.client.fetch(`campaigns/${this.id}/campaign_entries`, null, entries, "PUT"); | ||
const analytics = publicKeys.map((pk) => { | ||
return { | ||
event: "FUNDING_FAILED", | ||
public_key: pk, | ||
}; | ||
}); | ||
yield this.client.fetch("analytics", null, analytics, "POST"); | ||
return true; | ||
}); | ||
} | ||
getEntries(params) { | ||
@@ -267,3 +286,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
const useFingerprint = typeof (params) != "undefined" && typeof (params.useFingerprint) != "undefined" ? params.useFingerprint : true; | ||
const unlimitedClaims = typeof (params) != "undefined" && typeof (params.unlimitedClaims) != "undefined" ? params.unlimitedClaims : true; | ||
const unlimitedClaims = typeof (params) != "undefined" && typeof (params.unlimitedClaims) != "undefined" ? params.unlimitedClaims : false; | ||
const active = typeof (params) != "undefined" && typeof (params.active) != "undefined" && params.active !== null ? params.active : true; | ||
@@ -460,2 +479,5 @@ const includedEntryIds = typeof (params) != "undefined" && typeof (params.includedEntryIds) != "undefined" && params.includedEntryIds !== null ? params.includedEntryIds : []; | ||
} | ||
if (params.themeId) { | ||
formData.append(`mint[${index}][themeId]`, String(params.themeId)); | ||
} | ||
if (params.mintName) { | ||
@@ -462,0 +484,0 @@ formData.append(`mint[${index}][name]`, params.mintName); |
@@ -1,3 +0,3 @@ | ||
import { PublicKey } from '@solana/web3.js'; | ||
import { EscrowTipLink, TipLink } from '.'; | ||
import { PublicKey } from "@solana/web3.js"; | ||
import { EscrowTipLink, TipLink } from "."; | ||
/** | ||
@@ -7,9 +7,9 @@ * Asynchronously calls secure enclave to create a TipLink, store it with an associated email, and return its public key. | ||
* @param {string} apiKey - The API key to be used for the request. | ||
* @param {string} email - The email address to be associated with the generated tiplink. | ||
* @returns {Promise<PublicKey>} A promise that resolves to the PublicKey of the generated tiplink. | ||
* @param {string} email - The email address to be associated with the receiver tiplink. | ||
* @returns {Promise<PublicKey>} A promise that resolves to the PublicKey of the receiver tiplink. | ||
* @throws {Error} Throws an error if the HTTPS request fails with a non-ok status. | ||
*/ | ||
export declare function createGeneratedTipLink(apiKey: string, email: string): Promise<PublicKey>; | ||
export declare function createReceiverTipLink(apiKey: string, email: string): Promise<PublicKey>; | ||
/** | ||
* Asynchronously calls secure enclave to retrieve the email associated with a TipLink public key. | ||
* Asynchronously calls secure enclave to retrieve the email associated with a receiver TipLink. | ||
* | ||
@@ -21,3 +21,3 @@ * @param {string} apiKey - The API key to be used for the request. | ||
*/ | ||
export declare function getGeneratedTipLinkEmail(apiKey: string, publicKey: PublicKey): Promise<string>; | ||
export declare function getReceiverEmail(apiKey: string, publicKey: PublicKey): Promise<string>; | ||
/** | ||
@@ -37,8 +37,6 @@ * Asynchronously emails a TipLink. | ||
/** | ||
* Asynchronously emails a deposited Escrow TipLink to a pre-defined recipient. | ||
* | ||
* @param {string} apiKey - The API key to be used for the request. | ||
* @param {EscrowTipLink} tiplinkPublicKey - The Escrow TipLink to be sent. Includes the toEmail and TipLink public key. | ||
* @param {string} escrowTipLink - The Escrow TipLink to be sent. Includes the toEmail and receiver TipLink public key. | ||
* @param {string} [toName] - Optional name of the recipient for the email. | ||
* @param {string} replyEmail - Optional email address for the recipient to reply to. | ||
* @param {string} [replyEmail] - Optional email address for the recipient to reply to. | ||
* @param {string} [replyName] - Optional name of the sender for the email. | ||
@@ -48,2 +46,32 @@ * @returns {Promise<void>} A promise that resolves when the email has been sent. | ||
*/ | ||
export declare function mailEscrow(apiKey: string, escrowTipLink: EscrowTipLink, toName?: string, replyEmail?: string, replyName?: string): Promise<void>; | ||
interface MailEscrowWithObjArgs { | ||
apiKey: string; | ||
escrowTipLink: EscrowTipLink; | ||
toName?: string; | ||
replyEmail?: string; | ||
replyName?: string; | ||
} | ||
/** | ||
* @param {string} apiKey - The API key to be used for the request. | ||
* @param {URL} depositorUrl - The TipLink URL received by the depositor. | ||
* @param {PublicKey} receiverTipLink - The public key of the receiver TipLink. | ||
* @param {string} [toName] - Optional name of the recipient for the email. | ||
* @param {string} [replyEmail] - Optional email address for the recipient to reply to. | ||
* @param {string} [replyName] - Optional name of the sender for the email. | ||
* @returns {Promise<void>} A promise that resolves when the email has been sent. | ||
* @throws {Error} Throws an error if the HTTP request fails with a non-ok status. | ||
*/ | ||
interface MailEscrowWithValsArgs { | ||
apiKey: string; | ||
toEmail: string; | ||
depositorUrl: URL; | ||
receiverTipLink: PublicKey; | ||
toName?: string; | ||
replyEmail?: string; | ||
replyName?: string; | ||
} | ||
/** | ||
* Asynchronously emails a deposited Escrow TipLink to a pre-defined recipient. | ||
*/ | ||
export declare function mailEscrow(args: MailEscrowWithObjArgs | MailEscrowWithValsArgs): Promise<void>; | ||
export {}; |
@@ -12,6 +12,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mailEscrow = exports.mail = exports.getGeneratedTipLinkEmail = exports.createGeneratedTipLink = void 0; | ||
exports.mailEscrow = exports.mail = exports.getReceiverEmail = exports.createReceiverTipLink = void 0; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const ENCLAVE_ENDPOINT = process.env.NEXT_PUBLIC_ENCLAVE_ENDPOINT_OVERRIDE || | ||
'https://mailer.tiplink.io'; | ||
"https://mailer.tiplink.io"; | ||
/** | ||
@@ -21,14 +21,14 @@ * Asynchronously calls secure enclave to create a TipLink, store it with an associated email, and return its public key. | ||
* @param {string} apiKey - The API key to be used for the request. | ||
* @param {string} email - The email address to be associated with the generated tiplink. | ||
* @returns {Promise<PublicKey>} A promise that resolves to the PublicKey of the generated tiplink. | ||
* @param {string} email - The email address to be associated with the receiver tiplink. | ||
* @returns {Promise<PublicKey>} A promise that resolves to the PublicKey of the receiver tiplink. | ||
* @throws {Error} Throws an error if the HTTPS request fails with a non-ok status. | ||
*/ | ||
function createGeneratedTipLink(apiKey, email) { | ||
function createReceiverTipLink(apiKey, email) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = `${ENCLAVE_ENDPOINT}/api/v1/generated-tiplinks/create`; | ||
const res = yield fetch(endpoint, { | ||
method: 'POST', | ||
method: "POST", | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'x-api-key': apiKey, | ||
"Content-Type": "application/json", | ||
"x-api-key": apiKey, | ||
}, | ||
@@ -44,5 +44,5 @@ body: JSON.stringify({ email }), | ||
} | ||
exports.createGeneratedTipLink = createGeneratedTipLink; | ||
exports.createReceiverTipLink = createReceiverTipLink; | ||
/** | ||
* Asynchronously calls secure enclave to retrieve the email associated with a TipLink public key. | ||
* Asynchronously calls secure enclave to retrieve the email associated with a receiver TipLink. | ||
* | ||
@@ -54,9 +54,9 @@ * @param {string} apiKey - The API key to be used for the request. | ||
*/ | ||
function getGeneratedTipLinkEmail(apiKey, publicKey) { | ||
function getReceiverEmail(apiKey, publicKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = `${ENCLAVE_ENDPOINT}/api/v1/generated-tiplinks/${publicKey.toString()}/email`; | ||
const res = yield fetch(endpoint, { | ||
method: 'GET', | ||
method: "GET", | ||
headers: { | ||
'x-api-key': apiKey, | ||
"x-api-key": apiKey, | ||
}, | ||
@@ -71,3 +71,3 @@ }); | ||
} | ||
exports.getGeneratedTipLinkEmail = getGeneratedTipLinkEmail; | ||
exports.getReceiverEmail = getReceiverEmail; | ||
/** | ||
@@ -96,6 +96,6 @@ * Asynchronously emails a TipLink. | ||
const res = yield fetch(url, { | ||
method: 'POST', | ||
method: "POST", | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'x-api-key': apiKey, | ||
"Content-Type": "application/json", | ||
"x-api-key": apiKey, | ||
}, | ||
@@ -107,3 +107,3 @@ body: JSON.stringify(body), | ||
} | ||
console.log('TipLink sent!', res); | ||
console.log("TipLink sent!", res); | ||
}); | ||
@@ -114,32 +114,32 @@ } | ||
* Asynchronously emails a deposited Escrow TipLink to a pre-defined recipient. | ||
* | ||
* @param {string} apiKey - The API key to be used for the request. | ||
* @param {EscrowTipLink} tiplinkPublicKey - The Escrow TipLink to be sent. Includes the toEmail and TipLink public key. | ||
* @param {string} [toName] - Optional name of the recipient for the email. | ||
* @param {string} replyEmail - Optional email address for the recipient to reply to. | ||
* @param {string} [replyName] - Optional name of the sender for the email. | ||
* @returns {Promise<void>} A promise that resolves when the email has been sent. | ||
* @throws {Error} Throws an error if the HTTP request fails with a non-ok status. | ||
*/ | ||
function mailEscrow(apiKey, escrowTipLink, toName, replyEmail, replyName) { | ||
function mailEscrow(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { apiKey, toName, replyEmail, replyName } = args; | ||
const { escrowTipLink } = args; | ||
let { toEmail, depositorUrl, receiverTipLink } = args; | ||
if (escrowTipLink) { | ||
toEmail = escrowTipLink.toEmail; | ||
depositorUrl = escrowTipLink.depositorUrl; | ||
receiverTipLink = escrowTipLink.receiverTipLink; | ||
} | ||
// Sanity check; error checking occurs in the enclave and on-chain program | ||
if (!escrowTipLink.pda) { | ||
throw new Error('Escrow has not been deposited'); | ||
if (!toEmail || !depositorUrl || !receiverTipLink) { | ||
throw new Error("Improper escrow."); | ||
} | ||
const url = `${ENCLAVE_ENDPOINT}/api/v1/email/send/escrow`; | ||
const body = { | ||
toEmail: escrowTipLink.toEmail, | ||
toEmail, | ||
toName, | ||
replyEmail, | ||
replyName, | ||
depositorUrl: escrowTipLink.depositUrl.toString(), | ||
tiplinkPublicKey: escrowTipLink.tiplinkPublicKey.toString(), | ||
depositorUrl: depositorUrl.toString(), | ||
tiplinkPublicKey: receiverTipLink.toString(), | ||
receiverUrlOverride: process.env.NEXT_PUBLIC_ESCROW_RECEIVER_URL_OVERRIDE || undefined, | ||
}; | ||
const res = yield fetch(url, { | ||
method: 'POST', | ||
method: "POST", | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'x-api-key': apiKey, | ||
"Content-Type": "application/json", | ||
"x-api-key": apiKey, | ||
}, | ||
@@ -151,5 +151,5 @@ body: JSON.stringify(body), | ||
} | ||
console.log('Escrow TipLink sent!', res); | ||
console.log("Escrow TipLink sent!", res); | ||
}); | ||
} | ||
exports.mailEscrow = mailEscrow; |
@@ -1,2 +0,2 @@ | ||
export type TiplinkEscrow = { | ||
export declare type TiplinkEscrow = { | ||
"version": "0.1.0"; | ||
@@ -3,0 +3,0 @@ "name": "tiplink_escrow"; |
@@ -1,2 +0,2 @@ | ||
import { PublicKey } from '@solana/web3.js'; | ||
import { PublicKey } from "@solana/web3.js"; | ||
export declare const ESCROW_PROGRAM_ID: PublicKey; | ||
@@ -6,1 +6,2 @@ export declare const TREASURY_PUBLIC_KEY: PublicKey; | ||
export declare const DEPOSIT_URL_BASE = "https://tiplink-mailer.vercel.app/depositor-url"; | ||
export declare const PRIO_FEES_LAMPORTS = 10000; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEPOSIT_URL_BASE = exports.PDA_SEED = exports.TREASURY_PUBLIC_KEY = exports.ESCROW_PROGRAM_ID = void 0; | ||
exports.PRIO_FEES_LAMPORTS = exports.DEPOSIT_URL_BASE = exports.PDA_SEED = exports.TREASURY_PUBLIC_KEY = exports.ESCROW_PROGRAM_ID = void 0; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
exports.ESCROW_PROGRAM_ID = new web3_js_1.PublicKey('8TqqugH88U3fDEWeKHqBSxZKeqoRrXkdpy3ciX5GAruK'); | ||
exports.TREASURY_PUBLIC_KEY = new web3_js_1.PublicKey('BGZMcTjyTCbkRszC1CBpFpP9CbVh3Ah2ZhjzCsc9PsAr'); | ||
exports.PDA_SEED = 'escrow'; | ||
exports.DEPOSIT_URL_BASE = 'https://tiplink-mailer.vercel.app/depositor-url'; // TEMP | ||
exports.ESCROW_PROGRAM_ID = new web3_js_1.PublicKey("8TqqugH88U3fDEWeKHqBSxZKeqoRrXkdpy3ciX5GAruK"); | ||
exports.TREASURY_PUBLIC_KEY = new web3_js_1.PublicKey("BGZMcTjyTCbkRszC1CBpFpP9CbVh3Ah2ZhjzCsc9PsAr"); | ||
exports.PDA_SEED = "escrow"; | ||
exports.DEPOSIT_URL_BASE = "https://tiplink-mailer.vercel.app/depositor-url"; // TEMP | ||
exports.PRIO_FEES_LAMPORTS = 10000; |
@@ -1,3 +0,30 @@ | ||
import { Connection, PublicKey, Transaction } from '@solana/web3.js'; | ||
import { Mint } from '@solana/spl-token'; | ||
import { Connection, PublicKey, Transaction } from "@solana/web3.js"; | ||
import { Mint } from "@solana/spl-token"; | ||
interface CreateWithReceiverArgs { | ||
connection: Connection; | ||
amount: number; | ||
toEmail: string; | ||
depositor: PublicKey; | ||
receiverTipLink: PublicKey; | ||
mint?: Mint; | ||
} | ||
interface CreateWithApiArgs { | ||
connection: Connection; | ||
amount: number; | ||
toEmail: string; | ||
depositor: PublicKey; | ||
apiKey: string; | ||
mint?: Mint; | ||
} | ||
interface GetaWithReceiverArgs { | ||
connection: Connection; | ||
pda: PublicKey; | ||
receiverEmail: string; | ||
} | ||
interface GetWithApiArgs { | ||
connection: Connection; | ||
pda: PublicKey; | ||
apiKey: string; | ||
} | ||
export declare function getEscrowReceiverTipLink(connection: Connection, pda: PublicKey): Promise<PublicKey | undefined>; | ||
/** | ||
@@ -11,8 +38,9 @@ * Represents an on-chain escrow that can be withdrawn by the original depositor or a TipLink, e-mailed to a recipient. | ||
toEmail: string; | ||
tiplinkPublicKey: PublicKey; | ||
receiverTipLink: PublicKey; | ||
amount: number; | ||
depositor: PublicKey; | ||
pda?: PublicKey; | ||
escrowId: PublicKey; | ||
pda: PublicKey; | ||
mint?: Mint; | ||
get depositUrl(): URL; | ||
get depositorUrl(): URL; | ||
private constructor(); | ||
@@ -22,7 +50,7 @@ /** | ||
*/ | ||
static create(apiKey: string, amount: number, toEmail: string, depositor: PublicKey, mint?: Mint): Promise<EscrowTipLink>; | ||
static create(args: CreateWithReceiverArgs | CreateWithApiArgs): Promise<EscrowTipLink>; | ||
/** | ||
* Creates an EscrowTipLink instance from a deposited, on-chain escrow. | ||
*/ | ||
static get(apiKey: string, connection: Connection, pda: PublicKey): Promise<EscrowTipLink | undefined>; | ||
static get(args: GetaWithReceiverArgs | GetWithApiArgs): Promise<EscrowTipLink | undefined>; | ||
private depositLamportTx; | ||
@@ -35,1 +63,2 @@ private depositSplTx; | ||
} | ||
export {}; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EscrowTipLink = void 0; | ||
exports.EscrowTipLink = exports.getEscrowReceiverTipLink = void 0; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
@@ -20,2 +20,27 @@ const spl_token_1 = require("@solana/spl-token"); | ||
const enclave_1 = require("../enclave"); | ||
function getEscrowReceiverTipLink(connection, pda) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const escrowProgram = new anchor_1.Program(tiplink_escrow_1.IDL, constants_1.ESCROW_PROGRAM_ID, { connection } // Provider interface only requires a connection, not a wallet | ||
); | ||
let pdaAccount; | ||
// TODO: Implement better method of deciphering between lamport and SPL PDAs | ||
try { | ||
// First see if it's a lamport escrow | ||
pdaAccount = yield escrowProgram.account.escrowLamports.fetch(pda); | ||
} | ||
catch (_a) { | ||
try { | ||
// If not, see if it's a SPL escrow | ||
pdaAccount = yield escrowProgram.account.escrowSpl.fetch(pda); | ||
} | ||
catch (_b) { | ||
// No escrow exists for this PDA | ||
// TODO: Provide info on whether it was withdrawn or never existed | ||
return undefined; | ||
} | ||
} | ||
return pdaAccount.tiplink; | ||
}); | ||
} | ||
exports.getEscrowReceiverTipLink = getEscrowReceiverTipLink; | ||
/** | ||
@@ -28,27 +53,38 @@ * Represents an on-chain escrow that can be withdrawn by the original depositor or a TipLink, e-mailed to a recipient. | ||
class EscrowTipLink { | ||
get depositUrl() { | ||
constructor(toEmail, receiverTipLink, amount, depositor, escrowId, pda, mint) { | ||
this.toEmail = toEmail; | ||
this.receiverTipLink = receiverTipLink; | ||
this.amount = amount; | ||
this.depositor = depositor; | ||
this.escrowId = escrowId; | ||
this.pda = pda; | ||
this.mint = mint; | ||
} | ||
get depositorUrl() { | ||
// Sanity check; error checking occurs in the enclave and on-chain program | ||
if (!this.pda) { | ||
throw new Error('Attempted to get depositUrl from a non-deposited escrow.'); | ||
throw new Error("Attempted to get depositorUrl from a non-deposited escrow."); | ||
} | ||
const urlStr = process.env.NEXT_PUBLIC_ESCROW_DEPOSITOR_URL_OVERRIDE || constants_1.DEPOSIT_URL_BASE; | ||
const url = new URL(urlStr); | ||
url.searchParams.append('pda', this.pda.toString()); | ||
url.searchParams.append("pda", this.pda.toString()); | ||
return url; | ||
} | ||
constructor(toEmail, tiplink, amount, depositor, pda, mint) { | ||
this.toEmail = toEmail; | ||
this.tiplinkPublicKey = tiplink; | ||
this.amount = amount; | ||
this.depositor = depositor; | ||
this.pda = pda; | ||
this.mint = mint; | ||
} | ||
/** | ||
* Creates an EscrowTipLink instance to be deposited. | ||
*/ | ||
static create(apiKey, amount, toEmail, depositor, mint) { | ||
static create(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const tiplink = yield (0, enclave_1.createGeneratedTipLink)(apiKey, toEmail); | ||
return new EscrowTipLink(toEmail, tiplink, amount, depositor, undefined, mint); | ||
const { connection, amount, toEmail, depositor, mint } = args; | ||
let { receiverTipLink } = args; | ||
const { apiKey } = args; | ||
if (!receiverTipLink) { | ||
receiverTipLink = yield (0, enclave_1.createReceiverTipLink)(apiKey, toEmail); | ||
} | ||
const tiplinkEscrowProgram = new anchor_1.Program(tiplink_escrow_1.IDL, constants_1.ESCROW_PROGRAM_ID, { connection } // Provider interface only requires a connection, not a wallet | ||
); | ||
const escrowKeypair = web3_js_1.Keypair.generate(); | ||
const escrowId = escrowKeypair.publicKey; | ||
const [pda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.PDA_SEED), escrowId.toBuffer(), depositor.toBuffer()], tiplinkEscrowProgram.programId); | ||
return new EscrowTipLink(toEmail, receiverTipLink, amount, depositor, escrowId, pda, mint); | ||
}); | ||
@@ -59,4 +95,7 @@ } | ||
*/ | ||
static get(apiKey, connection, pda) { | ||
static get(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { connection, pda } = args; | ||
let { receiverEmail } = args; | ||
const { apiKey } = args; | ||
const escrowProgram = new anchor_1.Program(tiplink_escrow_1.IDL, constants_1.ESCROW_PROGRAM_ID, { connection } // Provider interface only requires a connection, not a wallet | ||
@@ -84,5 +123,7 @@ ); | ||
} | ||
const tiplinkPublicKey = pdaAccount.tiplink; | ||
const email = yield (0, enclave_1.getGeneratedTipLinkEmail)(apiKey, tiplinkPublicKey); | ||
return new EscrowTipLink(email, tiplinkPublicKey, pdaAccount.amount.toNumber(), pdaAccount.depositor, pda, mint); | ||
const receiverTipLink = pdaAccount.tiplink; | ||
if (!receiverEmail) { | ||
receiverEmail = yield (0, enclave_1.getReceiverEmail)(apiKey, receiverTipLink); | ||
} | ||
return new EscrowTipLink(receiverEmail, receiverTipLink, pdaAccount.amount.toNumber(), pdaAccount.depositor, pdaAccount.escrowId, pda, mint); | ||
}); | ||
@@ -98,3 +139,3 @@ } | ||
treasury: constants_1.TREASURY_PUBLIC_KEY, | ||
tiplink: this.tiplinkPublicKey, | ||
tiplink: this.receiverTipLink, | ||
}) | ||
@@ -109,3 +150,3 @@ .transaction(); | ||
if (!this.mint) { | ||
throw new Error('Attempted to deposit SPL without mint set'); | ||
throw new Error("Attempted to deposit SPL without mint set"); | ||
} | ||
@@ -122,3 +163,3 @@ const pdaAta = yield (0, spl_token_1.getAssociatedTokenAddress)(this.mint.address, pda, true); | ||
pdaAta, | ||
tiplink: this.tiplinkPublicKey, | ||
tiplink: this.receiverTipLink, | ||
treasury: constants_1.TREASURY_PUBLIC_KEY, | ||
@@ -133,15 +174,7 @@ mint: this.mint.address, | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// Sanity check; error checking occurs in the enclave and on-chain program | ||
if (this.pda) { | ||
throw new Error('Escrow can only be deposited once'); | ||
} | ||
const tiplinkEscrowProgram = new anchor_1.Program(tiplink_escrow_1.IDL, constants_1.ESCROW_PROGRAM_ID, { connection } // Provider interface only requires a connection, not a wallet | ||
); | ||
const escrowKeypair = web3_js_1.Keypair.generate(); | ||
const escrowId = escrowKeypair.publicKey; | ||
const [pda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.PDA_SEED), escrowId.toBuffer(), this.depositor.toBuffer()], tiplinkEscrowProgram.programId); | ||
const tx = this.mint | ||
? yield this.depositSplTx(tiplinkEscrowProgram, escrowId, pda) | ||
: yield this.depositLamportTx(tiplinkEscrowProgram, escrowId, pda); | ||
this.pda = pda; | ||
? yield this.depositSplTx(tiplinkEscrowProgram, this.escrowId, this.pda) | ||
: yield this.depositLamportTx(tiplinkEscrowProgram, this.escrowId, this.pda); | ||
return tx; | ||
@@ -166,7 +199,4 @@ }); | ||
// Sanity check; error checking occurs in the enclave and on-chain program | ||
if (!this.pda) { | ||
throw new Error('Escrow has not been deposited.'); | ||
} | ||
if (!this.mint) { | ||
throw new Error('Attempted to withdraw SPL without mint set'); | ||
throw new Error("Attempted to withdraw SPL without mint set"); | ||
} | ||
@@ -192,6 +222,2 @@ // Recalculating to keep class state smaller | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// Sanity check; error checking occurs in the enclave and on-chain program | ||
if (!this.pda) { | ||
throw new Error('Escrow has not been deposited'); | ||
} | ||
const tiplinkEscrowProgram = new anchor_1.Program(tiplink_escrow_1.IDL, constants_1.ESCROW_PROGRAM_ID, { connection } // Provider interface only requires a connection, not a wallet | ||
@@ -198,0 +224,0 @@ ); |
@@ -1,2 +0,3 @@ | ||
import { EscrowTipLink } from './EscrowTipLink'; | ||
export { EscrowTipLink }; | ||
import { EscrowTipLink, getEscrowReceiverTipLink } from "./EscrowTipLink"; | ||
import { PRIO_FEES_LAMPORTS } from "./constants"; | ||
export { EscrowTipLink, getEscrowReceiverTipLink, PRIO_FEES_LAMPORTS }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EscrowTipLink = void 0; | ||
exports.PRIO_FEES_LAMPORTS = exports.getEscrowReceiverTipLink = exports.EscrowTipLink = void 0; | ||
const EscrowTipLink_1 = require("./EscrowTipLink"); | ||
Object.defineProperty(exports, "EscrowTipLink", { enumerable: true, get: function () { return EscrowTipLink_1.EscrowTipLink; } }); | ||
Object.defineProperty(exports, "getEscrowReceiverTipLink", { enumerable: true, get: function () { return EscrowTipLink_1.getEscrowReceiverTipLink; } }); | ||
const constants_1 = require("./constants"); | ||
Object.defineProperty(exports, "PRIO_FEES_LAMPORTS", { enumerable: true, get: function () { return constants_1.PRIO_FEES_LAMPORTS; } }); |
@@ -1,2 +0,3 @@ | ||
import { Keypair } from '@solana/web3.js'; | ||
import { Keypair } from "@solana/web3.js"; | ||
export declare const TIPLINK_ORIGIN: string; | ||
export declare class TipLink { | ||
@@ -10,7 +11,7 @@ url: URL; | ||
} | ||
import { TipLinkClient } from './client'; | ||
import { TipLinkClient } from "./client"; | ||
export { TipLinkClient }; | ||
import { EscrowTipLink } from './escrow'; | ||
export { EscrowTipLink }; | ||
import { mail, mailEscrow } from './enclave'; | ||
export { mail, mailEscrow }; | ||
import { EscrowTipLink, getEscrowReceiverTipLink, PRIO_FEES_LAMPORTS } from "./escrow"; | ||
export { EscrowTipLink, getEscrowReceiverTipLink, PRIO_FEES_LAMPORTS }; | ||
import { mail, mailEscrow, createReceiverTipLink, getReceiverEmail } from "./enclave"; | ||
export { mail, mailEscrow, createReceiverTipLink, getReceiverEmail }; |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mailEscrow = exports.mail = exports.EscrowTipLink = exports.TipLinkClient = exports.TipLink = void 0; | ||
exports.getReceiverEmail = exports.createReceiverTipLink = exports.mailEscrow = exports.mail = exports.PRIO_FEES_LAMPORTS = exports.getEscrowReceiverTipLink = exports.EscrowTipLink = exports.TipLinkClient = exports.TipLink = exports.TIPLINK_ORIGIN = void 0; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
@@ -22,3 +22,3 @@ const libsodium_wrappers_sumo_1 = __importDefault(require("libsodium-wrappers-sumo")); | ||
const DEFAULT_HASHLESS_TIPLINK_KEYLENGTH = 16; // 16 bytes = 128 bits | ||
const TIPLINK_ORIGIN = "https://tiplink.io"; | ||
exports.TIPLINK_ORIGIN = process.env.TIPLINK_ORIGIN_OVERRIDE || "https://tiplink.io"; | ||
const TIPLINK_PATH = "/i"; | ||
@@ -52,3 +52,3 @@ const VERSION_DELIMITER = "_"; | ||
const seed = sodium.pad(pw, sodium.crypto_sign_SEEDBYTES); | ||
return (web3_js_1.Keypair.fromSeed(seed)); | ||
return web3_js_1.Keypair.fromSeed(seed); | ||
}); | ||
@@ -70,3 +70,3 @@ class TipLink { | ||
const hash = (0, bs58_1.encode)(b); | ||
const urlString = `${TIPLINK_ORIGIN}${TIPLINK_PATH}#${VERSION_DELIMITER}${hash}`; | ||
const urlString = `${exports.TIPLINK_ORIGIN}${TIPLINK_PATH}#${VERSION_DELIMITER}${hash}`; | ||
// can't assign hash as it causes an error in React Native | ||
@@ -77,7 +77,8 @@ const link = new URL(urlString); | ||
} | ||
else { // version === 0 | ||
else { | ||
// version === 0 | ||
const b = yield randBuf(DEFAULT_TIPLINK_KEYLENGTH); | ||
const keypair = yield pwToKeypair(b); | ||
const hash = (0, bs58_1.encode)(b); | ||
const urlString = `${TIPLINK_ORIGIN}${TIPLINK_PATH}#${hash}`; | ||
const urlString = `${exports.TIPLINK_ORIGIN}${TIPLINK_PATH}#${hash}`; | ||
// can't assign hash as it causes an error in React Native | ||
@@ -128,4 +129,8 @@ const link = new URL(urlString); | ||
Object.defineProperty(exports, "EscrowTipLink", { enumerable: true, get: function () { return escrow_1.EscrowTipLink; } }); | ||
Object.defineProperty(exports, "getEscrowReceiverTipLink", { enumerable: true, get: function () { return escrow_1.getEscrowReceiverTipLink; } }); | ||
Object.defineProperty(exports, "PRIO_FEES_LAMPORTS", { enumerable: true, get: function () { return escrow_1.PRIO_FEES_LAMPORTS; } }); | ||
const enclave_1 = require("./enclave"); | ||
Object.defineProperty(exports, "mail", { enumerable: true, get: function () { return enclave_1.mail; } }); | ||
Object.defineProperty(exports, "mailEscrow", { enumerable: true, get: function () { return enclave_1.mailEscrow; } }); | ||
Object.defineProperty(exports, "createReceiverTipLink", { enumerable: true, get: function () { return enclave_1.createReceiverTipLink; } }); | ||
Object.defineProperty(exports, "getReceiverEmail", { enumerable: true, get: function () { return enclave_1.getReceiverEmail; } }); |
{ | ||
"name": "@tiplink/api", | ||
"version": "0.1.9", | ||
"version": "0.1.11", | ||
"description": "Api for creating and sending TipLinks", | ||
@@ -39,2 +39,3 @@ "main": "dist/index.js", | ||
"dotenv": "^16.3.1", | ||
"encoding": "^0.1.13", | ||
"eslint": "^8.19.0", | ||
@@ -41,0 +42,0 @@ "jest": "^28.1.3", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102970
23
2406
12
4
6