Commit ee209646 authored by web's avatar web

up template

parent 2a3cfc26
[
{
"id": "1",
"image": "template1.png",
"prompt": "A figure engulfed in light, with intense glow radiating fiercely behind."
},
{
"id": "2",
"image": "template2.png",
"prompt": "A person standing amidst a storm, lightning crackling in the background."
},
{
"id": "3",
"image": "template3.png",
"prompt": "A silhouette surrounded by swirling mist, ethereal light illuminating the scene behind."
},
{
"id": "4",
"image": "template4.png",
"prompt": "A figure emerging from a dense forest, with beams of sunlight creating a radiant backdrop."
}
]
\ No newline at end of file
src/assets/images/banner.png

702 KB | W: | H:

src/assets/images/banner.png

630 KB | W: | H:

src/assets/images/banner.png
src/assets/images/banner.png
src/assets/images/banner.png
src/assets/images/banner.png
  • 2-up
  • Swipe
  • Onion skin
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("web3"),d=require("web3-eth-accounts"),f={TYPE_TG:1,TYPE_FP:2};let l=class{constructor({rpc_url:e="https://dev.rpc.aonet.ai",type:s=f.TYPE_FP,server:n="https://dev.rpc.aonet.ai",password:i="",storeage_url:o="",timeout:r=3e3,force_aon:c=!0}={}){if(this.rpc_url=e,this.type=s,this.server=n,this.password=i,this.storeage_url=o,this.timeout=r,this.force_aon=c,this.type==f.TYPE_FP&&this.storeage_url=="")throw new Error("storeage_url must be set when type = TYPE_FP")}static get LoginTypes(){return f}};var w;(function(t){t.NUMBER="NUMBER_NUMBER",t.HEX="NUMBER_HEX",t.STR="NUMBER_STR",t.BIGINT="NUMBER_BIGINT"})(w||(w={}));var y;(function(t){t.HEX="BYTES_HEX",t.UINT8ARRAY="BYTES_UINT8ARRAY"})(y||(y={}));w.BIGINT,y.HEX;w.HEX,y.HEX;var v;(function(t){t.EARLIEST="earliest",t.LATEST="latest",t.PENDING="pending",t.SAFE="safe",t.FINALIZED="finalized"})(v||(v={}));var P;(function(t){t.chainstart="chainstart",t.frontier="frontier",t.homestead="homestead",t.dao="dao",t.tangerineWhistle="tangerineWhistle",t.spuriousDragon="spuriousDragon",t.byzantium="byzantium",t.constantinople="constantinople",t.petersburg="petersburg",t.istanbul="istanbul",t.muirGlacier="muirGlacier",t.berlin="berlin",t.london="london",t.altair="altair",t.arrowGlacier="arrowGlacier",t.grayGlacier="grayGlacier",t.bellatrix="bellatrix",t.merge="merge",t.capella="capella",t.shanghai="shanghai"})(P||(P={}));var E=function(t,e,s,n){function i(o){return o instanceof s?o:new s(function(r){r(o)})}return new(s||(s=Promise))(function(o,r){function c(h){try{p(n.next(h))}catch(m){r(m)}}function a(h){try{p(n.throw(h))}catch(m){r(m)}}function p(h){h.done?o(h.value):i(h.value).then(c,a)}p((n=n.apply(t,e||[])).next())})};const I=Symbol.for("web3/base-provider");class T{static isWeb3Provider(e){return e instanceof T||!!(e&&e[I])}get[I](){return!0}send(e,s){this.request(e).then(n=>{s(null,n)}).catch(n=>{s(n)})}sendAsync(e){return E(this,void 0,void 0,function*(){return this.request(e)})}asEIP1193Provider(){const e=Object.create(this),s=e.request;return e.request=function(i){return E(this,void 0,void 0,function*(){return(yield s(i)).result})},e.asEIP1193Provider=void 0,e}}class q{constructor(e=new Options){try{this.options=e}catch(s){throw s}}async setItem(e,s,n){try{let i=localStorage.getItem("fingerprint"),o={key:e+"_"+i,value:s},r=localStorage.getItem("token");r=r.replace(/^\"|\"$/g,"");let c={Authorization:"Bearer "+r},a=this.options.storeage_url+"/kvapi/v1/storage/set";const h=await(await fetch(a,{method:"POST",headers:c,body:JSON.stringify(o)})).json();h&&h.success?n(null):n(new Error(JSON.stringify(h)||""))}catch(i){n(i)}}async getItem(e,s){try{let n=localStorage.getItem("token");n=n.replace(/^\"|\"$/g,"");let i={Authorization:"Bearer "+n},o=localStorage.getItem("fingerprint");e=e+"_"+o;let r=this.options.storeage_url+"/kvapi/v1/storage/get?key="+e;const a=await(await fetch(r,{method:"GET",headers:i})).json();a&&a.success?s(null,a.value):s(new Error(JSON.stringify(a)||""),null)}catch(n){s(n,null)}}}let g;const D=new Uint8Array(16);function R(){if(!g&&(g=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!g))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return g(D)}const u=[];for(let t=0;t<256;++t)u.push((t+256).toString(16).slice(1));function x(t,e=0){return u[t[e+0]]+u[t[e+1]]+u[t[e+2]]+u[t[e+3]]+"-"+u[t[e+4]]+u[t[e+5]]+"-"+u[t[e+6]]+u[t[e+7]]+"-"+u[t[e+8]]+u[t[e+9]]+"-"+u[t[e+10]]+u[t[e+11]]+u[t[e+12]]+u[t[e+13]]+u[t[e+14]]+u[t[e+15]]}const Y=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),b={randomUUID:Y};function G(t,e,s){if(b.randomUUID&&!e&&!t)return b.randomUUID();t=t||{};const n=t.random||(t.rng||R)();return n[6]=n[6]&15|64,n[8]=n[8]&63|128,x(n)}class B extends T{constructor(e=new l){try{super(),this.options=e,this.isAON=!0,window.Telegram&&window.Telegram.WebApp&&window.Telegram.WebApp.initData&&(e.type=l.LoginTypes.TYPE_TG),e.type==l.LoginTypes.TYPE_TG?(this.webapp=window.Telegram.WebApp,this.storage=window.Telegram.WebApp.CloudStorage):e.type==l.LoginTypes.TYPE_FP&&(this.storage=new q(e)),this.keystore=null,this.account=null,this._nextId=0,this.provider=new U.Web3.providers.HttpProvider(e.rpc_url)}catch(s){throw s}}async _getPassword(){return await new Promise((s,n)=>{this.storage.getItem("aon_web_sdk_password",(i,o)=>{i&&n(i),s(o)})})}async check(e){try{let s={};if(e.type==l.LoginTypes.TYPE_TG)s={platform:"telegram",initData:this.webapp.initData};else if(e.type==l.LoginTypes.TYPE_FP){let r=localStorage.getItem("fingerprint");r||(r=await new Promise((c,a)=>{const p=G();c(p)}),localStorage.setItem("fingerprint",r)),s={platform:"fingerprint",visitorId:r}}let n=e.server+"/api/v1/user/check";const o=await(await fetch(n,{method:"POST",body:JSON.stringify(s)})).json();if(o.code==0&&o.data){const r=o.data.token;return r&&this.setAuth(r),o.data}return o}catch(s){throw s}}async setPassword(e){await new Promise((s,n)=>{this.storage.setItem("aon_web_sdk_password",e,i=>{i&&n(i),s()})})}generateRandomPassword(e){const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+{}|:<>?-=[];',./";let n="";for(let i=0;i<e;i++){const o=Math.floor(Math.random()*s.length);n+=s[o]}return n}async getAuth(){return this.options.type==l.LoginTypes.TYPE_TG?await new Promise((s,n)=>{this.storage.getItem("token",(i,o)=>{i&&n(i),s(o)})}):localStorage.getItem("token")}async setAuth(e){this.options.type==l.LoginTypes.TYPE_TG?await new Promise((s,n)=>{this.storage.setItem("token",JSON.stringify(e),i=>{i&&n(i),s()})}):localStorage.setItem("token",e)}async createUserToServer(e,s){let n={keystore:JSON.stringify(e),signature:s},i=await this.getAuth();i=i.replace(/^\"|\"$/g,"");let o={Authorization:"Bearer "+i},r=this.options.server+"/api/v1/user/create";return await(await fetch(r,{method:"POST",headers:o,body:JSON.stringify(n)})).json()}async createUser(){let e=this.generateRandomPassword(20),s=d.create(),n=await d.encrypt(s.privateKey,e),o=d.sign(JSON.stringify(n),s.privateKey).signature,r=await this.createUserToServer(n,o);if(r.code==0)return await this.setPassword(e),{keystore:n,account:s};throw new Error(r.error||r.msg)}async loadKeystore(){try{let e=await this.check(this.options);if(e.code)throw new Error(e.msg||e.error);if(e.isNewUser){let n=await this.createUser();this.account=n.account,this.keystore=n.keystore;return}let s=await this._getPassword();this.keystore=JSON.parse(e.keystore),this.account=await d.decrypt(this.keystore,s)}catch(e){console.log("loadKeystore error",e)}}request(e){return console.log("request",e),e.method=="eth_accounts"||e.method=="eth_requestAccounts"?new Promise((s,n)=>{try{if(this.account){s([this.account.address]);return}s([])}catch(i){n(i)}}):e.method=="eth_sendTransaction"?(e.method="eth_signTransaction",new Promise((s,n)=>{let i=e.params&&e.params.length&&e.params[0];i.gasLimit||(i.gasLimit=5e5),this.provider.request({method:"eth_chainId"}).then(o=>{console.log("eth_chainId ",o);let r=100199;o.result&&(r=parseInt(o.result,16)),i.chainId||(i.chainId=r),i.v=27+i.chainId*2+8,this.provider.request({method:"eth_getTransactionCount",params:[this.account.address]}).then(c=>{console.log("eth_getTransactionCount ",c),i.nonce||(i.nonce=c.result),console.log("before signTransaction param",i),d.signTransaction(new d.Transaction(i),this.account.privateKey).then(a=>{if(console.log("signTransaction ",a),a&&a.rawTransaction&&a.rawTransaction.length){const p={method:"eth_sendRawTransaction",params:[a.rawTransaction],id:this._nextId++,jsonrpc:"2.0"};this.provider.request(p).then(h=>{console.log("eth_sendRawTransaction ",h),s(h)}).catch(h=>{console.log("eth_sendRawTransaction error",h),n(h)})}else n(new Error("signTransaction error"))}).catch(a=>{console.log("signTransaction error",a),n(a)})}).catch(c=>{console.log("eth_getTransactionCount error",c),n(c)})}).catch(o=>{console.log("eth_chainId error",o),n(o)})})):this.provider.request(e)}async send(e,s){console.log("send",e,s);const n={method:e,params:s,id:this._nextId++,jsonrpc:"2.0"};return this.request(n)}}async function _(t=new l){console.log("detectEthereumProvider in");let e=!1;return await new Promise(async(n,i)=>{if(window.ethereum){if(t.force_aon&&!window.ethereum.isAON){let r=await o(t);n(r)}n(window.ethereum)}else{let r=await o(t);n(r)}async function o(r){if(console.log("createProvider in"),e)return;e=!0;const c=new B(r);return await c.loadKeystore(),window.ethereum=c,console.log("createProvider instance",c),c}})}class A{constructor(e=new l){this.options=e}async login(){return(await _(this.options)).request({method:"eth_accounts"})}}const L=1,S=2,W={1:"/api",2:"/jwt"};class N{constructor(e){if(!(e&&e.auth&&e.auth.length))throw new Error("options.auth is not found");this.auth=e.auth,this.options=e,this.init()}init(){let e="/v1";this.options&&this.options.api_version&&this.options.api_version.length&&(e=this.options.api_version),this.auth_type=this.parseAuthType(this.auth),this.path=W[this.auth_type]+e}parseAuthType(e){const s=this.decodeBase64(e);return console.log("parseAuthType",s),s.indexOf("JWT")>-1?S:L}decodeBase64(e){return typeof window<"u"&&typeof window.atob=="function"?window.atob(e):Buffer.from(e,"base64").toString("utf-8")}async prediction(e,s){try{let n="https://api.aonet.ai";this.options&&this.options.host&&this.options.host.length&&(n=this.options.host);const i=n+this.path+e;let o={apikey:this.auth};if(this.auth_type==S&&(o={Authorization:"Bearer "+this.auth}),this.options&&this.options.headers)for(const a in this.options.headers)a!="apikey"&&a!="Authorization"&&(o[a]=this.options.headers[a]);const r=await fetch(i,{method:"POST",headers:o,body:JSON.stringify(s)});return r?await r.json():{task:{is_success:!1,task_error:"network error",exec_code:"5000"}}}catch(n){console.error("Error:",n)}}}(function(t,e){typeof define=="function"&&define.amd?define(["web3","web3-eth-accounts"],e):typeof module=="object"&&module.exports?module.exports=e(require("web3"),require("web3-eth-accounts")):t.aonweb=e(t.Web3,t.Web3EthAccounts)})(typeof self<"u"?self:void 0,function(t,e){return{Options:l,User:A,AI:N,detectEthereumProvider:_}});exports.AI=N;exports.Options=l;exports.User=A;exports.detectEthereumProvider=_;
import { Web3 as S } from "web3";
import { create as A, encrypt as N, sign as U, decrypt as D, signTransaction as R, Transaction as x } from "web3-eth-accounts";
const m = {
TYPE_TG: 1,
TYPE_FP: 2
};
let l = class {
constructor({
rpc_url: t = "https://dev.rpc.aonet.ai",
type: s = m.TYPE_FP,
server: n = "https://dev.rpc.aonet.ai",
password: i = "",
storeage_url: o = "",
timeout: r = 3e3,
force_aon: c = !0
} = {}) {
if (this.rpc_url = t, this.type = s, this.server = n, this.password = i, this.storeage_url = o, this.timeout = r, this.force_aon = c, this.type == m.TYPE_FP && this.storeage_url == "")
throw new Error("storeage_url must be set when type = TYPE_FP");
}
static get LoginTypes() {
return m;
}
};
var g;
(function(e) {
e.NUMBER = "NUMBER_NUMBER", e.HEX = "NUMBER_HEX", e.STR = "NUMBER_STR", e.BIGINT = "NUMBER_BIGINT";
})(g || (g = {}));
var w;
(function(e) {
e.HEX = "BYTES_HEX", e.UINT8ARRAY = "BYTES_UINT8ARRAY";
})(w || (w = {}));
g.BIGINT, w.HEX;
g.HEX, w.HEX;
var _;
(function(e) {
e.EARLIEST = "earliest", e.LATEST = "latest", e.PENDING = "pending", e.SAFE = "safe", e.FINALIZED = "finalized";
})(_ || (_ = {}));
var T;
(function(e) {
e.chainstart = "chainstart", e.frontier = "frontier", e.homestead = "homestead", e.dao = "dao", e.tangerineWhistle = "tangerineWhistle", e.spuriousDragon = "spuriousDragon", e.byzantium = "byzantium", e.constantinople = "constantinople", e.petersburg = "petersburg", e.istanbul = "istanbul", e.muirGlacier = "muirGlacier", e.berlin = "berlin", e.london = "london", e.altair = "altair", e.arrowGlacier = "arrowGlacier", e.grayGlacier = "grayGlacier", e.bellatrix = "bellatrix", e.merge = "merge", e.capella = "capella", e.shanghai = "shanghai";
})(T || (T = {}));
var v = function(e, t, s, n) {
function i(o) {
return o instanceof s ? o : new s(function(r) {
r(o);
});
}
return new (s || (s = Promise))(function(o, r) {
function c(h) {
try {
p(n.next(h));
} catch (y) {
r(y);
}
}
function a(h) {
try {
p(n.throw(h));
} catch (y) {
r(y);
}
}
function p(h) {
h.done ? o(h.value) : i(h.value).then(c, a);
}
p((n = n.apply(e, t || [])).next());
});
};
const P = Symbol.for("web3/base-provider");
class f {
static isWeb3Provider(t) {
return t instanceof f || !!(t && t[P]);
}
// To match an object "instanceof" does not work if
// matcher class and object is using different package versions
// to overcome this bottleneck used this approach.
// The symbol value for one string will always remain same regardless of package versions
// eslint-disable-next-line class-methods-use-this
get [P]() {
return !0;
}
/**
* @deprecated Please use `.request` instead.
* @param payload - Request Payload
* @param callback - Callback
*/
send(t, s) {
this.request(t).then((n) => {
s(null, n);
}).catch((n) => {
s(n);
});
}
/**
* @deprecated Please use `.request` instead.
* @param payload - Request Payload
*/
sendAsync(t) {
return v(this, void 0, void 0, function* () {
return this.request(t);
});
}
/**
* Modify the return type of the request method to be fully compatible with EIP-1193
*
* [deprecated] In the future major releases (\>= v5) all providers are supposed to be fully compatible with EIP-1193.
* So this method will not be needed and would not be available in the future.
*
* @returns A new instance of the provider with the request method fully compatible with EIP-1193
*
* @example
* ```ts
* const provider = new Web3HttpProvider('http://localhost:8545');
* const fullyCompatibleProvider = provider.asEIP1193Provider();
* const result = await fullyCompatibleProvider.request({ method: 'eth_getBalance' });
* console.log(result); // '0x0234c8a3397aab58' or something like that
* ```
*/
asEIP1193Provider() {
const t = Object.create(this), s = t.request;
return t.request = function(i) {
return v(this, void 0, void 0, function* () {
return (yield s(i)).result;
});
}, t.asEIP1193Provider = void 0, t;
}
}
class q {
constructor(t = new Options()) {
try {
this.options = t;
} catch (s) {
throw s;
}
}
async setItem(t, s, n) {
try {
let i = localStorage.getItem("fingerprint"), o = {
key: t + "_" + i,
value: s
}, r = localStorage.getItem("token");
r = r.replace(/^\"|\"$/g, "");
let c = {
Authorization: "Bearer " + r
}, a = this.options.storeage_url + "/kvapi/v1/storage/set";
const h = await (await fetch(a, {
method: "POST",
headers: c,
body: JSON.stringify(o)
})).json();
h && h.success ? n(null) : n(new Error(JSON.stringify(h) || ""));
} catch (i) {
n(i);
}
}
async getItem(t, s) {
try {
let n = localStorage.getItem("token");
n = n.replace(/^\"|\"$/g, "");
let i = {
Authorization: "Bearer " + n
}, o = localStorage.getItem("fingerprint");
t = t + "_" + o;
let r = this.options.storeage_url + "/kvapi/v1/storage/get?key=" + t;
const a = await (await fetch(r, {
method: "GET",
headers: i
})).json();
a && a.success ? s(null, a.value) : s(new Error(JSON.stringify(a) || ""), null);
} catch (n) {
s(n, null);
}
}
}
let d;
const Y = new Uint8Array(16);
function G() {
if (!d && (d = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !d))
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
return d(Y);
}
const u = [];
for (let e = 0; e < 256; ++e)
u.push((e + 256).toString(16).slice(1));
function B(e, t = 0) {
return u[e[t + 0]] + u[e[t + 1]] + u[e[t + 2]] + u[e[t + 3]] + "-" + u[e[t + 4]] + u[e[t + 5]] + "-" + u[e[t + 6]] + u[e[t + 7]] + "-" + u[e[t + 8]] + u[e[t + 9]] + "-" + u[e[t + 10]] + u[e[t + 11]] + u[e[t + 12]] + u[e[t + 13]] + u[e[t + 14]] + u[e[t + 15]];
}
const L = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), E = {
randomUUID: L
};
function W(e, t, s) {
if (E.randomUUID && !t && !e)
return E.randomUUID();
e = e || {};
const n = e.random || (e.rng || G)();
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, B(n);
}
class J extends f {
constructor(t = new l()) {
try {
super(), this.options = t, this.isAON = !0, window.Telegram && window.Telegram.WebApp && window.Telegram.WebApp.initData && (t.type = l.LoginTypes.TYPE_TG), t.type == l.LoginTypes.TYPE_TG ? (this.webapp = window.Telegram.WebApp, this.storage = window.Telegram.WebApp.CloudStorage) : t.type == l.LoginTypes.TYPE_FP && (this.storage = new q(t)), this.keystore = null, this.account = null, this._nextId = 0, this.provider = new S.providers.HttpProvider(t.rpc_url);
} catch (s) {
throw s;
}
}
async _getPassword() {
return await new Promise((s, n) => {
this.storage.getItem("aon_web_sdk_password", (i, o) => {
i && n(i), s(o);
});
});
}
async check(t) {
try {
let s = {};
if (t.type == l.LoginTypes.TYPE_TG)
s = {
platform: "telegram",
initData: this.webapp.initData
};
else if (t.type == l.LoginTypes.TYPE_FP) {
let r = localStorage.getItem("fingerprint");
r || (r = await new Promise((c, a) => {
const p = W();
c(p);
}), localStorage.setItem("fingerprint", r)), s = {
platform: "fingerprint",
visitorId: r
};
}
let n = t.server + "/api/v1/user/check";
const o = await (await fetch(n, {
method: "POST",
body: JSON.stringify(s)
})).json();
if (o.code == 0 && o.data) {
const r = o.data.token;
return r && this.setAuth(r), o.data;
}
return o;
} catch (s) {
throw s;
}
}
async setPassword(t) {
await new Promise((s, n) => {
this.storage.setItem("aon_web_sdk_password", t, (i) => {
i && n(i), s();
});
});
}
generateRandomPassword(t) {
const s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+{}|:<>?-=[];',./";
let n = "";
for (let i = 0; i < t; i++) {
const o = Math.floor(Math.random() * s.length);
n += s[o];
}
return n;
}
async getAuth() {
return this.options.type == l.LoginTypes.TYPE_TG ? await new Promise((s, n) => {
this.storage.getItem("token", (i, o) => {
i && n(i), s(o);
});
}) : localStorage.getItem("token");
}
async setAuth(t) {
this.options.type == l.LoginTypes.TYPE_TG ? await new Promise((s, n) => {
this.storage.setItem("token", JSON.stringify(t), (i) => {
i && n(i), s();
});
}) : localStorage.setItem("token", t);
}
async createUserToServer(t, s) {
let n = {
keystore: JSON.stringify(t),
signature: s
}, i = await this.getAuth();
i = i.replace(/^\"|\"$/g, "");
let o = {
Authorization: "Bearer " + i
}, r = this.options.server + "/api/v1/user/create";
return await (await fetch(r, {
method: "POST",
headers: o,
body: JSON.stringify(n)
})).json();
}
async createUser() {
let t = this.generateRandomPassword(20), s = A(), n = await N(s.privateKey, t), o = U(JSON.stringify(n), s.privateKey).signature, r = await this.createUserToServer(n, o);
if (r.code == 0)
return await this.setPassword(t), {
keystore: n,
account: s
};
throw new Error(r.error || r.msg);
}
async loadKeystore() {
try {
let t = await this.check(this.options);
if (t.code)
throw new Error(t.msg || t.error);
if (t.isNewUser) {
let n = await this.createUser();
this.account = n.account, this.keystore = n.keystore;
return;
}
let s = await this._getPassword();
this.keystore = JSON.parse(t.keystore), this.account = await D(this.keystore, s);
} catch (t) {
console.log("loadKeystore error", t);
}
}
request(t) {
return console.log("request", t), t.method == "eth_accounts" || t.method == "eth_requestAccounts" ? new Promise((s, n) => {
try {
if (this.account) {
s([this.account.address]);
return;
}
s([]);
} catch (i) {
n(i);
}
}) : t.method == "eth_sendTransaction" ? (t.method = "eth_signTransaction", new Promise((s, n) => {
let i = t.params && t.params.length && t.params[0];
i.gasLimit || (i.gasLimit = 5e5), this.provider.request({ method: "eth_chainId" }).then((o) => {
console.log("eth_chainId ", o);
let r = 100199;
o.result && (r = parseInt(o.result, 16)), i.chainId || (i.chainId = r), i.v = 27 + i.chainId * 2 + 8, this.provider.request({ method: "eth_getTransactionCount", params: [this.account.address] }).then((c) => {
console.log("eth_getTransactionCount ", c), i.nonce || (i.nonce = c.result), console.log("before signTransaction param", i), R(new x(i), this.account.privateKey).then((a) => {
if (console.log("signTransaction ", a), a && a.rawTransaction && a.rawTransaction.length) {
const p = {
method: "eth_sendRawTransaction",
params: [a.rawTransaction],
id: this._nextId++,
jsonrpc: "2.0"
};
this.provider.request(p).then((h) => {
console.log("eth_sendRawTransaction ", h), s(h);
}).catch((h) => {
console.log("eth_sendRawTransaction error", h), n(h);
});
} else
n(new Error("signTransaction error"));
}).catch((a) => {
console.log("signTransaction error", a), n(a);
});
}).catch((c) => {
console.log("eth_getTransactionCount error", c), n(c);
});
}).catch((o) => {
console.log("eth_chainId error", o), n(o);
});
})) : this.provider.request(t);
}
async send(t, s) {
console.log("send", t, s);
const n = {
method: t,
params: s,
id: this._nextId++,
jsonrpc: "2.0"
};
return this.request(n);
}
}
async function b(e = new l()) {
console.log("detectEthereumProvider in");
let t = !1;
return await new Promise(async (n, i) => {
if (window.ethereum) {
if (e.force_aon && !window.ethereum.isAON) {
let r = await o(e);
n(r);
}
n(window.ethereum);
} else {
let r = await o(e);
n(r);
}
async function o(r) {
if (console.log("createProvider in"), t)
return;
t = !0;
const c = new J(r);
return await c.loadKeystore(), window.ethereum = c, console.log("createProvider instance", c), c;
}
});
}
class j {
constructor(t = new l()) {
this.options = t;
}
async login() {
return (await b(this.options)).request({ method: "eth_accounts" });
}
}
const z = 1, I = 2, k = {
1: "/api",
2: "/jwt"
};
class O {
constructor(t) {
if (!(t && t.auth && t.auth.length))
throw new Error("options.auth is not found");
this.auth = t.auth, this.options = t, this.init();
}
init() {
let t = "/v1";
this.options && this.options.api_version && this.options.api_version.length && (t = this.options.api_version), this.auth_type = this.parseAuthType(this.auth), this.path = k[this.auth_type] + t;
}
parseAuthType(t) {
const s = this.decodeBase64(t);
return console.log("parseAuthType", s), s.indexOf("JWT") > -1 ? I : z;
}
decodeBase64(t) {
return typeof window < "u" && typeof window.atob == "function" ? window.atob(t) : Buffer.from(t, "base64").toString("utf-8");
}
async prediction(t, s) {
try {
let n = "https://api.aonet.ai";
this.options && this.options.host && this.options.host.length && (n = this.options.host);
const i = n + this.path + t;
let o = {
apikey: this.auth
};
if (this.auth_type == I && (o = {
Authorization: "Bearer " + this.auth
}), this.options && this.options.headers)
for (const a in this.options.headers)
a != "apikey" && a != "Authorization" && (o[a] = this.options.headers[a]);
const r = await fetch(i, {
method: "POST",
headers: o,
body: JSON.stringify(s)
});
return r ? await r.json() : {
task: {
is_success: !1,
task_error: "network error",
exec_code: "5000"
}
};
} catch (n) {
console.error("Error:", n);
}
}
}
(function(e, t) {
typeof define == "function" && define.amd ? define(["web3", "web3-eth-accounts"], t) : typeof module == "object" && module.exports ? module.exports = t(require("web3"), require("web3-eth-accounts")) : e.aonweb = t(e.Web3, e.Web3EthAccounts);
})(typeof self < "u" ? self : void 0, function(e, t) {
return {
Options: l,
User: j,
AI: O,
detectEthereumProvider: b
};
});
export {
O as AI,
l as Options,
j as User,
b as detectEthereumProvider
};
var aonweb=function(d,D,g){"use strict";const f={TYPE_TG:1,TYPE_FP:2};let l=class{constructor({rpc_url:e="https://dev.rpc.aonet.ai",type:i=f.TYPE_FP,server:n="https://dev.rpc.aonet.ai",password:s="",storeage_url:o="",timeout:r=3e3,force_aon:c=!0}={}){if(this.rpc_url=e,this.type=i,this.server=n,this.password=s,this.storeage_url=o,this.timeout=r,this.force_aon=c,this.type==f.TYPE_FP&&this.storeage_url=="")throw new Error("storeage_url must be set when type = TYPE_FP")}static get LoginTypes(){return f}};var w;(function(t){t.NUMBER="NUMBER_NUMBER",t.HEX="NUMBER_HEX",t.STR="NUMBER_STR",t.BIGINT="NUMBER_BIGINT"})(w||(w={}));var y;(function(t){t.HEX="BYTES_HEX",t.UINT8ARRAY="BYTES_UINT8ARRAY"})(y||(y={})),w.BIGINT,y.HEX,w.HEX,y.HEX;var P;(function(t){t.EARLIEST="earliest",t.LATEST="latest",t.PENDING="pending",t.SAFE="safe",t.FINALIZED="finalized"})(P||(P={}));var I;(function(t){t.chainstart="chainstart",t.frontier="frontier",t.homestead="homestead",t.dao="dao",t.tangerineWhistle="tangerineWhistle",t.spuriousDragon="spuriousDragon",t.byzantium="byzantium",t.constantinople="constantinople",t.petersburg="petersburg",t.istanbul="istanbul",t.muirGlacier="muirGlacier",t.berlin="berlin",t.london="london",t.altair="altair",t.arrowGlacier="arrowGlacier",t.grayGlacier="grayGlacier",t.bellatrix="bellatrix",t.merge="merge",t.capella="capella",t.shanghai="shanghai"})(I||(I={}));var b=function(t,e,i,n){function s(o){return o instanceof i?o:new i(function(r){r(o)})}return new(i||(i=Promise))(function(o,r){function c(u){try{p(n.next(u))}catch(v){r(v)}}function a(u){try{p(n.throw(u))}catch(v){r(v)}}function p(u){u.done?o(u.value):s(u.value).then(c,a)}p((n=n.apply(t,e||[])).next())})};const E=Symbol.for("web3/base-provider");class T{static isWeb3Provider(e){return e instanceof T||!!(e&&e[E])}get[E](){return!0}send(e,i){this.request(e).then(n=>{i(null,n)}).catch(n=>{i(n)})}sendAsync(e){return b(this,void 0,void 0,function*(){return this.request(e)})}asEIP1193Provider(){const e=Object.create(this),i=e.request;return e.request=function(s){return b(this,void 0,void 0,function*(){return(yield i(s)).result})},e.asEIP1193Provider=void 0,e}}class R{constructor(e=new Options){try{this.options=e}catch(i){throw i}}async setItem(e,i,n){try{let s=localStorage.getItem("fingerprint"),o={key:e+"_"+s,value:i},r=localStorage.getItem("token");r=r.replace(/^\"|\"$/g,"");let c={Authorization:"Bearer "+r},a=this.options.storeage_url+"/kvapi/v1/storage/set";const u=await(await fetch(a,{method:"POST",headers:c,body:JSON.stringify(o)})).json();u&&u.success?n(null):n(new Error(JSON.stringify(u)||""))}catch(s){n(s)}}async getItem(e,i){try{let n=localStorage.getItem("token");n=n.replace(/^\"|\"$/g,"");let s={Authorization:"Bearer "+n},o=localStorage.getItem("fingerprint");e=e+"_"+o;let r=this.options.storeage_url+"/kvapi/v1/storage/get?key="+e;const a=await(await fetch(r,{method:"GET",headers:s})).json();a&&a.success?i(null,a.value):i(new Error(JSON.stringify(a)||""),null)}catch(n){i(n,null)}}}let m;const q=new Uint8Array(16);function Y(){if(!m&&(m=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!m))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return m(q)}const h=[];for(let t=0;t<256;++t)h.push((t+256).toString(16).slice(1));function G(t,e=0){return h[t[e+0]]+h[t[e+1]]+h[t[e+2]]+h[t[e+3]]+"-"+h[t[e+4]]+h[t[e+5]]+"-"+h[t[e+6]]+h[t[e+7]]+"-"+h[t[e+8]]+h[t[e+9]]+"-"+h[t[e+10]]+h[t[e+11]]+h[t[e+12]]+h[t[e+13]]+h[t[e+14]]+h[t[e+15]]}const S={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function W(t,e,i){if(S.randomUUID&&!e&&!t)return S.randomUUID();t=t||{};const n=t.random||(t.rng||Y)();return n[6]=n[6]&15|64,n[8]=n[8]&63|128,G(n)}class x extends T{constructor(e=new l){try{super(),this.options=e,this.isAON=!0,window.Telegram&&window.Telegram.WebApp&&window.Telegram.WebApp.initData&&(e.type=l.LoginTypes.TYPE_TG),e.type==l.LoginTypes.TYPE_TG?(this.webapp=window.Telegram.WebApp,this.storage=window.Telegram.WebApp.CloudStorage):e.type==l.LoginTypes.TYPE_FP&&(this.storage=new R(e)),this.keystore=null,this.account=null,this._nextId=0,this.provider=new D.Web3.providers.HttpProvider(e.rpc_url)}catch(i){throw i}}async _getPassword(){return await new Promise((i,n)=>{this.storage.getItem("aon_web_sdk_password",(s,o)=>{s&&n(s),i(o)})})}async check(e){try{let i={};if(e.type==l.LoginTypes.TYPE_TG)i={platform:"telegram",initData:this.webapp.initData};else if(e.type==l.LoginTypes.TYPE_FP){let r=localStorage.getItem("fingerprint");r||(r=await new Promise((c,a)=>{const p=W();c(p)}),localStorage.setItem("fingerprint",r)),i={platform:"fingerprint",visitorId:r}}let n=e.server+"/api/v1/user/check";const o=await(await fetch(n,{method:"POST",body:JSON.stringify(i)})).json();if(o.code==0&&o.data){const r=o.data.token;return r&&this.setAuth(r),o.data}return o}catch(i){throw i}}async setPassword(e){await new Promise((i,n)=>{this.storage.setItem("aon_web_sdk_password",e,s=>{s&&n(s),i()})})}generateRandomPassword(e){const i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+{}|:<>?-=[];',./";let n="";for(let s=0;s<e;s++){const o=Math.floor(Math.random()*i.length);n+=i[o]}return n}async getAuth(){return this.options.type==l.LoginTypes.TYPE_TG?await new Promise((i,n)=>{this.storage.getItem("token",(s,o)=>{s&&n(s),i(o)})}):localStorage.getItem("token")}async setAuth(e){this.options.type==l.LoginTypes.TYPE_TG?await new Promise((i,n)=>{this.storage.setItem("token",JSON.stringify(e),s=>{s&&n(s),i()})}):localStorage.setItem("token",e)}async createUserToServer(e,i){let n={keystore:JSON.stringify(e),signature:i},s=await this.getAuth();s=s.replace(/^\"|\"$/g,"");let o={Authorization:"Bearer "+s},r=this.options.server+"/api/v1/user/create";return await(await fetch(r,{method:"POST",headers:o,body:JSON.stringify(n)})).json()}async createUser(){let e=this.generateRandomPassword(20),i=g.create(),n=await g.encrypt(i.privateKey,e),o=g.sign(JSON.stringify(n),i.privateKey).signature,r=await this.createUserToServer(n,o);if(r.code==0)return await this.setPassword(e),{keystore:n,account:i};throw new Error(r.error||r.msg)}async loadKeystore(){try{let e=await this.check(this.options);if(e.code)throw new Error(e.msg||e.error);if(e.isNewUser){let n=await this.createUser();this.account=n.account,this.keystore=n.keystore;return}let i=await this._getPassword();this.keystore=JSON.parse(e.keystore),this.account=await g.decrypt(this.keystore,i)}catch(e){console.log("loadKeystore error",e)}}request(e){return console.log("request",e),e.method=="eth_accounts"||e.method=="eth_requestAccounts"?new Promise((i,n)=>{try{if(this.account){i([this.account.address]);return}i([])}catch(s){n(s)}}):e.method=="eth_sendTransaction"?(e.method="eth_signTransaction",new Promise((i,n)=>{let s=e.params&&e.params.length&&e.params[0];s.gasLimit||(s.gasLimit=5e5),this.provider.request({method:"eth_chainId"}).then(o=>{console.log("eth_chainId ",o);let r=100199;o.result&&(r=parseInt(o.result,16)),s.chainId||(s.chainId=r),s.v=27+s.chainId*2+8,this.provider.request({method:"eth_getTransactionCount",params:[this.account.address]}).then(c=>{console.log("eth_getTransactionCount ",c),s.nonce||(s.nonce=c.result),console.log("before signTransaction param",s),g.signTransaction(new g.Transaction(s),this.account.privateKey).then(a=>{if(console.log("signTransaction ",a),a&&a.rawTransaction&&a.rawTransaction.length){const p={method:"eth_sendRawTransaction",params:[a.rawTransaction],id:this._nextId++,jsonrpc:"2.0"};this.provider.request(p).then(u=>{console.log("eth_sendRawTransaction ",u),i(u)}).catch(u=>{console.log("eth_sendRawTransaction error",u),n(u)})}else n(new Error("signTransaction error"))}).catch(a=>{console.log("signTransaction error",a),n(a)})}).catch(c=>{console.log("eth_getTransactionCount error",c),n(c)})}).catch(o=>{console.log("eth_chainId error",o),n(o)})})):this.provider.request(e)}async send(e,i){console.log("send",e,i);const n={method:e,params:i,id:this._nextId++,jsonrpc:"2.0"};return this.request(n)}}async function _(t=new l){console.log("detectEthereumProvider in");let e=!1;return await new Promise(async(n,s)=>{if(window.ethereum){if(t.force_aon&&!window.ethereum.isAON){let r=await o(t);n(r)}n(window.ethereum)}else{let r=await o(t);n(r)}async function o(r){if(console.log("createProvider in"),e)return;e=!0;const c=new x(r);return await c.loadKeystore(),window.ethereum=c,console.log("createProvider instance",c),c}})}class A{constructor(e=new l){this.options=e}async login(){return(await _(this.options)).request({method:"eth_accounts"})}}const B=1,U=2,L={1:"/api",2:"/jwt"};class N{constructor(e){if(!(e&&e.auth&&e.auth.length))throw new Error("options.auth is not found");this.auth=e.auth,this.options=e,this.init()}init(){let e="/v1";this.options&&this.options.api_version&&this.options.api_version.length&&(e=this.options.api_version),this.auth_type=this.parseAuthType(this.auth),this.path=L[this.auth_type]+e}parseAuthType(e){const i=this.decodeBase64(e);return console.log("parseAuthType",i),i.indexOf("JWT")>-1?U:B}decodeBase64(e){return typeof window<"u"&&typeof window.atob=="function"?window.atob(e):Buffer.from(e,"base64").toString("utf-8")}async prediction(e,i){try{let n="https://api.aonet.ai";this.options&&this.options.host&&this.options.host.length&&(n=this.options.host);const s=n+this.path+e;let o={apikey:this.auth};if(this.auth_type==U&&(o={Authorization:"Bearer "+this.auth}),this.options&&this.options.headers)for(const a in this.options.headers)a!="apikey"&&a!="Authorization"&&(o[a]=this.options.headers[a]);const r=await fetch(s,{method:"POST",headers:o,body:JSON.stringify(i)});return r?await r.json():{task:{is_success:!1,task_error:"network error",exec_code:"5000"}}}catch(n){console.error("Error:",n)}}}return function(t,e){typeof define=="function"&&define.amd?define(["web3","web3-eth-accounts"],e):typeof module=="object"&&module.exports?module.exports=e(require("web3"),require("web3-eth-accounts")):t.aonweb=e(t.Web3,t.Web3EthAccounts)}(typeof self<"u"?self:void 0,function(t,e){return{Options:l,User:A,AI:N,detectEthereumProvider:_}}),d.AI=N,d.Options=l,d.User=A,d.detectEthereumProvider=_,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"}),d}({},Web3,Web3EthAccounts);
(function(p,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("web3"),require("web3-eth-accounts")):typeof define=="function"&&define.amd?define(["exports","web3","web3-eth-accounts"],w):(p=typeof globalThis<"u"?globalThis:p||self,w(p.aonweb={},p.Web3,p.Web3EthAccounts))})(this,function(p,w,g){"use strict";const T={TYPE_TG:1,TYPE_FP:2};let l=class{constructor({rpc_url:e="https://dev.rpc.aonet.ai",type:i=T.TYPE_FP,server:n="https://dev.rpc.aonet.ai",password:s="",storeage_url:o="",timeout:r=3e3,force_aon:c=!0}={}){if(this.rpc_url=e,this.type=i,this.server=n,this.password=s,this.storeage_url=o,this.timeout=r,this.force_aon=c,this.type==T.TYPE_FP&&this.storeage_url=="")throw new Error("storeage_url must be set when type = TYPE_FP")}static get LoginTypes(){return T}};var y;(function(t){t.NUMBER="NUMBER_NUMBER",t.HEX="NUMBER_HEX",t.STR="NUMBER_STR",t.BIGINT="NUMBER_BIGINT"})(y||(y={}));var f;(function(t){t.HEX="BYTES_HEX",t.UINT8ARRAY="BYTES_UINT8ARRAY"})(f||(f={})),y.BIGINT,f.HEX,y.HEX,f.HEX;var I;(function(t){t.EARLIEST="earliest",t.LATEST="latest",t.PENDING="pending",t.SAFE="safe",t.FINALIZED="finalized"})(I||(I={}));var b;(function(t){t.chainstart="chainstart",t.frontier="frontier",t.homestead="homestead",t.dao="dao",t.tangerineWhistle="tangerineWhistle",t.spuriousDragon="spuriousDragon",t.byzantium="byzantium",t.constantinople="constantinople",t.petersburg="petersburg",t.istanbul="istanbul",t.muirGlacier="muirGlacier",t.berlin="berlin",t.london="london",t.altair="altair",t.arrowGlacier="arrowGlacier",t.grayGlacier="grayGlacier",t.bellatrix="bellatrix",t.merge="merge",t.capella="capella",t.shanghai="shanghai"})(b||(b={}));var E=function(t,e,i,n){function s(o){return o instanceof i?o:new i(function(r){r(o)})}return new(i||(i=Promise))(function(o,r){function c(u){try{d(n.next(u))}catch(P){r(P)}}function a(u){try{d(n.throw(u))}catch(P){r(P)}}function d(u){u.done?o(u.value):s(u.value).then(c,a)}d((n=n.apply(t,e||[])).next())})};const S=Symbol.for("web3/base-provider");class _{static isWeb3Provider(e){return e instanceof _||!!(e&&e[S])}get[S](){return!0}send(e,i){this.request(e).then(n=>{i(null,n)}).catch(n=>{i(n)})}sendAsync(e){return E(this,void 0,void 0,function*(){return this.request(e)})}asEIP1193Provider(){const e=Object.create(this),i=e.request;return e.request=function(s){return E(this,void 0,void 0,function*(){return(yield i(s)).result})},e.asEIP1193Provider=void 0,e}}class q{constructor(e=new Options){try{this.options=e}catch(i){throw i}}async setItem(e,i,n){try{let s=localStorage.getItem("fingerprint"),o={key:e+"_"+s,value:i},r=localStorage.getItem("token");r=r.replace(/^\"|\"$/g,"");let c={Authorization:"Bearer "+r},a=this.options.storeage_url+"/kvapi/v1/storage/set";const u=await(await fetch(a,{method:"POST",headers:c,body:JSON.stringify(o)})).json();u&&u.success?n(null):n(new Error(JSON.stringify(u)||""))}catch(s){n(s)}}async getItem(e,i){try{let n=localStorage.getItem("token");n=n.replace(/^\"|\"$/g,"");let s={Authorization:"Bearer "+n},o=localStorage.getItem("fingerprint");e=e+"_"+o;let r=this.options.storeage_url+"/kvapi/v1/storage/get?key="+e;const a=await(await fetch(r,{method:"GET",headers:s})).json();a&&a.success?i(null,a.value):i(new Error(JSON.stringify(a)||""),null)}catch(n){i(n,null)}}}let m;const R=new Uint8Array(16);function x(){if(!m&&(m=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!m))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return m(R)}const h=[];for(let t=0;t<256;++t)h.push((t+256).toString(16).slice(1));function Y(t,e=0){return h[t[e+0]]+h[t[e+1]]+h[t[e+2]]+h[t[e+3]]+"-"+h[t[e+4]]+h[t[e+5]]+"-"+h[t[e+6]]+h[t[e+7]]+"-"+h[t[e+8]]+h[t[e+9]]+"-"+h[t[e+10]]+h[t[e+11]]+h[t[e+12]]+h[t[e+13]]+h[t[e+14]]+h[t[e+15]]}const A={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function G(t,e,i){if(A.randomUUID&&!e&&!t)return A.randomUUID();t=t||{};const n=t.random||(t.rng||x)();return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Y(n)}class W extends _{constructor(e=new l){try{super(),this.options=e,this.isAON=!0,window.Telegram&&window.Telegram.WebApp&&window.Telegram.WebApp.initData&&(e.type=l.LoginTypes.TYPE_TG),e.type==l.LoginTypes.TYPE_TG?(this.webapp=window.Telegram.WebApp,this.storage=window.Telegram.WebApp.CloudStorage):e.type==l.LoginTypes.TYPE_FP&&(this.storage=new q(e)),this.keystore=null,this.account=null,this._nextId=0,this.provider=new w.Web3.providers.HttpProvider(e.rpc_url)}catch(i){throw i}}async _getPassword(){return await new Promise((i,n)=>{this.storage.getItem("aon_web_sdk_password",(s,o)=>{s&&n(s),i(o)})})}async check(e){try{let i={};if(e.type==l.LoginTypes.TYPE_TG)i={platform:"telegram",initData:this.webapp.initData};else if(e.type==l.LoginTypes.TYPE_FP){let r=localStorage.getItem("fingerprint");r||(r=await new Promise((c,a)=>{const d=G();c(d)}),localStorage.setItem("fingerprint",r)),i={platform:"fingerprint",visitorId:r}}let n=e.server+"/api/v1/user/check";const o=await(await fetch(n,{method:"POST",body:JSON.stringify(i)})).json();if(o.code==0&&o.data){const r=o.data.token;return r&&this.setAuth(r),o.data}return o}catch(i){throw i}}async setPassword(e){await new Promise((i,n)=>{this.storage.setItem("aon_web_sdk_password",e,s=>{s&&n(s),i()})})}generateRandomPassword(e){const i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+{}|:<>?-=[];',./";let n="";for(let s=0;s<e;s++){const o=Math.floor(Math.random()*i.length);n+=i[o]}return n}async getAuth(){return this.options.type==l.LoginTypes.TYPE_TG?await new Promise((i,n)=>{this.storage.getItem("token",(s,o)=>{s&&n(s),i(o)})}):localStorage.getItem("token")}async setAuth(e){this.options.type==l.LoginTypes.TYPE_TG?await new Promise((i,n)=>{this.storage.setItem("token",JSON.stringify(e),s=>{s&&n(s),i()})}):localStorage.setItem("token",e)}async createUserToServer(e,i){let n={keystore:JSON.stringify(e),signature:i},s=await this.getAuth();s=s.replace(/^\"|\"$/g,"");let o={Authorization:"Bearer "+s},r=this.options.server+"/api/v1/user/create";return await(await fetch(r,{method:"POST",headers:o,body:JSON.stringify(n)})).json()}async createUser(){let e=this.generateRandomPassword(20),i=g.create(),n=await g.encrypt(i.privateKey,e),o=g.sign(JSON.stringify(n),i.privateKey).signature,r=await this.createUserToServer(n,o);if(r.code==0)return await this.setPassword(e),{keystore:n,account:i};throw new Error(r.error||r.msg)}async loadKeystore(){try{let e=await this.check(this.options);if(e.code)throw new Error(e.msg||e.error);if(e.isNewUser){let n=await this.createUser();this.account=n.account,this.keystore=n.keystore;return}let i=await this._getPassword();this.keystore=JSON.parse(e.keystore),this.account=await g.decrypt(this.keystore,i)}catch(e){console.log("loadKeystore error",e)}}request(e){return console.log("request",e),e.method=="eth_accounts"||e.method=="eth_requestAccounts"?new Promise((i,n)=>{try{if(this.account){i([this.account.address]);return}i([])}catch(s){n(s)}}):e.method=="eth_sendTransaction"?(e.method="eth_signTransaction",new Promise((i,n)=>{let s=e.params&&e.params.length&&e.params[0];s.gasLimit||(s.gasLimit=5e5),this.provider.request({method:"eth_chainId"}).then(o=>{console.log("eth_chainId ",o);let r=100199;o.result&&(r=parseInt(o.result,16)),s.chainId||(s.chainId=r),s.v=27+s.chainId*2+8,this.provider.request({method:"eth_getTransactionCount",params:[this.account.address]}).then(c=>{console.log("eth_getTransactionCount ",c),s.nonce||(s.nonce=c.result),console.log("before signTransaction param",s),g.signTransaction(new g.Transaction(s),this.account.privateKey).then(a=>{if(console.log("signTransaction ",a),a&&a.rawTransaction&&a.rawTransaction.length){const d={method:"eth_sendRawTransaction",params:[a.rawTransaction],id:this._nextId++,jsonrpc:"2.0"};this.provider.request(d).then(u=>{console.log("eth_sendRawTransaction ",u),i(u)}).catch(u=>{console.log("eth_sendRawTransaction error",u),n(u)})}else n(new Error("signTransaction error"))}).catch(a=>{console.log("signTransaction error",a),n(a)})}).catch(c=>{console.log("eth_getTransactionCount error",c),n(c)})}).catch(o=>{console.log("eth_chainId error",o),n(o)})})):this.provider.request(e)}async send(e,i){console.log("send",e,i);const n={method:e,params:i,id:this._nextId++,jsonrpc:"2.0"};return this.request(n)}}async function v(t=new l){console.log("detectEthereumProvider in");let e=!1;return await new Promise(async(n,s)=>{if(window.ethereum){if(t.force_aon&&!window.ethereum.isAON){let r=await o(t);n(r)}n(window.ethereum)}else{let r=await o(t);n(r)}async function o(r){if(console.log("createProvider in"),e)return;e=!0;const c=new W(r);return await c.loadKeystore(),window.ethereum=c,console.log("createProvider instance",c),c}})}class U{constructor(e=new l){this.options=e}async login(){return(await v(this.options)).request({method:"eth_accounts"})}}const B=1,N=2,L={1:"/api",2:"/jwt"};class D{constructor(e){if(!(e&&e.auth&&e.auth.length))throw new Error("options.auth is not found");this.auth=e.auth,this.options=e,this.init()}init(){let e="/v1";this.options&&this.options.api_version&&this.options.api_version.length&&(e=this.options.api_version),this.auth_type=this.parseAuthType(this.auth),this.path=L[this.auth_type]+e}parseAuthType(e){const i=this.decodeBase64(e);return console.log("parseAuthType",i),i.indexOf("JWT")>-1?N:B}decodeBase64(e){return typeof window<"u"&&typeof window.atob=="function"?window.atob(e):Buffer.from(e,"base64").toString("utf-8")}async prediction(e,i){try{let n="https://api.aonet.ai";this.options&&this.options.host&&this.options.host.length&&(n=this.options.host);const s=n+this.path+e;let o={apikey:this.auth};if(this.auth_type==N&&(o={Authorization:"Bearer "+this.auth}),this.options&&this.options.headers)for(const a in this.options.headers)a!="apikey"&&a!="Authorization"&&(o[a]=this.options.headers[a]);const r=await fetch(s,{method:"POST",headers:o,body:JSON.stringify(i)});return r?await r.json():{task:{is_success:!1,task_error:"network error",exec_code:"5000"}}}catch(n){console.error("Error:",n)}}}(function(t,e){typeof define=="function"&&define.amd?define(["web3","web3-eth-accounts"],e):typeof module=="object"&&module.exports?module.exports=e(require("web3"),require("web3-eth-accounts")):t.aonweb=e(t.Web3,t.Web3EthAccounts)})(typeof self<"u"?self:void 0,function(t,e){return{Options:l,User:U,AI:D,detectEthereumProvider:v}}),p.AI=D,p.Options=l,p.User=U,p.detectEthereumProvider=v,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
interface Template {
id: string
image: string
prompt: string
}
// 获取模板
export async function getTemplate() {
const imgOrigin = window.location.origin
const response = await fetch('/templates/template.json');
const resList = await response.json();
if(resList && resList.length > 0){
resList.forEach((item: Template) => {
item.image = `${imgOrigin}/templates/images/${item.image}`
})
}
return resList
}
\ No newline at end of file
...@@ -4,7 +4,11 @@ ...@@ -4,7 +4,11 @@
<div> <div>
<!-- 页面内容 --> <!-- 页面内容 -->
<div class="container"> <div class="container">
<img class="banner" src="../assets/images/banner.png" mode=""></img> <div class="banner">
<img src="../assets/images/banner.png" mode=""></img>
<p>AON 3D Clothing</p>
<p>Customize your clothing logo and generate a 3D avatar</p>
</div>
<div class="uni-form-item uni-column"> <div class="uni-form-item uni-column">
<div class="title">Upload your photos</div> <div class="title">Upload your photos</div>
...@@ -27,10 +31,24 @@ ...@@ -27,10 +31,24 @@
</div> </div>
<div class="uni-form-item uni-column"> <!-- <div class="uni-form-item uni-column">
<div class="title">Customize your clothing logo</div> <div class="title">Customize your clothing logo</div>
<div class="content"> <div class="content">
<input v-model="logoText" name="input" placeholder="Please enter the logo text on your clothes" /> <input v-model="prompt" name="input" placeholder="Please enter the logo text on your clothes" />
</div>
</div> -->
<div class="uni-form-item uni-column">
<div class="title">Choose your template</div>
<div class="templateCon" v-if="templateList.length > 0">
<div v-for="(item, index) in templateList"
:class="`template_item ${Number(item.id) === templateId ? 'templateActive' : ''}`"
@click="selectTemplate(Number(item.id), item.image, item.prompt)" :key="index">
<img :src="item.image" alt="" />
<div :class="`isActiveIcon ${Number(item.id) === templateId ? 'active' : ''}`">
<img src="../assets/icons/selectIcon.png" alt="" v-if="Number(item.id) === templateId">
</div>
</div>
</div> </div>
</div> </div>
...@@ -53,11 +71,12 @@ ...@@ -53,11 +71,12 @@
</template> </template>
<script setup> <script setup>
import { ref } from 'vue'; import { ref, onMounted } from 'vue';
import { showToast } from 'vant'; import { showToast } from 'vant';
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { AI } from 'aonweb' import { AI } from 'aonweb'
import { getTemplate } from '../lib/getTemplate'
import 'vant/lib/index.css'; import 'vant/lib/index.css';
import Header from '../components/Header.vue'; import Header from '../components/Header.vue';
...@@ -67,9 +86,11 @@ const router = useRouter() ...@@ -67,9 +86,11 @@ const router = useRouter()
const showLoading = ref(false); const showLoading = ref(false);
const showError = ref(false); const showError = ref(false);
const logoText = ref(''); const prompt = ref('');
const imgUrl = ref(''); const imgUrl = ref('');
const submitImgUrl = ref(''); const submitImgUrl = ref('');
const templateList = ref([]);
const templateId = ref(1);
const maxSize = 30 * 1024 * 1024; const maxSize = 30 * 1024 * 1024;
function goToComplete(url) { function goToComplete(url) {
...@@ -81,18 +102,15 @@ function goToComplete(url) { ...@@ -81,18 +102,15 @@ function goToComplete(url) {
} }
const onOversize = (file) => { const onOversize = (file) => {
console.log(file);
showToast('文件大小不能超过 30MB'); showToast('文件大小不能超过 30MB');
}; };
function afterRead(file) { function afterRead(file) {
const formData = new FormData(); const formData = new FormData();
formData.append('file', file.file); formData.append('file', file.file);
console.log(formData, file.file)
// 调用上传接口 // 调用上传接口
uploadFile(formData).then(res => { uploadFile(formData).then(res => {
console.log(res);
if (res.code == 200 && res.data && res.data.length) { if (res.code == 200 && res.data && res.data.length) {
submitImgUrl.value = res.data submitImgUrl.value = res.data
} }
...@@ -113,7 +131,6 @@ const uploadFile = async (formData) => { ...@@ -113,7 +131,6 @@ const uploadFile = async (formData) => {
}); });
const data = await response.json(); const data = await response.json();
console.log(data);
return data; return data;
}; };
...@@ -135,7 +152,8 @@ function deleteImg() { ...@@ -135,7 +152,8 @@ function deleteImg() {
const formSubmit = async () => { const formSubmit = async () => {
if (!logoText.value || !imgUrl.value || !submitImgUrl.value) { console.log(prompt.value, submitImgUrl.value)
if (!imgUrl.value || !submitImgUrl.value) {
showError.value = true showError.value = true
setTimeout(() => { setTimeout(() => {
...@@ -158,16 +176,14 @@ const formSubmit = async () => { ...@@ -158,16 +176,14 @@ const formSubmit = async () => {
input: { input: {
"image": submitImgUrl.value, "image": submitImgUrl.value,
"style": "3D", "style": "3D",
"prompt": logoText.value, "prompt": prompt.value,
"negative_prompt": "", "negative_prompt": "",
"prompt_strength": 4.5, "prompt_strength": 4.5,
"denoising_strength": 1, "denoising_strength": 1,
"instant_id_strength": 0.8 "instant_id_strength": 0.8
} }
} }
console.log("formSubmit data", data)
let response = await aonet.prediction("/predictions/ai/face-to-many", data) let response = await aonet.prediction("/predictions/ai/face-to-many", data)
console.log("test", response)
if (response.task.exec_code == 200 && response.task.is_success) { if (response.task.exec_code == 200 && response.task.is_success) {
showLoading.value = false showLoading.value = false
...@@ -191,6 +207,25 @@ const formSubmit = async () => { ...@@ -191,6 +207,25 @@ const formSubmit = async () => {
} }
async function getTemplateList() {
try {
const list = await getTemplate()
templateList.value = list
prompt.value = list[0].prompt
} catch (error) {
console.log(error)
}
}
function selectTemplate(id, imageUrl, prompt_) {
templateId.value = id
prompt.value = prompt_
}
onMounted(() => {
getTemplateList()
})
</script> </script>
<style scoped> <style scoped>
...@@ -198,8 +233,41 @@ const formSubmit = async () => { ...@@ -198,8 +233,41 @@ const formSubmit = async () => {
width: 100%; width: 100%;
height: 27.73vw; height: 27.73vw;
margin-top: 8.53vw; margin-top: 8.53vw;
margin-bottom: 8.53vw; margin-bottom: 8.53vw;
position: relative;
padding: 4.27vw;
}
.banner img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.banner p {
position: relative;
z-index: 10;
font-family: Roboto-Black;
font-weight: 900;
font-size: 6.4vw;
color: #FFFFFF;
text-align: left;
font-style: normal;
text-transform: none;
}
.banner p:last-child {
width: 49.07vw;
font-family: Roboto-Regular;
font-weight: 400;
font-size: 2.4vw;
color: #FFFFFF;
line-height: 4.27vw;
text-align: left;
font-style: normal;
text-transform: none;
} }
.uni-form-item .title { .uni-form-item .title {
...@@ -228,7 +296,12 @@ const formSubmit = async () => { ...@@ -228,7 +296,12 @@ const formSubmit = async () => {
box-sizing: border-box; box-sizing: border-box;
} }
.error-text{
width: 86.67vw;
position: fixed;
bottom: 21.6vw;
}
.error-text .content { .error-text .content {
background-color: #F3A32B; background-color: #F3A32B;
font-size: 3.2vw; font-size: 3.2vw;
...@@ -313,4 +386,59 @@ const formSubmit = async () => { ...@@ -313,4 +386,59 @@ const formSubmit = async () => {
color: transparent; color: transparent;
background-clip: text; background-clip: text;
} }
.templateCon {
display: flex;
flex-direction: row;
justify-content: space-between;
flex-wrap: wrap;
height: auto;
background: transparent;
}
.template_item {
width: 24.8vw;
height: 44vw;
background: #F1F1F1;
border-radius: 1.07vw;
margin-bottom: 4.53vw;
position: relative;
overflow: hidden;
box-sizing: border-box;
}
.template_item img {
width: 100%;
height: 100%;
object-fit: cover;
}
.templateActive {
border: .27vw solid #000;
}
.isActiveIcon {
position: absolute;
bottom: 1.6vw;
right: 1.6vw;
width: 3.2vw;
height: 3.2vw;
background: #FFFFFF;
border: .27vw solid #000000;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
}
.isActiveIcon img{
height: 2.13vw;
width: 2.13vw;
}
.active{
background: #EBCC2F;
}
</style> </style>
{ {
"extends": "@vue/tsconfig/tsconfig.dom.json", "extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"], "include": ["env.d.ts", "src/**/*", "src/**/*.vue", "src/**/*.ts", "src/**/*.json"],
"exclude": ["src/**/__tests__/*"], "exclude": ["src/**/__tests__/*"],
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment