warthog-ts 0.1.21
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.
- package/LICENSE +21 -0
- package/README.md +300 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/src/tests/account.test.d.ts +2 -0
- package/dist/src/tests/account.test.d.ts.map +1 -0
- package/dist/src/tests/account.test.js +32 -0
- package/dist/src/tests/account.test.js.map +1 -0
- package/dist/src/tests/funds.test.d.ts +2 -0
- package/dist/src/tests/funds.test.d.ts.map +1 -0
- package/dist/src/tests/funds.test.js +161 -0
- package/dist/src/tests/funds.test.js.map +1 -0
- package/dist/src/tests/hdwallet.test.d.ts +2 -0
- package/dist/src/tests/hdwallet.test.d.ts.map +1 -0
- package/dist/src/tests/hdwallet.test.js +26 -0
- package/dist/src/tests/hdwallet.test.js.map +1 -0
- package/dist/src/tests/price.test.d.ts +2 -0
- package/dist/src/tests/price.test.d.ts.map +1 -0
- package/dist/src/tests/price.test.js +40 -0
- package/dist/src/tests/price.test.js.map +1 -0
- package/dist/src/types/Account.d.ts +44 -0
- package/dist/src/types/Account.d.ts.map +1 -0
- package/dist/src/types/Account.js +74 -0
- package/dist/src/types/Account.js.map +1 -0
- package/dist/src/types/Address.d.ts +24 -0
- package/dist/src/types/Address.d.ts.map +1 -0
- package/dist/src/types/Address.js +56 -0
- package/dist/src/types/Address.js.map +1 -0
- package/dist/src/types/Api.d.ts +90 -0
- package/dist/src/types/Api.d.ts.map +1 -0
- package/dist/src/types/Api.js +99 -0
- package/dist/src/types/Api.js.map +1 -0
- package/dist/src/types/Funds.d.ts +175 -0
- package/dist/src/types/Funds.d.ts.map +1 -0
- package/dist/src/types/Funds.js +329 -0
- package/dist/src/types/Funds.js.map +1 -0
- package/dist/src/types/HDWallet.d.ts +29 -0
- package/dist/src/types/HDWallet.d.ts.map +1 -0
- package/dist/src/types/HDWallet.js +40 -0
- package/dist/src/types/HDWallet.js.map +1 -0
- package/dist/src/types/NonceId.d.ts +26 -0
- package/dist/src/types/NonceId.d.ts.map +1 -0
- package/dist/src/types/NonceId.js +37 -0
- package/dist/src/types/NonceId.js.map +1 -0
- package/dist/src/types/Price.d.ts +93 -0
- package/dist/src/types/Price.d.ts.map +1 -0
- package/dist/src/types/Price.js +170 -0
- package/dist/src/types/Price.js.map +1 -0
- package/dist/src/types/TransactionContext.d.ts +135 -0
- package/dist/src/types/TransactionContext.d.ts.map +1 -0
- package/dist/src/types/TransactionContext.js +314 -0
- package/dist/src/types/TransactionContext.js.map +1 -0
- package/dist/src/util/frexp.d.ts +2 -0
- package/dist/src/util/frexp.d.ts.map +1 -0
- package/dist/src/util/frexp.js +68 -0
- package/dist/src/util/frexp.js.map +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// This is from https://raw.githubusercontent.com/locutusjs/locutus/refs/heads/main/src/c/math/frexp.ts, MIT LICENSE
|
|
2
|
+
export function frexp(arg) {
|
|
3
|
+
// discuss at: https://locutus.io/c/frexp/
|
|
4
|
+
// original by: Oskar Larsson Högfeldt (https://oskar-lh.name/)
|
|
5
|
+
// note 1: Instead of
|
|
6
|
+
// note 1: double frexp( double arg, int* exp );
|
|
7
|
+
// note 1: this is built as
|
|
8
|
+
// note 1: [double, int] frexp( double arg );
|
|
9
|
+
// note 1: due to the lack of pointers in JavaScript.
|
|
10
|
+
// note 1: See code comments for further information.
|
|
11
|
+
// example 1: frexp(1)
|
|
12
|
+
// returns 1: [0.5, 1]
|
|
13
|
+
// example 2: frexp(1.5)
|
|
14
|
+
// returns 2: [0.75, 1]
|
|
15
|
+
// example 3: frexp(3 * Math.pow(2, 500))
|
|
16
|
+
// returns 3: [0.75, 502]
|
|
17
|
+
// example 4: frexp(-4)
|
|
18
|
+
// returns 4: [-0.5, 3]
|
|
19
|
+
// example 5: frexp(Number.MAX_VALUE)
|
|
20
|
+
// returns 5: [0.9999999999999999, 1024]
|
|
21
|
+
// example 6: frexp(Number.MIN_VALUE)
|
|
22
|
+
// returns 6: [0.5, -1073]
|
|
23
|
+
// example 7: frexp(-Infinity)
|
|
24
|
+
// returns 7: [-Infinity, 0]
|
|
25
|
+
// example 8: frexp(-0)
|
|
26
|
+
// returns 8: [-0, 0]
|
|
27
|
+
// example 9: frexp(NaN)
|
|
28
|
+
// returns 9: [NaN, 0]
|
|
29
|
+
// Potential issue with this implementation:
|
|
30
|
+
// the precisions of Math.pow and the ** operator are undefined in the ECMAScript standard,
|
|
31
|
+
// however, sane implementations should give the same results for Math.pow(2, <integer>) operations
|
|
32
|
+
// Like frexp of C and std::frexp of C++,
|
|
33
|
+
// but returns an array instead of using a pointer argument for passing the exponent result.
|
|
34
|
+
// Object.is(n, frexp(n)[0] * 2 ** frexp(n)[1]) for all number values of n except when Math.isFinite(n) && Math.abs(n) > 2**1023
|
|
35
|
+
// Object.is(n, (2 * frexp(n)[0]) * 2 ** (frexp(n)[1] - 1)) for all number values of n
|
|
36
|
+
// Object.is(n, frexp(n)[0]) for these values of n: 0, -0, NaN, Infinity, -Infinity
|
|
37
|
+
// Math.abs(frexp(n)[0]) is >= 0.5 and < 1.0 for any other number-type value of n
|
|
38
|
+
// See https://en.cppreference.com/w/c/numeric/math/frexp for a more detailed description
|
|
39
|
+
arg = Number(arg);
|
|
40
|
+
const result = [arg, 0];
|
|
41
|
+
if (arg !== 0 && Number.isFinite(arg)) {
|
|
42
|
+
const absArg = Math.abs(arg);
|
|
43
|
+
// Math.log2 was introduced in ES2015, use it when available
|
|
44
|
+
const log2 = Math.log2 ||
|
|
45
|
+
function log2(n) {
|
|
46
|
+
return Math.log(n) * Math.LOG2E;
|
|
47
|
+
};
|
|
48
|
+
let exp = Math.max(-1023, Math.floor(log2(absArg)) + 1);
|
|
49
|
+
let x = absArg * Math.pow(2, -exp);
|
|
50
|
+
// These while loops compensate for rounding errors that sometimes occur because of ECMAScript's Math.log2's undefined precision
|
|
51
|
+
// and also works around the issue of Math.pow(2, -exp) === Infinity when exp <= -1024
|
|
52
|
+
while (x < 0.5) {
|
|
53
|
+
x *= 2;
|
|
54
|
+
exp--;
|
|
55
|
+
}
|
|
56
|
+
while (x >= 1) {
|
|
57
|
+
x *= 0.5;
|
|
58
|
+
exp++;
|
|
59
|
+
}
|
|
60
|
+
if (arg < 0) {
|
|
61
|
+
x = -x;
|
|
62
|
+
}
|
|
63
|
+
result[0] = x;
|
|
64
|
+
result[1] = exp;
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=frexp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frexp.js","sourceRoot":"","sources":["../../../src/util/frexp.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,2CAA2C;IAC3C,+DAA+D;IAC/D,0BAA0B;IAC1B,qDAAqD;IACrD,gCAAgC;IAChC,kDAAkD;IAClD,0DAA0D;IAC1D,0DAA0D;IAC1D,wBAAwB;IACxB,wBAAwB;IACxB,0BAA0B;IAC1B,yBAAyB;IACzB,2CAA2C;IAC3C,2BAA2B;IAC3B,yBAAyB;IACzB,yBAAyB;IACzB,uCAAuC;IACvC,0CAA0C;IAC1C,uCAAuC;IACvC,4BAA4B;IAC5B,gCAAgC;IAChC,8BAA8B;IAC9B,yBAAyB;IACzB,uBAAuB;IACvB,0BAA0B;IAC1B,wBAAwB;IAExB,4CAA4C;IAC5C,2FAA2F;IAC3F,mGAAmG;IAEnG,yCAAyC;IACzC,4FAA4F;IAC5F,gIAAgI;IAChI,sFAAsF;IACtF,mFAAmF;IACnF,iFAAiF;IACjF,yFAAyF;IAEzF,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;IAEjB,MAAM,MAAM,GAAqB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;IAEzC,IAAI,GAAG,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC5B,4DAA4D;QAC5D,MAAM,IAAI,GACR,IAAI,CAAC,IAAI;YACT,SAAS,IAAI,CAAC,CAAC;gBACb,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;YACjC,CAAC,CAAA;QACH,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QACvD,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;QAElC,gIAAgI;QAChI,sFAAsF;QACtF,OAAO,CAAC,GAAG,GAAG,EAAE,CAAC;YACf,CAAC,IAAI,CAAC,CAAA;YACN,GAAG,EAAE,CAAA;QACP,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACd,CAAC,IAAI,GAAG,CAAA;YACR,GAAG,EAAE,CAAA;QACP,CAAC;QAED,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;YACZ,CAAC,GAAG,CAAC,CAAC,CAAA;QACR,CAAC;QACD,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;QACb,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;IACjB,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "warthog-ts",
|
|
3
|
+
"repository": "github:warthog-network/warthog-ts",
|
|
4
|
+
"version": "0.1.21",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "a TypeScript library for the Warthog cryptocurrency",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -p tsconfig.build.json",
|
|
23
|
+
"clean": "rimraf ./dist",
|
|
24
|
+
"prepare": "tsc -p tsconfig.build.json",
|
|
25
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/bun": "latest",
|
|
29
|
+
"@types/elliptic": "^6.4.18",
|
|
30
|
+
"ethers": "^6.16.0",
|
|
31
|
+
"rimraf": "^6.0.0",
|
|
32
|
+
"typescript": "^5"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"ethers": "^6.0.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"elliptic": "^6.6.1"
|
|
39
|
+
}
|
|
40
|
+
}
|