@xyo-network/crypto-nft-witness-wallet-plugin 2.70.0

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.
Files changed (46) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/cjs/Plugin.js +16 -0
  4. package/dist/cjs/Plugin.js.map +1 -0
  5. package/dist/cjs/Witness.js +34 -0
  6. package/dist/cjs/Witness.js.map +1 -0
  7. package/dist/cjs/index.js +11 -0
  8. package/dist/cjs/index.js.map +1 -0
  9. package/dist/cjs/lib/getExternalProviderFromHttpProvider.js +23 -0
  10. package/dist/cjs/lib/getExternalProviderFromHttpProvider.js.map +1 -0
  11. package/dist/cjs/lib/getNftsOwnedByAddress.js +56 -0
  12. package/dist/cjs/lib/getNftsOwnedByAddress.js.map +1 -0
  13. package/dist/cjs/lib/index.js +6 -0
  14. package/dist/cjs/lib/index.js.map +1 -0
  15. package/dist/esm/Plugin.js +11 -0
  16. package/dist/esm/Plugin.js.map +1 -0
  17. package/dist/esm/Witness.js +26 -0
  18. package/dist/esm/Witness.js.map +1 -0
  19. package/dist/esm/index.js +7 -0
  20. package/dist/esm/index.js.map +1 -0
  21. package/dist/esm/lib/getExternalProviderFromHttpProvider.js +19 -0
  22. package/dist/esm/lib/getExternalProviderFromHttpProvider.js.map +1 -0
  23. package/dist/esm/lib/getNftsOwnedByAddress.js +51 -0
  24. package/dist/esm/lib/getNftsOwnedByAddress.js.map +1 -0
  25. package/dist/esm/lib/index.js +3 -0
  26. package/dist/esm/lib/index.js.map +1 -0
  27. package/dist/types/Plugin.d.ts +54 -0
  28. package/dist/types/Plugin.d.ts.map +1 -0
  29. package/dist/types/Witness.d.ts +14 -0
  30. package/dist/types/Witness.d.ts.map +1 -0
  31. package/dist/types/index.d.ts +6 -0
  32. package/dist/types/index.d.ts.map +1 -0
  33. package/dist/types/lib/getExternalProviderFromHttpProvider.d.ts +16 -0
  34. package/dist/types/lib/getExternalProviderFromHttpProvider.d.ts.map +1 -0
  35. package/dist/types/lib/getNftsOwnedByAddress.d.ts +3 -0
  36. package/dist/types/lib/getNftsOwnedByAddress.d.ts.map +1 -0
  37. package/dist/types/lib/index.d.ts +3 -0
  38. package/dist/types/lib/index.d.ts.map +1 -0
  39. package/package.json +65 -0
  40. package/src/Plugin.ts +16 -0
  41. package/src/Witness.ts +48 -0
  42. package/src/index.ts +9 -0
  43. package/src/lib/getExternalProviderFromHttpProvider.ts +24 -0
  44. package/src/lib/getNftsOwnedByAddress.ts +61 -0
  45. package/src/lib/index.ts +2 -0
  46. package/typedoc.json +5 -0
package/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ [![logo][]](https://xyo.network)
2
+
3
+ Part of [sdk-xyo-clint-js](https://www.npmjs.com/package/@xyo-network/sdk-xyo-client-js)
4
+
5
+ ## License
6
+
7
+ > See the [LICENSE](LICENSE) file for license details
8
+
9
+ ## Credits
10
+
11
+ [Made with 🔥 and ❄️ by XYO](https://xyo.network)
12
+
13
+ [logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CryptoWalletNftWitnessPlugin = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const crypto_nft_payload_plugin_1 = require("@xyo-network/crypto-nft-payload-plugin");
6
+ const payload_model_1 = require("@xyo-network/payload-model");
7
+ const payloadset_plugin_1 = require("@xyo-network/payloadset-plugin");
8
+ const Witness_1 = require("./Witness");
9
+ const CryptoWalletNftWitnessPlugin = () => (0, payloadset_plugin_1.createPayloadSetWitnessPlugin)({ required: { [crypto_nft_payload_plugin_1.NftSchema]: 1 }, schema: payload_model_1.PayloadSetSchema }, {
10
+ witness: (params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
11
+ const result = yield Witness_1.CryptoWalletNftWitness.create(params);
12
+ return result;
13
+ }),
14
+ });
15
+ exports.CryptoWalletNftWitnessPlugin = CryptoWalletNftWitnessPlugin;
16
+ //# sourceMappingURL=Plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.js","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":";;;;AAAA,sFAAkE;AAClE,8DAA6D;AAC7D,sEAA8E;AAE9E,uCAAkD;AAE3C,MAAM,4BAA4B,GAAG,GAAG,EAAE,CAC/C,IAAA,iDAA6B,EAC3B,EAAE,QAAQ,EAAE,EAAE,CAAC,qCAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,gCAAgB,EAAE,EAC1D;IACE,OAAO,EAAE,CAAO,MAAM,EAAE,EAAE;QACxB,MAAM,MAAM,GAAG,MAAM,gCAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC1D,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;CACF,CACF,CAAA;AATU,QAAA,4BAA4B,gCAStC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CryptoWalletNftWitness = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const assert_1 = require("@xylabs/assert");
6
+ const crypto_nft_payload_plugin_1 = require("@xyo-network/crypto-nft-payload-plugin");
7
+ const witness_1 = require("@xyo-network/witness");
8
+ const lib_1 = require("./lib");
9
+ const schema = crypto_nft_payload_plugin_1.NftSchema;
10
+ class CryptoWalletNftWitness extends witness_1.AbstractWitness {
11
+ get provider() {
12
+ return (0, assert_1.assertEx)(this.params.provider, 'Provider Required');
13
+ }
14
+ observeHandler(payloads) {
15
+ var _a;
16
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
17
+ yield this.started('throw');
18
+ const queries = (_a = payloads === null || payloads === void 0 ? void 0 : payloads.filter(crypto_nft_payload_plugin_1.isNftWitnessQueryPayload)) !== null && _a !== void 0 ? _a : [];
19
+ const observations = yield Promise.all(queries.map((query) => tslib_1.__awaiter(this, void 0, void 0, function* () {
20
+ const address = (0, assert_1.assertEx)((query === null || query === void 0 ? void 0 : query.address) || this.config.address, 'params.address is required');
21
+ const chainId = (0, assert_1.assertEx)((query === null || query === void 0 ? void 0 : query.chainId) || this.config.chainId, 'params.chainId is required');
22
+ const nfts = yield (0, lib_1.getNftsOwnedByAddress)(address, chainId, this.account.private.hex);
23
+ const observation = nfts.map((nft) => {
24
+ return Object.assign(Object.assign({}, nft), { schema });
25
+ });
26
+ return observation;
27
+ })));
28
+ return observations.flat();
29
+ });
30
+ }
31
+ }
32
+ exports.CryptoWalletNftWitness = CryptoWalletNftWitness;
33
+ CryptoWalletNftWitness.configSchemas = [crypto_nft_payload_plugin_1.NftWitnessConfigSchema];
34
+ //# sourceMappingURL=Witness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Witness.js","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":";;;;AACA,2CAAyC;AACzC,sFAM+C;AAG/C,kDAAqE;AAErE,+BAA6C;AAS7C,MAAM,MAAM,GAAG,qCAAS,CAAA;AAExB,MAAa,sBAAoG,SAAQ,yBAAwB;IAG/I,IAAc,QAAQ;QACpB,OAAO,IAAA,iBAAQ,EAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAA;IAC5D,CAAC;IAEwB,cAAc,CAAC,QAAoB;;;YAC1D,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YAC3B,MAAM,OAAO,GAAG,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,CAAC,oDAAwB,CAAC,mCAAI,EAAE,CAAA;YAChE,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,CACpC,OAAO,CAAC,GAAG,CAAC,CAAO,KAAK,EAAE,EAAE;gBAC1B,MAAM,OAAO,GAAG,IAAA,iBAAQ,EAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,KAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,4BAA4B,CAAC,CAAA;gBAC7F,MAAM,OAAO,GAAG,IAAA,iBAAQ,EAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,KAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,4BAA4B,CAAC,CAAA;gBAC7F,MAAM,IAAI,GAAG,MAAM,IAAA,2BAAqB,EAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;gBACpF,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAiB,CAAC,GAAG,EAAE,EAAE;oBACnD,uCAAY,GAAG,KAAE,MAAM,IAAE;gBAC3B,CAAC,CAAC,CAAA;gBACF,OAAO,WAAW,CAAA;YACpB,CAAC,CAAA,CAAC,CACH,CAAA;YACD,OAAO,YAAY,CAAC,IAAI,EAAE,CAAA;;KAC3B;;AAtBH,wDAuBC;AAtBiB,oCAAa,GAAG,CAAC,kDAAsB,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CryptoWalletNftWitnessPlugin = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const Plugin_1 = require("./Plugin");
6
+ Object.defineProperty(exports, "CryptoWalletNftWitnessPlugin", { enumerable: true, get: function () { return Plugin_1.CryptoWalletNftWitnessPlugin; } });
7
+ tslib_1.__exportStar(require("./lib"), exports);
8
+ tslib_1.__exportStar(require("./Witness"), exports);
9
+ // eslint-disable-next-line import/no-default-export
10
+ exports.default = Plugin_1.CryptoWalletNftWitnessPlugin;
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAuD;AAK9C,6GALA,qCAA4B,OAKA;AAHrC,gDAAqB;AACrB,oDAAyB;AAIzB,oDAAoD;AACpD,kBAAe,qCAA4B,CAAA"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExternalProviderFromHttpProvider = void 0;
4
+ /**
5
+ * This method attempts to appease TypeScript without just
6
+ * casting away the underlying types as to preserve as much
7
+ * of the type information as possible.
8
+ * The direct conversion from HttpProvider to ExternalProvider
9
+ * won't work because the types for send/sendAsync are incompatible
10
+ * (implemented as async in one vs with callbacks in the other).
11
+ * However, the disparity is handled under the hood by the library
12
+ * by closing over the request function and promisify-ing it.
13
+ * @param provider
14
+ * @returns
15
+ */
16
+ const getExternalProviderFromHttpProvider = (provider) => {
17
+ const external = provider;
18
+ external === null || external === void 0 ? true : delete external.send;
19
+ external === null || external === void 0 ? true : delete external.sendAsync;
20
+ return external;
21
+ };
22
+ exports.getExternalProviderFromHttpProvider = getExternalProviderFromHttpProvider;
23
+ //# sourceMappingURL=getExternalProviderFromHttpProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getExternalProviderFromHttpProvider.js","sourceRoot":"","sources":["../../../src/lib/getExternalProviderFromHttpProvider.ts"],"names":[],"mappings":";;;AAMA;;;;;;;;;;;GAWG;AACI,MAAM,mCAAmC,GAAG,CAAC,QAAsB,EAAoB,EAAE;IAC9F,MAAM,QAAQ,GAAG,QAAwB,CAAA;IACjC,QAA8B,aAA9B,QAAQ,4BAAR,QAAQ,CAAwB,IAAI,CAAA;IACpC,QAA8B,aAA9B,QAAQ,4BAAR,QAAQ,CAAwB,SAAS,CAAA;IACjD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AALY,QAAA,mCAAmC,uCAK/C"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNftsOwnedByAddress = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const sdk_1 = require("@infura/sdk");
6
+ const getNftsOwnedByAddress = (
7
+ /**
8
+ * The address of the wallet to search for NFTs
9
+ */
10
+ publicAddress,
11
+ /**
12
+ * The chain ID (1 = Ethereum Mainnet, 4 = Rinkeby, etc.) of the chain to search for NFTs on
13
+ */
14
+ chainId,
15
+ // /**
16
+ // * The ethers provider to use to search for NFTs
17
+ // */
18
+ // provider: ExternalProvider | JsonRpcFetchFunc,
19
+ /**
20
+ * The private key of the wallet to use to search for NFTs
21
+ */
22
+ privateKey,
23
+ /**
24
+ * The maximum number of NFTs to return. Configurable to prevent
25
+ * large wallets from exhausting Infura API credits.
26
+ */
27
+ maxNftCount = 1000) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
28
+ // Instantiate SDK
29
+ const sdk = new sdk_1.SDK(new sdk_1.Auth({
30
+ chainId,
31
+ privateKey,
32
+ projectId: process.env.INFURA_PROJECT_ID,
33
+ // ipfs: {
34
+ // apiKeySecret: process.env.INFURA_IPFS_PROJECT_SECRET,
35
+ // projectId: process.env.INFURA_IPFS_PROJECT_ID,
36
+ // },
37
+ // provider,
38
+ // NOTE: rpcUrl is not required if chainId & projectId are provided
39
+ // rpcUrl: process.env.EVM_RPC_URL,
40
+ secretId: process.env.INFURA_PROJECT_SECRET,
41
+ }));
42
+ const nfts = [];
43
+ let cursor = undefined;
44
+ do {
45
+ const opts = { cursor, includeMetadata: true, publicAddress };
46
+ const { cursor: nextCursor, pageSize, total, assets } = yield sdk.api.getNFTs(opts);
47
+ const batch = assets.slice(0, Math.min(pageSize, total - nfts.length));
48
+ nfts.push(...batch);
49
+ cursor = nextCursor;
50
+ if (nfts.length >= total || !cursor)
51
+ break;
52
+ } while (nfts.length < maxNftCount);
53
+ return nfts;
54
+ });
55
+ exports.getNftsOwnedByAddress = getNftsOwnedByAddress;
56
+ //# sourceMappingURL=getNftsOwnedByAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getNftsOwnedByAddress.js","sourceRoot":"","sources":["../../../src/lib/getNftsOwnedByAddress.ts"],"names":[],"mappings":";;;;AAAA,qCAAuC;AAUhC,MAAM,qBAAqB,GAAG;AACnC;;GAEG;AACH,aAAqB;AACrB;;GAEG;AACH,OAAe;AACf,MAAM;AACN,mDAAmD;AACnD,MAAM;AACN,iDAAiD;AACjD;;GAEG;AACH,UAAkB;AAClB;;;GAGG;AACH,WAAW,GAAG,IAAI,EACE,EAAE;IACtB,kBAAkB;IAClB,MAAM,GAAG,GAAG,IAAI,SAAG,CACjB,IAAI,UAAI,CAAC;QACP,OAAO;QACP,UAAU;QACV,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;QACxC,UAAU;QACV,0DAA0D;QAC1D,mDAAmD;QACnD,KAAK;QACL,YAAY;QACZ,mEAAmE;QACnE,mCAAmC;QACnC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;KAC5C,CAAC,CACH,CAAA;IACD,MAAM,IAAI,GAAc,EAAE,CAAA;IAC1B,IAAI,MAAM,GAAuB,SAAS,CAAA;IAC1C,GAAG;QACD,MAAM,IAAI,GAAyB,EAAE,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;QACnF,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACnF,MAAM,KAAK,GAAc,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;QACjF,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;QACnB,MAAM,GAAG,UAAU,CAAA;QACnB,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,IAAI,CAAC,MAAM;YAAE,MAAK;KAC3C,QAAQ,IAAI,CAAC,MAAM,GAAG,WAAW,EAAC;IACnC,OAAO,IAAI,CAAA;AACb,CAAC,CAAA,CAAA;AAlDY,QAAA,qBAAqB,yBAkDjC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./getExternalProviderFromHttpProvider"), exports);
5
+ tslib_1.__exportStar(require("./getNftsOwnedByAddress"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":";;;AAAA,gFAAqD;AACrD,kEAAuC"}
@@ -0,0 +1,11 @@
1
+ import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin';
2
+ import { PayloadSetSchema } from '@xyo-network/payload-model';
3
+ import { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin';
4
+ import { CryptoWalletNftWitness } from './Witness';
5
+ export const CryptoWalletNftWitnessPlugin = () => createPayloadSetWitnessPlugin({ required: { [NftSchema]: 1 }, schema: PayloadSetSchema }, {
6
+ witness: async (params) => {
7
+ const result = await CryptoWalletNftWitness.create(params);
8
+ return result;
9
+ },
10
+ });
11
+ //# sourceMappingURL=Plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.js","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAA;AAE9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAElD,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,EAAE,CAC/C,6BAA6B,CAC3B,EAAE,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAC1D;IACE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QACxB,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC1D,OAAO,MAAM,CAAA;IACf,CAAC;CACF,CACF,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { assertEx } from '@xylabs/assert';
2
+ import { isNftWitnessQueryPayload, NftSchema, NftWitnessConfigSchema, } from '@xyo-network/crypto-nft-payload-plugin';
3
+ import { AbstractWitness } from '@xyo-network/witness';
4
+ import { getNftsOwnedByAddress } from './lib';
5
+ const schema = NftSchema;
6
+ export class CryptoWalletNftWitness extends AbstractWitness {
7
+ static configSchemas = [NftWitnessConfigSchema];
8
+ get provider() {
9
+ return assertEx(this.params.provider, 'Provider Required');
10
+ }
11
+ async observeHandler(payloads) {
12
+ await this.started('throw');
13
+ const queries = payloads?.filter(isNftWitnessQueryPayload) ?? [];
14
+ const observations = await Promise.all(queries.map(async (query) => {
15
+ const address = assertEx(query?.address || this.config.address, 'params.address is required');
16
+ const chainId = assertEx(query?.chainId || this.config.chainId, 'params.chainId is required');
17
+ const nfts = await getNftsOwnedByAddress(address, chainId, this.account.private.hex);
18
+ const observation = nfts.map((nft) => {
19
+ return { ...nft, schema };
20
+ });
21
+ return observation;
22
+ }));
23
+ return observations.flat();
24
+ }
25
+ }
26
+ //# sourceMappingURL=Witness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Witness.js","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAEL,wBAAwB,EAExB,SAAS,EACT,sBAAsB,GACvB,MAAM,wCAAwC,CAAA;AAG/C,OAAO,EAAE,eAAe,EAAiB,MAAM,sBAAsB,CAAA;AAErE,OAAO,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAS7C,MAAM,MAAM,GAAG,SAAS,CAAA;AAExB,MAAM,OAAO,sBAAoG,SAAQ,eAAwB;IAC/I,MAAM,CAAU,aAAa,GAAG,CAAC,sBAAsB,CAAC,CAAA;IAExD,IAAc,QAAQ;QACpB,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAA;IAC5D,CAAC;IAEkB,KAAK,CAAC,cAAc,CAAC,QAAoB;QAC1D,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3B,MAAM,OAAO,GAAG,QAAQ,EAAE,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,CAAA;QAChE,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,CACpC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YAC1B,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,4BAA4B,CAAC,CAAA;YAC7F,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,4BAA4B,CAAC,CAAA;YAC7F,MAAM,IAAI,GAAG,MAAM,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YACpF,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAiB,CAAC,GAAG,EAAE,EAAE;gBACnD,OAAO,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAA;YAC3B,CAAC,CAAC,CAAA;YACF,OAAO,WAAW,CAAA;QACpB,CAAC,CAAC,CACH,CAAA;QACD,OAAO,YAAY,CAAC,IAAI,EAAE,CAAA;IAC5B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { CryptoWalletNftWitnessPlugin } from './Plugin';
2
+ export * from './lib';
3
+ export * from './Witness';
4
+ export { CryptoWalletNftWitnessPlugin };
5
+ // eslint-disable-next-line import/no-default-export
6
+ export default CryptoWalletNftWitnessPlugin;
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAEvD,cAAc,OAAO,CAAA;AACrB,cAAc,WAAW,CAAA;AAEzB,OAAO,EAAE,4BAA4B,EAAE,CAAA;AAEvC,oDAAoD;AACpD,eAAe,4BAA4B,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This method attempts to appease TypeScript without just
3
+ * casting away the underlying types as to preserve as much
4
+ * of the type information as possible.
5
+ * The direct conversion from HttpProvider to ExternalProvider
6
+ * won't work because the types for send/sendAsync are incompatible
7
+ * (implemented as async in one vs with callbacks in the other).
8
+ * However, the disparity is handled under the hood by the library
9
+ * by closing over the request function and promisify-ing it.
10
+ * @param provider
11
+ * @returns
12
+ */
13
+ export const getExternalProviderFromHttpProvider = (provider) => {
14
+ const external = provider;
15
+ delete external?.send;
16
+ delete external?.sendAsync;
17
+ return external;
18
+ };
19
+ //# sourceMappingURL=getExternalProviderFromHttpProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getExternalProviderFromHttpProvider.js","sourceRoot":"","sources":["../../../src/lib/getExternalProviderFromHttpProvider.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,QAAsB,EAAoB,EAAE;IAC9F,MAAM,QAAQ,GAAG,QAAwB,CAAA;IACzC,OAAQ,QAA8B,EAAE,IAAI,CAAA;IAC5C,OAAQ,QAA8B,EAAE,SAAS,CAAA;IACjD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
@@ -0,0 +1,51 @@
1
+ import { Auth, SDK } from '@infura/sdk';
2
+ export const getNftsOwnedByAddress = async (
3
+ /**
4
+ * The address of the wallet to search for NFTs
5
+ */
6
+ publicAddress,
7
+ /**
8
+ * The chain ID (1 = Ethereum Mainnet, 4 = Rinkeby, etc.) of the chain to search for NFTs on
9
+ */
10
+ chainId,
11
+ // /**
12
+ // * The ethers provider to use to search for NFTs
13
+ // */
14
+ // provider: ExternalProvider | JsonRpcFetchFunc,
15
+ /**
16
+ * The private key of the wallet to use to search for NFTs
17
+ */
18
+ privateKey,
19
+ /**
20
+ * The maximum number of NFTs to return. Configurable to prevent
21
+ * large wallets from exhausting Infura API credits.
22
+ */
23
+ maxNftCount = 1000) => {
24
+ // Instantiate SDK
25
+ const sdk = new SDK(new Auth({
26
+ chainId,
27
+ privateKey,
28
+ projectId: process.env.INFURA_PROJECT_ID,
29
+ // ipfs: {
30
+ // apiKeySecret: process.env.INFURA_IPFS_PROJECT_SECRET,
31
+ // projectId: process.env.INFURA_IPFS_PROJECT_ID,
32
+ // },
33
+ // provider,
34
+ // NOTE: rpcUrl is not required if chainId & projectId are provided
35
+ // rpcUrl: process.env.EVM_RPC_URL,
36
+ secretId: process.env.INFURA_PROJECT_SECRET,
37
+ }));
38
+ const nfts = [];
39
+ let cursor = undefined;
40
+ do {
41
+ const opts = { cursor, includeMetadata: true, publicAddress };
42
+ const { cursor: nextCursor, pageSize, total, assets } = await sdk.api.getNFTs(opts);
43
+ const batch = assets.slice(0, Math.min(pageSize, total - nfts.length));
44
+ nfts.push(...batch);
45
+ cursor = nextCursor;
46
+ if (nfts.length >= total || !cursor)
47
+ break;
48
+ } while (nfts.length < maxNftCount);
49
+ return nfts;
50
+ };
51
+ //# sourceMappingURL=getNftsOwnedByAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getNftsOwnedByAddress.js","sourceRoot":"","sources":["../../../src/lib/getNftsOwnedByAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAUvC,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK;AACxC;;GAEG;AACH,aAAqB;AACrB;;GAEG;AACH,OAAe;AACf,MAAM;AACN,mDAAmD;AACnD,MAAM;AACN,iDAAiD;AACjD;;GAEG;AACH,UAAkB;AAClB;;;GAGG;AACH,WAAW,GAAG,IAAI,EACE,EAAE;IACtB,kBAAkB;IAClB,MAAM,GAAG,GAAG,IAAI,GAAG,CACjB,IAAI,IAAI,CAAC;QACP,OAAO;QACP,UAAU;QACV,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;QACxC,UAAU;QACV,0DAA0D;QAC1D,mDAAmD;QACnD,KAAK;QACL,YAAY;QACZ,mEAAmE;QACnE,mCAAmC;QACnC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;KAC5C,CAAC,CACH,CAAA;IACD,MAAM,IAAI,GAAc,EAAE,CAAA;IAC1B,IAAI,MAAM,GAAuB,SAAS,CAAA;IAC1C,GAAG;QACD,MAAM,IAAI,GAAyB,EAAE,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;QACnF,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACnF,MAAM,KAAK,GAAc,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;QACjF,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;QACnB,MAAM,GAAG,UAAU,CAAA;QACnB,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,IAAI,CAAC,MAAM;YAAE,MAAK;KAC3C,QAAQ,IAAI,CAAC,MAAM,GAAG,WAAW,EAAC;IACnC,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './getExternalProviderFromHttpProvider';
2
+ export * from './getNftsOwnedByAddress';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,cAAc,yBAAyB,CAAA"}
@@ -0,0 +1,54 @@
1
+ import { CryptoWalletNftWitness } from './Witness';
2
+ export declare const CryptoWalletNftWitnessPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<CryptoWalletNftWitness<import("@xyo-network/core").BaseParamsFields & {
3
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
4
+ accountDerivationPath?: string | undefined;
5
+ config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
6
+ readonly archivist?: import("@xyo-network/module-model").ArchivistModuleConfig | undefined;
7
+ readonly name?: string | undefined;
8
+ readonly paging?: Record<string, {
9
+ size?: number | undefined;
10
+ }> | undefined;
11
+ readonly schema: string;
12
+ readonly security?: {
13
+ readonly allowAnonymous?: boolean | undefined;
14
+ readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
15
+ readonly disallowed?: Record<string, string[]> | undefined;
16
+ } | undefined;
17
+ readonly sign?: boolean | undefined;
18
+ readonly storeQueries?: boolean | undefined;
19
+ } & Omit<Omit<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
20
+ readonly archivist?: import("@xyo-network/module-model").ArchivistModuleConfig | undefined;
21
+ readonly name?: string | undefined;
22
+ readonly paging?: Record<string, {
23
+ size?: number | undefined;
24
+ }> | undefined;
25
+ readonly schema: "network.xyo.crypto.nft.witness.config";
26
+ readonly security?: {
27
+ readonly allowAnonymous?: boolean | undefined;
28
+ readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
29
+ readonly disallowed?: Record<string, string[]> | undefined;
30
+ } | undefined;
31
+ readonly sign?: boolean | undefined;
32
+ readonly storeQueries?: boolean | undefined;
33
+ } & Omit<{
34
+ schema: "network.xyo.crypto.nft.witness.config";
35
+ targetSet?: (import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & import("@xyo-network/payload-model").PayloadSet & {
36
+ schema: "network.xyo.payload.set";
37
+ }) | undefined;
38
+ } & {
39
+ address?: string | undefined;
40
+ chainId?: number | undefined;
41
+ schema: "network.xyo.crypto.nft.witness.config";
42
+ }, "schema"> & {
43
+ schema: "network.xyo.crypto.nft.witness.config";
44
+ }, "schema"> & {
45
+ schema: string;
46
+ }, "schema"> & {
47
+ schema: string;
48
+ };
49
+ ephemeralQueryAccountEnabled?: boolean | undefined;
50
+ wallet?: import("@xyo-network/wallet-model").WalletInstance | undefined;
51
+ } & {
52
+ provider?: import("@ethersproject/providers").ExternalProvider | import("@ethersproject/providers").JsonRpcFetchFunc | undefined;
53
+ }>>;
54
+ //# sourceMappingURL=Plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAElD,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAStC,CAAA"}
@@ -0,0 +1,14 @@
1
+ import type { ExternalProvider, JsonRpcFetchFunc } from '@ethersproject/providers';
2
+ import { CryptoWalletNftWitnessConfig } from '@xyo-network/crypto-nft-payload-plugin';
3
+ import { AnyConfigSchema } from '@xyo-network/module';
4
+ import { Payload } from '@xyo-network/payload-model';
5
+ import { AbstractWitness, WitnessParams } from '@xyo-network/witness';
6
+ export type CryptoWalletNftWitnessParams = WitnessParams<AnyConfigSchema<CryptoWalletNftWitnessConfig>, {
7
+ provider?: ExternalProvider | JsonRpcFetchFunc;
8
+ }>;
9
+ export declare class CryptoWalletNftWitness<TParams extends CryptoWalletNftWitnessParams = CryptoWalletNftWitnessParams> extends AbstractWitness<TParams> {
10
+ static configSchemas: "network.xyo.crypto.nft.witness.config"[];
11
+ protected get provider(): ExternalProvider | JsonRpcFetchFunc;
12
+ protected observeHandler(payloads?: Payload[]): Promise<Payload[]>;
13
+ }
14
+ //# sourceMappingURL=Witness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAElF,OAAO,EACL,4BAA4B,EAK7B,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAIrE,MAAM,MAAM,4BAA4B,GAAG,aAAa,CACtD,eAAe,CAAC,4BAA4B,CAAC,EAC7C;IACE,QAAQ,CAAC,EAAE,gBAAgB,GAAG,gBAAgB,CAAA;CAC/C,CACF,CAAA;AAID,qBAAa,sBAAsB,CAAC,OAAO,SAAS,4BAA4B,GAAG,4BAA4B,CAAE,SAAQ,eAAe,CAAC,OAAO,CAAC;IAC/I,OAAgB,aAAa,4CAA2B;IAExD,SAAS,KAAK,QAAQ,wCAErB;cAEwB,cAAc,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAgBlF"}
@@ -0,0 +1,6 @@
1
+ import { CryptoWalletNftWitnessPlugin } from './Plugin';
2
+ export * from './lib';
3
+ export * from './Witness';
4
+ export { CryptoWalletNftWitnessPlugin };
5
+ export default CryptoWalletNftWitnessPlugin;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAEvD,cAAc,OAAO,CAAA;AACrB,cAAc,WAAW,CAAA;AAEzB,OAAO,EAAE,4BAA4B,EAAE,CAAA;AAGvC,eAAe,4BAA4B,CAAA"}
@@ -0,0 +1,16 @@
1
+ import type { ExternalProvider } from '@ethersproject/providers';
2
+ import { HttpProvider } from 'web3-providers-http';
3
+ /**
4
+ * This method attempts to appease TypeScript without just
5
+ * casting away the underlying types as to preserve as much
6
+ * of the type information as possible.
7
+ * The direct conversion from HttpProvider to ExternalProvider
8
+ * won't work because the types for send/sendAsync are incompatible
9
+ * (implemented as async in one vs with callbacks in the other).
10
+ * However, the disparity is handled under the hood by the library
11
+ * by closing over the request function and promisify-ing it.
12
+ * @param provider
13
+ * @returns
14
+ */
15
+ export declare const getExternalProviderFromHttpProvider: (provider: HttpProvider) => ExternalProvider;
16
+ //# sourceMappingURL=getExternalProviderFromHttpProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getExternalProviderFromHttpProvider.d.ts","sourceRoot":"","sources":["../../../src/lib/getExternalProviderFromHttpProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAKlD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mCAAmC,aAAc,YAAY,KAAG,gBAK5E,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { NftInfo } from '@xyo-network/crypto-nft-payload-plugin';
2
+ export declare const getNftsOwnedByAddress: (publicAddress: string, chainId: number, privateKey: string, maxNftCount?: number) => Promise<NftInfo[]>;
3
+ //# sourceMappingURL=getNftsOwnedByAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getNftsOwnedByAddress.d.ts","sourceRoot":"","sources":["../../../src/lib/getNftsOwnedByAddress.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAA;AAShE,eAAO,MAAM,qBAAqB,kBAIjB,MAAM,WAIZ,MAAM,cAQH,MAAM,2BAMjB,QAAQ,OAAO,EAAE,CA4BnB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './getExternalProviderFromHttpProvider';
2
+ export * from './getNftsOwnedByAddress';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,cAAc,yBAAyB,CAAA"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@xyo-network/crypto-nft-witness-wallet-plugin",
3
+ "author": {
4
+ "email": "support@xyo.network",
5
+ "name": "XYO Development Team",
6
+ "url": "https://xyo.network"
7
+ },
8
+ "bugs": {
9
+ "email": "support@xyo.network",
10
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
+ },
12
+ "dependencies": {
13
+ "@ethersproject/providers": "^5.7.2",
14
+ "@infura/sdk": "^2.4.3",
15
+ "@xylabs/assert": "^2.9.3",
16
+ "@xyo-network/crypto-nft-payload-plugin": "~2.70.0",
17
+ "@xyo-network/module": "~2.70.0",
18
+ "@xyo-network/payload-model": "~2.70.0",
19
+ "@xyo-network/payloadset-plugin": "~2.70.0",
20
+ "@xyo-network/witness": "~2.70.0",
21
+ "web3-providers-http": "^4.0.3"
22
+ },
23
+ "devDependencies": {
24
+ "@xylabs/jest-helpers": "^2.9.3",
25
+ "@xylabs/ts-scripts-yarn3": "^2.19.0",
26
+ "@xylabs/tsconfig": "^2.19.0",
27
+ "ethers": "^5.7.2",
28
+ "jest": "^29.6.2",
29
+ "typescript": "^5.1.6"
30
+ },
31
+ "description": "Primary SDK for using XYO Protocol 2.0",
32
+ "browser": "dist/esm/index.js",
33
+ "docs": "dist/docs.json",
34
+ "exports": {
35
+ ".": {
36
+ "node": {
37
+ "import": "./dist/esm/index.js",
38
+ "require": "./dist/cjs/index.js"
39
+ },
40
+ "browser": {
41
+ "import": "./dist/esm/index.js",
42
+ "require": "./dist/cjs/index.js"
43
+ },
44
+ "default": "./dist/esm/index.js"
45
+ },
46
+ "./dist/docs.json": {
47
+ "default": "./dist/docs.json"
48
+ },
49
+ "./package.json": "./package.json"
50
+ },
51
+ "main": "dist/cjs/index.js",
52
+ "module": "dist/esm/index.js",
53
+ "homepage": "https://xyo.network",
54
+ "license": "LGPL-3.0",
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
61
+ },
62
+ "sideEffects": false,
63
+ "types": "dist/types/index.d.ts",
64
+ "version": "2.70.0"
65
+ }
package/src/Plugin.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'
2
+ import { PayloadSetSchema } from '@xyo-network/payload-model'
3
+ import { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'
4
+
5
+ import { CryptoWalletNftWitness } from './Witness'
6
+
7
+ export const CryptoWalletNftWitnessPlugin = () =>
8
+ createPayloadSetWitnessPlugin<CryptoWalletNftWitness>(
9
+ { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },
10
+ {
11
+ witness: async (params) => {
12
+ const result = await CryptoWalletNftWitness.create(params)
13
+ return result
14
+ },
15
+ },
16
+ )
package/src/Witness.ts ADDED
@@ -0,0 +1,48 @@
1
+ import type { ExternalProvider, JsonRpcFetchFunc } from '@ethersproject/providers'
2
+ import { assertEx } from '@xylabs/assert'
3
+ import {
4
+ CryptoWalletNftWitnessConfig,
5
+ isNftWitnessQueryPayload,
6
+ NftInfoPayload,
7
+ NftSchema,
8
+ NftWitnessConfigSchema,
9
+ } from '@xyo-network/crypto-nft-payload-plugin'
10
+ import { AnyConfigSchema } from '@xyo-network/module'
11
+ import { Payload } from '@xyo-network/payload-model'
12
+ import { AbstractWitness, WitnessParams } from '@xyo-network/witness'
13
+
14
+ import { getNftsOwnedByAddress } from './lib'
15
+
16
+ export type CryptoWalletNftWitnessParams = WitnessParams<
17
+ AnyConfigSchema<CryptoWalletNftWitnessConfig>,
18
+ {
19
+ provider?: ExternalProvider | JsonRpcFetchFunc
20
+ }
21
+ >
22
+
23
+ const schema = NftSchema
24
+
25
+ export class CryptoWalletNftWitness<TParams extends CryptoWalletNftWitnessParams = CryptoWalletNftWitnessParams> extends AbstractWitness<TParams> {
26
+ static override configSchemas = [NftWitnessConfigSchema]
27
+
28
+ protected get provider() {
29
+ return assertEx(this.params.provider, 'Provider Required')
30
+ }
31
+
32
+ protected override async observeHandler(payloads?: Payload[]): Promise<Payload[]> {
33
+ await this.started('throw')
34
+ const queries = payloads?.filter(isNftWitnessQueryPayload) ?? []
35
+ const observations = await Promise.all(
36
+ queries.map(async (query) => {
37
+ const address = assertEx(query?.address || this.config.address, 'params.address is required')
38
+ const chainId = assertEx(query?.chainId || this.config.chainId, 'params.chainId is required')
39
+ const nfts = await getNftsOwnedByAddress(address, chainId, this.account.private.hex)
40
+ const observation = nfts.map<NftInfoPayload>((nft) => {
41
+ return { ...nft, schema }
42
+ })
43
+ return observation
44
+ }),
45
+ )
46
+ return observations.flat()
47
+ }
48
+ }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { CryptoWalletNftWitnessPlugin } from './Plugin'
2
+
3
+ export * from './lib'
4
+ export * from './Witness'
5
+
6
+ export { CryptoWalletNftWitnessPlugin }
7
+
8
+ // eslint-disable-next-line import/no-default-export
9
+ export default CryptoWalletNftWitnessPlugin
@@ -0,0 +1,24 @@
1
+ import type { ExternalProvider } from '@ethersproject/providers'
2
+ import { HttpProvider } from 'web3-providers-http'
3
+
4
+ type WithOptionalSends = { send?: unknown; sendAsync?: unknown }
5
+ type WithoutSends = Omit<Omit<HttpProvider, 'sendAsync'>, 'send'>
6
+
7
+ /**
8
+ * This method attempts to appease TypeScript without just
9
+ * casting away the underlying types as to preserve as much
10
+ * of the type information as possible.
11
+ * The direct conversion from HttpProvider to ExternalProvider
12
+ * won't work because the types for send/sendAsync are incompatible
13
+ * (implemented as async in one vs with callbacks in the other).
14
+ * However, the disparity is handled under the hood by the library
15
+ * by closing over the request function and promisify-ing it.
16
+ * @param provider
17
+ * @returns
18
+ */
19
+ export const getExternalProviderFromHttpProvider = (provider: HttpProvider): ExternalProvider => {
20
+ const external = provider as WithoutSends
21
+ delete (external as WithOptionalSends)?.send
22
+ delete (external as WithOptionalSends)?.sendAsync
23
+ return external
24
+ }
@@ -0,0 +1,61 @@
1
+ import { Auth, SDK } from '@infura/sdk'
2
+ import { NftInfo } from '@xyo-network/crypto-nft-payload-plugin'
3
+
4
+ type PublicAddressOptions = {
5
+ cursor?: string
6
+ includeMetadata?: boolean
7
+ publicAddress: string
8
+ tokenAddresses?: string[]
9
+ }
10
+
11
+ export const getNftsOwnedByAddress = async (
12
+ /**
13
+ * The address of the wallet to search for NFTs
14
+ */
15
+ publicAddress: string,
16
+ /**
17
+ * The chain ID (1 = Ethereum Mainnet, 4 = Rinkeby, etc.) of the chain to search for NFTs on
18
+ */
19
+ chainId: number,
20
+ // /**
21
+ // * The ethers provider to use to search for NFTs
22
+ // */
23
+ // provider: ExternalProvider | JsonRpcFetchFunc,
24
+ /**
25
+ * The private key of the wallet to use to search for NFTs
26
+ */
27
+ privateKey: string,
28
+ /**
29
+ * The maximum number of NFTs to return. Configurable to prevent
30
+ * large wallets from exhausting Infura API credits.
31
+ */
32
+ maxNftCount = 1000,
33
+ ): Promise<NftInfo[]> => {
34
+ // Instantiate SDK
35
+ const sdk = new SDK(
36
+ new Auth({
37
+ chainId,
38
+ privateKey,
39
+ projectId: process.env.INFURA_PROJECT_ID,
40
+ // ipfs: {
41
+ // apiKeySecret: process.env.INFURA_IPFS_PROJECT_SECRET,
42
+ // projectId: process.env.INFURA_IPFS_PROJECT_ID,
43
+ // },
44
+ // provider,
45
+ // NOTE: rpcUrl is not required if chainId & projectId are provided
46
+ // rpcUrl: process.env.EVM_RPC_URL,
47
+ secretId: process.env.INFURA_PROJECT_SECRET,
48
+ }),
49
+ )
50
+ const nfts: NftInfo[] = []
51
+ let cursor: string | undefined = undefined
52
+ do {
53
+ const opts: PublicAddressOptions = { cursor, includeMetadata: true, publicAddress }
54
+ const { cursor: nextCursor, pageSize, total, assets } = await sdk.api.getNFTs(opts)
55
+ const batch: NftInfo[] = assets.slice(0, Math.min(pageSize, total - nfts.length))
56
+ nfts.push(...batch)
57
+ cursor = nextCursor
58
+ if (nfts.length >= total || !cursor) break
59
+ } while (nfts.length < maxNftCount)
60
+ return nfts
61
+ }
@@ -0,0 +1,2 @@
1
+ export * from './getExternalProviderFromHttpProvider'
2
+ export * from './getNftsOwnedByAddress'
package/typedoc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "entryPoints": ["./src/index.ts"],
4
+ "tsconfig": "./tsconfig.typedoc.json"
5
+ }