@initia/initia.js 0.2.32 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { RawKey } from './RawKey';
2
- export declare const INIT_COIN_TYPE = 118;
2
+ export declare const INIT_COIN_TYPE = 60;
3
3
  interface MnemonicKeyOptions {
4
4
  mnemonic?: string;
5
5
  account?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@initia/initia.js",
3
- "version": "0.2.32",
3
+ "version": "1.0.1",
4
4
  "description": "The JavaScript SDK for Initia",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Initia Foundation",
@@ -8,12 +8,16 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/initia-labs/initia.js"
10
10
  },
11
- "main": "dist/index.js",
12
- "typings": "dist/index.d.ts",
11
+ "type": "module",
12
+ "main": "dist/index.cjs",
13
+ "module": "dist/index.js",
14
+ "types": "dist/index.d.ts",
13
15
  "exports": {
14
- "import": "./dist/index.es.js",
15
- "require": "./dist/index.cjs.js",
16
- "types": "./dist/index.d.ts"
16
+ ".": {
17
+ "require": "./dist/index.cjs",
18
+ "import": "./dist/index.js",
19
+ "types": "./dist/index.d.ts"
20
+ }
17
21
  },
18
22
  "files": [
19
23
  "dist"
@@ -46,13 +50,13 @@
46
50
  "eslint-plugin-prettier": "^5.1.3",
47
51
  "husky": "^9.0.11",
48
52
  "jest": "^29.1.1",
49
- "lint-staged": "^13.3.0",
53
+ "lint-staged": "^15.4.3",
50
54
  "prettier": "^3.1.1",
51
55
  "ts-jest": "^29.2.5",
52
56
  "ts-node": "^10.9.2",
53
57
  "typescript": "^5.4.5",
54
58
  "typescript-eslint": "^7.13.1",
55
- "vite": "^5.4.8",
59
+ "vite": "^6.2.0",
56
60
  "vite-plugin-dts": "^4.2.3"
57
61
  },
58
62
  "dependencies": {
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("@ledgerhq/hw-transport"),o=require("./index-BY4R60_E.js");var c=function(i,e,t,n){function r(l){return l instanceof t?l:new t(function(d){d(l)})}return new(t||(t=Promise))(function(l,d){function f(s){try{a(n.next(s))}catch(v){d(v)}}function h(s){try{a(n.throw(s))}catch(v){d(v)}}function a(s){s.done?l(s.value):r(s.value).then(f,h)}a((n=n.apply(i,e||[])).next())})};const w=[{vendorId:o.ledgerUSBVendorId}],D=()=>Promise.resolve(!!(window.navigator&&window.navigator.hid)),p=()=>{const{hid:i}=navigator;if(!i)throw new o.TransportError("navigator.hid is not supported","HIDNotSupported");return i};function m(){return c(this,void 0,void 0,function*(){const i=yield p().requestDevice({filters:w});return Array.isArray(i)?i:[i]})}function g(){return c(this,void 0,void 0,function*(){return(yield p().getDevices()).filter(e=>e.vendorId===o.ledgerUSBVendorId)})}function I(){return c(this,void 0,void 0,function*(){const i=yield g();return i.length>0?i[0]:(yield m())[0]})}class u extends y{constructor(e){super(),this.channel=Math.floor(Math.random()*65535),this.packetSize=64,this.inputs=[],this.read=()=>this.inputs.length?Promise.resolve(this.inputs.shift()):new Promise(t=>{this.inputCallback=t}),this.onInputReport=t=>{const n=Buffer.from(t.data.buffer);this.inputCallback?(this.inputCallback(n),this.inputCallback=null):this.inputs.push(n)},this._disconnectEmitted=!1,this._emitDisconnect=t=>{this._disconnectEmitted||(this._disconnectEmitted=!0,this.emit("disconnect",t))},this.exchange=t=>c(this,void 0,void 0,function*(){return yield this.exchangeAtomicImpl(()=>c(this,void 0,void 0,function*(){const{channel:r,packetSize:l}=this;o.log("apdu","=> "+t.toString("hex"));const d=o.createHIDframing(r,l),f=d.makeBlocks(t);for(let s=0;s<f.length;s++)yield this.device.sendReport(0,f[s]);let h,a;for(;!(h=d.getReducedResult(a));){const s=yield this.read();a=d.reduceResponse(a,s)}return o.log("apdu","<= "+h.toString("hex")),h})).catch(r=>{throw r&&r.message&&r.message.includes("write")?(this._emitDisconnect(r),new o.DisconnectedDeviceDuringOperation(r.message)):r})}),this.device=e,this.deviceModel=typeof e.productId=="number"?o.identifyUSBProductId(e.productId):void 0,e.addEventListener("inputreport",this.onInputReport)}static request(){return c(this,void 0,void 0,function*(){const[e]=yield m();return u.open(e)})}static openConnected(){return c(this,void 0,void 0,function*(){const e=yield g();return e.length===0?null:u.open(e[0])})}static open(e){return c(this,void 0,void 0,function*(){yield e.open();const t=new u(e),n=r=>{e===r.device&&(p().removeEventListener("disconnect",n),t._emitDisconnect(new o.DisconnectedDevice))};return p().addEventListener("disconnect",n),t})}close(){return c(this,void 0,void 0,function*(){yield this.exchangeBusyPromise,this.device.removeEventListener("inputreport",this.onInputReport),yield this.device.close()})}setScrambleKey(){}}u.isSupported=D;u.list=g;u.listen=i=>{let e=!1;I().then(n=>{if(!n)i.error(new o.TransportOpenUserCancelled("Access denied to use Ledger device"));else if(!e){const r=typeof n.productId=="number"?o.identifyUSBProductId(n.productId):void 0;i.next({type:"add",descriptor:n,deviceModel:r}),i.complete()}},n=>{i.error(new o.TransportOpenUserCancelled(n.message))});function t(){e=!0}return{unsubscribe:t}};exports.default=u;
@@ -1,154 +0,0 @@
1
- import b from "@ledgerhq/hw-transport";
2
- import { l as m, D as I, i as y, T as g, a as x, b as w, c as S, d as k } from "./index-BNBWMUWc.mjs";
3
- var r = function(i, e, t, n) {
4
- function s(d) {
5
- return d instanceof t ? d : new t(function(c) {
6
- c(d);
7
- });
8
- }
9
- return new (t || (t = Promise))(function(d, c) {
10
- function h(o) {
11
- try {
12
- u(n.next(o));
13
- } catch (p) {
14
- c(p);
15
- }
16
- }
17
- function l(o) {
18
- try {
19
- u(n.throw(o));
20
- } catch (p) {
21
- c(p);
22
- }
23
- }
24
- function u(o) {
25
- o.done ? d(o.value) : s(o.value).then(h, l);
26
- }
27
- u((n = n.apply(i, e || [])).next());
28
- });
29
- };
30
- const E = [
31
- {
32
- vendorId: w
33
- }
34
- ], L = () => Promise.resolve(!!(window.navigator && window.navigator.hid)), f = () => {
35
- const { hid: i } = navigator;
36
- if (!i)
37
- throw new x("navigator.hid is not supported", "HIDNotSupported");
38
- return i;
39
- };
40
- function D() {
41
- return r(this, void 0, void 0, function* () {
42
- const i = yield f().requestDevice({
43
- filters: E
44
- });
45
- return Array.isArray(i) ? i : [i];
46
- });
47
- }
48
- function v() {
49
- return r(this, void 0, void 0, function* () {
50
- return (yield f().getDevices()).filter((e) => e.vendorId === w);
51
- });
52
- }
53
- function R() {
54
- return r(this, void 0, void 0, function* () {
55
- const i = yield v();
56
- return i.length > 0 ? i[0] : (yield D())[0];
57
- });
58
- }
59
- class a extends b {
60
- constructor(e) {
61
- super(), this.channel = Math.floor(Math.random() * 65535), this.packetSize = 64, this.inputs = [], this.read = () => this.inputs.length ? Promise.resolve(this.inputs.shift()) : new Promise((t) => {
62
- this.inputCallback = t;
63
- }), this.onInputReport = (t) => {
64
- const n = Buffer.from(t.data.buffer);
65
- this.inputCallback ? (this.inputCallback(n), this.inputCallback = null) : this.inputs.push(n);
66
- }, this._disconnectEmitted = !1, this._emitDisconnect = (t) => {
67
- this._disconnectEmitted || (this._disconnectEmitted = !0, this.emit("disconnect", t));
68
- }, this.exchange = (t) => r(this, void 0, void 0, function* () {
69
- return yield this.exchangeAtomicImpl(() => r(this, void 0, void 0, function* () {
70
- const { channel: s, packetSize: d } = this;
71
- m("apdu", "=> " + t.toString("hex"));
72
- const c = S(s, d), h = c.makeBlocks(t);
73
- for (let o = 0; o < h.length; o++)
74
- yield this.device.sendReport(0, h[o]);
75
- let l, u;
76
- for (; !(l = c.getReducedResult(u)); ) {
77
- const o = yield this.read();
78
- u = c.reduceResponse(u, o);
79
- }
80
- return m("apdu", "<= " + l.toString("hex")), l;
81
- })).catch((s) => {
82
- throw s && s.message && s.message.includes("write") ? (this._emitDisconnect(s), new I(s.message)) : s;
83
- });
84
- }), this.device = e, this.deviceModel = typeof e.productId == "number" ? y(e.productId) : void 0, e.addEventListener("inputreport", this.onInputReport);
85
- }
86
- /**
87
- * Similar to create() except it will always display the device permission (even if some devices are already accepted).
88
- */
89
- static request() {
90
- return r(this, void 0, void 0, function* () {
91
- const [e] = yield D();
92
- return a.open(e);
93
- });
94
- }
95
- /**
96
- * Similar to create() except it will never display the device permission (it returns a Promise<?Transport>, null if it fails to find a device).
97
- */
98
- static openConnected() {
99
- return r(this, void 0, void 0, function* () {
100
- const e = yield v();
101
- return e.length === 0 ? null : a.open(e[0]);
102
- });
103
- }
104
- /**
105
- * Create a Ledger transport with a HIDDevice
106
- */
107
- static open(e) {
108
- return r(this, void 0, void 0, function* () {
109
- yield e.open();
110
- const t = new a(e), n = (s) => {
111
- e === s.device && (f().removeEventListener("disconnect", n), t._emitDisconnect(new k()));
112
- };
113
- return f().addEventListener("disconnect", n), t;
114
- });
115
- }
116
- /**
117
- * Release the transport device
118
- */
119
- close() {
120
- return r(this, void 0, void 0, function* () {
121
- yield this.exchangeBusyPromise, this.device.removeEventListener("inputreport", this.onInputReport), yield this.device.close();
122
- });
123
- }
124
- setScrambleKey() {
125
- }
126
- }
127
- a.isSupported = L;
128
- a.list = v;
129
- a.listen = (i) => {
130
- let e = !1;
131
- R().then((n) => {
132
- if (!n)
133
- i.error(new g("Access denied to use Ledger device"));
134
- else if (!e) {
135
- const s = typeof n.productId == "number" ? y(n.productId) : void 0;
136
- i.next({
137
- type: "add",
138
- descriptor: n,
139
- deviceModel: s
140
- }), i.complete();
141
- }
142
- }, (n) => {
143
- i.error(new g(n.message));
144
- });
145
- function t() {
146
- e = !0;
147
- }
148
- return {
149
- unsubscribe: t
150
- };
151
- };
152
- export {
153
- a as default
154
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@ledgerhq/hw-transport"),d=require("./index-BY4R60_E.js");var p=function(r,e,o,t){function u(n){return n instanceof o?n:new o(function(i){i(n)})}return new(o||(o=Promise))(function(n,i){function a(c){try{s(t.next(c))}catch(h){i(h)}}function l(c){try{s(t.throw(c))}catch(h){i(h)}}function s(c){c.done?n(c.value):u(c.value).then(a,l)}s((t=t.apply(r,e||[])).next())})};const D=[{vendorId:d.ledgerUSBVendorId}];function w(){return p(this,void 0,void 0,function*(){return yield navigator.usb.requestDevice({filters:D})})}function g(){return p(this,void 0,void 0,function*(){return(yield navigator.usb.getDevices()).filter(e=>e.vendorId===d.ledgerUSBVendorId)})}function x(){return p(this,void 0,void 0,function*(){const r=yield g();return r.length>0?r[0]:w()})}const I=()=>Promise.resolve(!!navigator&&!!navigator.usb&&typeof navigator.usb.getDevices=="function");var v=function(r,e,o,t){function u(n){return n instanceof o?n:new o(function(i){i(n)})}return new(o||(o=Promise))(function(n,i){function a(c){try{s(t.next(c))}catch(h){i(h)}}function l(c){try{s(t.throw(c))}catch(h){i(h)}}function s(c){c.done?n(c.value):u(c.value).then(a,l)}s((t=t.apply(r,e||[])).next())})};const S=1,m=3;class f extends b{constructor(e,o){super(),this.channel=Math.floor(Math.random()*65535),this.packetSize=64,this._disconnectEmitted=!1,this._emitDisconnect=t=>{this._disconnectEmitted||(this._disconnectEmitted=!0,this.emit("disconnect",t))},this.device=e,this.interfaceNumber=o,this.deviceModel=d.identifyUSBProductId(e.productId)}static request(){return v(this,void 0,void 0,function*(){const e=yield w();return f.open(e)})}static openConnected(){return v(this,void 0,void 0,function*(){const e=yield g();return e.length===0?null:f.open(e[0])})}static open(e){return v(this,void 0,void 0,function*(){yield e.open(),e.configuration===null&&(yield e.selectConfiguration(S)),yield y(e);const o=e.configurations[0].interfaces.find(({alternates:i})=>i.some(a=>a.interfaceClass===255));if(!o)throw new d.TransportInterfaceNotAvailable("No WebUSB interface found for your Ledger device. Please upgrade firmware or contact techsupport.");const t=o.interfaceNumber;try{yield e.claimInterface(t)}catch(i){throw yield e.close(),new d.TransportInterfaceNotAvailable(i.message)}const u=new f(e,t),n=i=>{e===i.device&&(navigator.usb.removeEventListener("disconnect",n),u._emitDisconnect(new d.DisconnectedDevice))};return navigator.usb.addEventListener("disconnect",n),u})}close(){return v(this,void 0,void 0,function*(){yield this.exchangeBusyPromise,yield this.device.releaseInterface(this.interfaceNumber),yield y(this.device),yield this.device.close()})}exchange(e){return v(this,void 0,void 0,function*(){return yield this.exchangeAtomicImpl(()=>v(this,void 0,void 0,function*(){const{channel:t,packetSize:u}=this;d.log("apdu","=> "+e.toString("hex"));const n=d.createHIDframing(t,u),i=n.makeBlocks(e);for(let s=0;s<i.length;s++)yield this.device.transferOut(m,i[s]);let a,l;for(;!(a=n.getReducedResult(l));){const s=yield this.device.transferIn(m,u),c=Buffer.from(s.data.buffer);l=n.reduceResponse(l,c)}return d.log("apdu","<= "+a.toString("hex")),a})).catch(t=>{throw t&&t.message&&t.message.includes("disconnected")?(this._emitDisconnect(t),new d.DisconnectedDeviceDuringOperation(t.message)):t})})}setScrambleKey(){}}f.isSupported=I;f.list=g;f.listen=r=>{let e=!1;x().then(t=>{if(!e){const u=d.identifyUSBProductId(t.productId);r.next({type:"add",descriptor:t,deviceModel:u}),r.complete()}},t=>{window.DOMException&&t instanceof window.DOMException&&t.code===18?r.error(new d.TransportWebUSBGestureRequired(t.message)):r.error(new d.TransportOpenUserCancelled(t.message))});function o(){e=!0}return{unsubscribe:o}};function y(r){return v(this,void 0,void 0,function*(){try{yield r.reset()}catch(e){console.warn(e)}})}exports.default=f;
@@ -1,196 +0,0 @@
1
- import I from "@ledgerhq/hw-transport";
2
- import { b as D, i as b, e as m, l as g, D as _, f as S, T as E, d as N, c as L } from "./index-BNBWMUWc.mjs";
3
- var v = function(s, e, c, t) {
4
- function d(n) {
5
- return n instanceof c ? n : new c(function(i) {
6
- i(n);
7
- });
8
- }
9
- return new (c || (c = Promise))(function(n, i) {
10
- function u(o) {
11
- try {
12
- r(t.next(o));
13
- } catch (f) {
14
- i(f);
15
- }
16
- }
17
- function a(o) {
18
- try {
19
- r(t.throw(o));
20
- } catch (f) {
21
- i(f);
22
- }
23
- }
24
- function r(o) {
25
- o.done ? n(o.value) : d(o.value).then(u, a);
26
- }
27
- r((t = t.apply(s, e || [])).next());
28
- });
29
- };
30
- const M = [
31
- {
32
- vendorId: D
33
- }
34
- ];
35
- function x() {
36
- return v(this, void 0, void 0, function* () {
37
- return yield navigator.usb.requestDevice({
38
- filters: M
39
- });
40
- });
41
- }
42
- function p() {
43
- return v(this, void 0, void 0, function* () {
44
- return (yield navigator.usb.getDevices()).filter((e) => e.vendorId === D);
45
- });
46
- }
47
- function k() {
48
- return v(this, void 0, void 0, function* () {
49
- const s = yield p();
50
- return s.length > 0 ? s[0] : x();
51
- });
52
- }
53
- const B = () => Promise.resolve(!!navigator && !!navigator.usb && typeof navigator.usb.getDevices == "function");
54
- var l = function(s, e, c, t) {
55
- function d(n) {
56
- return n instanceof c ? n : new c(function(i) {
57
- i(n);
58
- });
59
- }
60
- return new (c || (c = Promise))(function(n, i) {
61
- function u(o) {
62
- try {
63
- r(t.next(o));
64
- } catch (f) {
65
- i(f);
66
- }
67
- }
68
- function a(o) {
69
- try {
70
- r(t.throw(o));
71
- } catch (f) {
72
- i(f);
73
- }
74
- }
75
- function r(o) {
76
- o.done ? n(o.value) : d(o.value).then(u, a);
77
- }
78
- r((t = t.apply(s, e || [])).next());
79
- });
80
- };
81
- const O = 1, y = 3;
82
- class h extends I {
83
- constructor(e, c) {
84
- super(), this.channel = Math.floor(Math.random() * 65535), this.packetSize = 64, this._disconnectEmitted = !1, this._emitDisconnect = (t) => {
85
- this._disconnectEmitted || (this._disconnectEmitted = !0, this.emit("disconnect", t));
86
- }, this.device = e, this.interfaceNumber = c, this.deviceModel = b(e.productId);
87
- }
88
- /**
89
- * Similar to create() except it will always display the device permission (even if some devices are already accepted).
90
- */
91
- static request() {
92
- return l(this, void 0, void 0, function* () {
93
- const e = yield x();
94
- return h.open(e);
95
- });
96
- }
97
- /**
98
- * Similar to create() except it will never display the device permission (it returns a Promise<?Transport>, null if it fails to find a device).
99
- */
100
- static openConnected() {
101
- return l(this, void 0, void 0, function* () {
102
- const e = yield p();
103
- return e.length === 0 ? null : h.open(e[0]);
104
- });
105
- }
106
- /**
107
- * Create a Ledger transport with a USBDevice
108
- */
109
- static open(e) {
110
- return l(this, void 0, void 0, function* () {
111
- yield e.open(), e.configuration === null && (yield e.selectConfiguration(O)), yield w(e);
112
- const c = e.configurations[0].interfaces.find(({ alternates: i }) => i.some((u) => u.interfaceClass === 255));
113
- if (!c)
114
- throw new m("No WebUSB interface found for your Ledger device. Please upgrade firmware or contact techsupport.");
115
- const t = c.interfaceNumber;
116
- try {
117
- yield e.claimInterface(t);
118
- } catch (i) {
119
- throw yield e.close(), new m(i.message);
120
- }
121
- const d = new h(e, t), n = (i) => {
122
- e === i.device && (navigator.usb.removeEventListener("disconnect", n), d._emitDisconnect(new N()));
123
- };
124
- return navigator.usb.addEventListener("disconnect", n), d;
125
- });
126
- }
127
- /**
128
- * Release the transport device
129
- */
130
- close() {
131
- return l(this, void 0, void 0, function* () {
132
- yield this.exchangeBusyPromise, yield this.device.releaseInterface(this.interfaceNumber), yield w(this.device), yield this.device.close();
133
- });
134
- }
135
- /**
136
- * Exchange with the device using APDU protocol.
137
- * @param apdu
138
- * @returns a promise of apdu response
139
- */
140
- exchange(e) {
141
- return l(this, void 0, void 0, function* () {
142
- return yield this.exchangeAtomicImpl(() => l(this, void 0, void 0, function* () {
143
- const { channel: t, packetSize: d } = this;
144
- g("apdu", "=> " + e.toString("hex"));
145
- const n = L(t, d), i = n.makeBlocks(e);
146
- for (let r = 0; r < i.length; r++)
147
- yield this.device.transferOut(y, i[r]);
148
- let u, a;
149
- for (; !(u = n.getReducedResult(a)); ) {
150
- const r = yield this.device.transferIn(y, d), o = Buffer.from(r.data.buffer);
151
- a = n.reduceResponse(a, o);
152
- }
153
- return g("apdu", "<= " + u.toString("hex")), u;
154
- })).catch((t) => {
155
- throw t && t.message && t.message.includes("disconnected") ? (this._emitDisconnect(t), new _(t.message)) : t;
156
- });
157
- });
158
- }
159
- setScrambleKey() {
160
- }
161
- }
162
- h.isSupported = B;
163
- h.list = p;
164
- h.listen = (s) => {
165
- let e = !1;
166
- k().then((t) => {
167
- if (!e) {
168
- const d = b(t.productId);
169
- s.next({
170
- type: "add",
171
- descriptor: t,
172
- deviceModel: d
173
- }), s.complete();
174
- }
175
- }, (t) => {
176
- window.DOMException && t instanceof window.DOMException && t.code === 18 ? s.error(new S(t.message)) : s.error(new E(t.message));
177
- });
178
- function c() {
179
- e = !0;
180
- }
181
- return {
182
- unsubscribe: c
183
- };
184
- };
185
- function w(s) {
186
- return l(this, void 0, void 0, function* () {
187
- try {
188
- yield s.reset();
189
- } catch (e) {
190
- console.warn(e);
191
- }
192
- });
193
- }
194
- export {
195
- h as default
196
- };