import{a as u,c as T,e as S,l as v}from"./chunk-CVKDPNYM.js";var N=T((P,B)=>{var a=u(function(i){if(!Array.isArray(i))throw new Error("Input must be an Array");if(i.length===0)throw new Error("Path must contain at least one level");for(var t=0;t<i.length;t++)if(typeof i[t]!="number")throw new Error("Path element is not a number");this.path=i},"BIPPath");a.validatePathArray=function(i){try{return a.fromPathArray(i),!0}catch{return!1}};a.validateString=function(i,t){try{return a.fromString(i,t),!0}catch{return!1}};a.fromPathArray=function(i){return new a(i)};a.fromString=function(i,t){if(/^m\//i.test(i))i=i.slice(2);else if(t)throw new Error("Root element is required");for(var r=i.split("/"),n=new Array(r.length),e=0;e<r.length;e++){var o=/(\d+)([hH\']?)/.exec(r[e]);if(o===null)throw new Error("Invalid input");if(n[e]=parseInt(o[1],10),n[e]>=2147483648)throw new Error("Invalid child index");if(o[2]==="h"||o[2]==="H"||o[2]==="'")n[e]+=2147483648;else if(o[2].length!=0)throw new Error("Invalid modifier")}return new a(n)};a.prototype.toPathArray=function(){return this.path};a.prototype.toString=function(i,t){for(var r=new Array(this.path.length),n=0;n<this.path.length;n++){var e=this.path[n];e&2147483648?r[n]=(e&2147483647)+(t?"h":"'"):r[n]=e}return(i?"":"m/")+r.join("/")};a.prototype.inspect=function(){return"BIPPath <"+this.toString()+">"};B.exports=a});var y=S(N());var l=function(i,t,r,n){function e(o){return o instanceof r?o:new r(function(s){s(o)})}return u(e,"adopt"),new(r||(r=Promise))(function(o,s){function g(f){try{c(n.next(f))}catch(I){s(I)}}u(g,"fulfilled");function h(f){try{c(n.throw(f))}catch(I){s(I)}}u(h,"rejected");function c(f){f.done?o(f.value):e(f.value).then(g,h)}u(c,"step"),c((n=n.apply(i,t||[])).next())})},D=0,w=1,m=1,O=2,d=255,_=224,E={GET_VERSION:4,GET_ADDR:5,SIGN:6,SIGN_OFFCHAIN:7},p;(function(i){i[i.BLIND_SIGNATURE_REQUIRED=26632]="BLIND_SIGNATURE_REQUIRED"})(p||(p={}));var A=class{static{u(this,"Solana")}constructor(t,r="solana_default_scramble_key"){this.transport=t,this.transport.decorateAppAPIMethods(this,["getAddress","signTransaction","getAppConfiguration"],r)}getAddress(t,r=!1){return l(this,void 0,void 0,function*(){let n=this.pathToBuffer(t);return{address:yield this.sendToDevice(E.GET_ADDR,r?w:D,n)}})}signTransaction(t,r){return l(this,void 0,void 0,function*(){let n=this.pathToBuffer(t),e=Buffer.alloc(1);e.writeUInt8(1,0);let o=Buffer.concat([e,n,r]);return{signature:yield this.sendToDevice(E.SIGN,w,o)}})}signOffchainMessage(t,r){return l(this,void 0,void 0,function*(){let n=this.pathToBuffer(t),e=Buffer.alloc(1);e.writeUInt8(1,0);let o=Buffer.concat([e,n,r]);return{signature:yield this.sendToDevice(E.SIGN_OFFCHAIN,w,o)}})}getAppConfiguration(){return l(this,void 0,void 0,function*(){let[t,r,n,e,o]=yield this.sendToDevice(E.GET_VERSION,D,Buffer.alloc(0));return{blindSigningEnabled:!!t,pubKeyDisplayMode:r,version:`${n}.${e}.${o}`}})}pathToBuffer(t){let r=t.split("/").map(e=>e.endsWith("'")||e.endsWith("h")?e:e+"'").join("/"),n=y.default.fromString(r).toPathArray();return this.serializePath(n)}serializePath(t){let r=Buffer.alloc(1+t.length*4);r.writeUInt8(t.length,0);for(let[n,e]of t.entries())r.writeUInt32BE(e,1+n*4);return r}sendToDevice(t,r,n){return l(this,void 0,void 0,function*(){let e=[v.OK,p.BLIND_SIGNATURE_REQUIRED],o=0,s=0;if(n.length>d)for(;n.length-s>d;){let c=n.slice(s,s+d);s+=d;let f=yield this.transport.send(_,t,r,o|O,c,e);this.throwOnFailure(f),o|=m}let g=n.slice(s),h=yield this.transport.send(_,t,r,o,g,e);return this.throwOnFailure(h),h.slice(0,h.length-2)})}throwOnFailure(t){switch(t.readUInt16BE(t.length-2)){case p.BLIND_SIGNATURE_REQUIRED:throw new Error("Missing a parameter. Try enabling blind signature in the app");default:return}}},R;(function(i){i[i.LONG=0]="LONG",i[i.SHORT=1]="SHORT"})(R||(R={}));export{A as default};
//# sourceMappingURL=Solana-UB4SGWQ3.js.map
