@audius/sdk 3.0.3-beta.94 → 3.0.3-beta.95
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/dist/index.cjs.js +28 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +28 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/legacy.js +28 -2
- package/dist/legacy.js.map +1 -1
- package/dist/native-libs.js +177 -151
- package/dist/native-libs.js.map +1 -1
- package/dist/services/ABIDecoder/AudiusABIDecoder.d.ts +6 -0
- package/dist/web-libs.js +28 -2
- package/dist/web-libs.js.map +1 -1
- package/package.json +2 -2
- package/src/services/ABIDecoder/AudiusABIDecoder.ts +31 -0
package/dist/native-libs.js
CHANGED
|
@@ -600,9 +600,9 @@ if (typeof window !== 'undefined' && window && window.Web3) {
|
|
|
600
600
|
var LibsWeb3 = Web3;
|
|
601
601
|
|
|
602
602
|
var name = "@audius/sdk";
|
|
603
|
-
var version$1 = "3.0.3-beta.
|
|
603
|
+
var version$1 = "3.0.3-beta.95";
|
|
604
604
|
var audius = {
|
|
605
|
-
releaseSHA: "
|
|
605
|
+
releaseSHA: "e33acd6fae099f9a3a3e7673e93ff87acad53a04"
|
|
606
606
|
};
|
|
607
607
|
var description = "Audius SDK";
|
|
608
608
|
var main = "dist/index.cjs.js";
|
|
@@ -8678,6 +8678,155 @@ var EntityManagerABI = {
|
|
|
8678
8678
|
abi: abi$c
|
|
8679
8679
|
};
|
|
8680
8680
|
|
|
8681
|
+
/**
|
|
8682
|
+
* This file includes schemas for use in EIP-712 compliant signature generation and
|
|
8683
|
+
* signature validation, generator functions for generating data
|
|
8684
|
+
* in the form needed by eth_personalSign / eth-sig-util's signTypedData functions,
|
|
8685
|
+
* generators for contract signing domains, and a helper function for generating
|
|
8686
|
+
* cryptographically secure nonces in nodejs or in the browser.
|
|
8687
|
+
* modeled off: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md
|
|
8688
|
+
*/
|
|
8689
|
+
var domains = {};
|
|
8690
|
+
|
|
8691
|
+
function getDomainData(contractName, signatureVersion, chainId, contractAddress) {
|
|
8692
|
+
return {
|
|
8693
|
+
name: contractName,
|
|
8694
|
+
version: signatureVersion,
|
|
8695
|
+
chainId: chainId,
|
|
8696
|
+
verifyingContract: contractAddress
|
|
8697
|
+
};
|
|
8698
|
+
}
|
|
8699
|
+
|
|
8700
|
+
domains.getEntityManagerDomain = function (chainId, contractAddress) {
|
|
8701
|
+
return getDomainData('Entity Manager', '1', chainId, contractAddress);
|
|
8702
|
+
};
|
|
8703
|
+
|
|
8704
|
+
var schemas = {};
|
|
8705
|
+
/* contract signing domain */
|
|
8706
|
+
|
|
8707
|
+
schemas.domain = [{
|
|
8708
|
+
name: 'name',
|
|
8709
|
+
type: 'string'
|
|
8710
|
+
}, {
|
|
8711
|
+
name: 'version',
|
|
8712
|
+
type: 'string'
|
|
8713
|
+
}, {
|
|
8714
|
+
name: 'chainId',
|
|
8715
|
+
type: 'uint256'
|
|
8716
|
+
}, {
|
|
8717
|
+
name: 'verifyingContract',
|
|
8718
|
+
type: 'address'
|
|
8719
|
+
}];
|
|
8720
|
+
schemas.manageEntity = [{
|
|
8721
|
+
name: 'userId',
|
|
8722
|
+
type: 'uint'
|
|
8723
|
+
}, {
|
|
8724
|
+
name: 'entityType',
|
|
8725
|
+
type: 'string'
|
|
8726
|
+
}, {
|
|
8727
|
+
name: 'entityId',
|
|
8728
|
+
type: 'uint'
|
|
8729
|
+
}, {
|
|
8730
|
+
name: 'action',
|
|
8731
|
+
type: 'string'
|
|
8732
|
+
}, {
|
|
8733
|
+
name: 'metadata',
|
|
8734
|
+
type: 'string'
|
|
8735
|
+
}, {
|
|
8736
|
+
name: 'nonce',
|
|
8737
|
+
type: 'bytes32'
|
|
8738
|
+
}];
|
|
8739
|
+
var generators = {};
|
|
8740
|
+
|
|
8741
|
+
function getRequestData(domainDataFn, chainId, contractAddress, messageTypeName, messageSchema, message) {
|
|
8742
|
+
var domainData = domainDataFn(chainId, contractAddress);
|
|
8743
|
+
var types = {
|
|
8744
|
+
EIP712Domain: schemas.domain
|
|
8745
|
+
};
|
|
8746
|
+
types[messageTypeName] = messageSchema;
|
|
8747
|
+
return {
|
|
8748
|
+
types: types,
|
|
8749
|
+
domain: domainData,
|
|
8750
|
+
primaryType: messageTypeName,
|
|
8751
|
+
message: message
|
|
8752
|
+
};
|
|
8753
|
+
}
|
|
8754
|
+
/* User Factory Generators */
|
|
8755
|
+
|
|
8756
|
+
|
|
8757
|
+
generators.getAddUserRequestData = function (chainId, contractAddress, handle, nonce) {
|
|
8758
|
+
var message = {
|
|
8759
|
+
handle: handle,
|
|
8760
|
+
nonce: nonce
|
|
8761
|
+
};
|
|
8762
|
+
return getRequestData(domains.getUserFactoryDomain, chainId, contractAddress, 'AddUserRequest', schemas.addUserRequest, message);
|
|
8763
|
+
};
|
|
8764
|
+
|
|
8765
|
+
generators.getManageEntityData = function (chainId, contractAddress, userId, entityType, entityId, action, metadata, nonce) {
|
|
8766
|
+
var message = {
|
|
8767
|
+
userId: userId,
|
|
8768
|
+
entityType: entityType,
|
|
8769
|
+
entityId: entityId,
|
|
8770
|
+
action: action,
|
|
8771
|
+
metadata: metadata,
|
|
8772
|
+
nonce: nonce
|
|
8773
|
+
};
|
|
8774
|
+
return getRequestData(domains.getEntityManagerDomain, chainId, contractAddress, 'ManageEntity', schemas.manageEntity, message);
|
|
8775
|
+
};
|
|
8776
|
+
/** Return a secure random hex string of nChar length in a browser-compatible way
|
|
8777
|
+
* Taken from https://stackoverflow.com/questions/37378237/how-to-generate-a-random-token-of-32-bit-in-javascript
|
|
8778
|
+
*/
|
|
8779
|
+
|
|
8780
|
+
|
|
8781
|
+
function browserRandomHash(nChar) {
|
|
8782
|
+
// convert number of characters to number of bytes
|
|
8783
|
+
var nBytes = Math.ceil(nChar = (+nChar || 8) / 2); // create a typed array of that many bytes
|
|
8784
|
+
|
|
8785
|
+
var u = new Uint8Array(nBytes); // populate it wit crypto-random values
|
|
8786
|
+
|
|
8787
|
+
window.crypto.getRandomValues(u); // convert it to an Array of Strings (e.g. '01', 'AF', ..)
|
|
8788
|
+
|
|
8789
|
+
var zpad = function zpad(str) {
|
|
8790
|
+
return '00'.slice(str.length) + str;
|
|
8791
|
+
};
|
|
8792
|
+
|
|
8793
|
+
var a = Array.prototype.map.call(u, function (x) {
|
|
8794
|
+
return zpad(x.toString(16));
|
|
8795
|
+
}); // Array of String to String
|
|
8796
|
+
|
|
8797
|
+
var str = a.join('').toLowerCase(); // and snip off the excess digit if we want an odd number
|
|
8798
|
+
|
|
8799
|
+
if (nChar % 2) str = str.slice(1); // return what we made
|
|
8800
|
+
|
|
8801
|
+
return str;
|
|
8802
|
+
} // We need to detect whether the nodejs crypto module is available to determine how to
|
|
8803
|
+
// generate secure random numbers below
|
|
8804
|
+
|
|
8805
|
+
|
|
8806
|
+
var nodeCrypto;
|
|
8807
|
+
|
|
8808
|
+
try {
|
|
8809
|
+
nodeCrypto = require('crypto');
|
|
8810
|
+
} catch (e) {
|
|
8811
|
+
nodeCrypto = null;
|
|
8812
|
+
}
|
|
8813
|
+
|
|
8814
|
+
function getNonce() {
|
|
8815
|
+
// detect whether we are in browser or in nodejs, and use the correct csprng
|
|
8816
|
+
if (typeof window === 'undefined' || window === null) {
|
|
8817
|
+
return '0x' + nodeCrypto.randomBytes(32).toString('hex');
|
|
8818
|
+
} else {
|
|
8819
|
+
return '0x' + browserRandomHash(64);
|
|
8820
|
+
}
|
|
8821
|
+
}
|
|
8822
|
+
|
|
8823
|
+
var signatureSchemas = {
|
|
8824
|
+
domains: domains,
|
|
8825
|
+
schemas: schemas,
|
|
8826
|
+
generators: generators,
|
|
8827
|
+
getNonce: getNonce
|
|
8828
|
+
};
|
|
8829
|
+
|
|
8681
8830
|
var abiMap = {};
|
|
8682
8831
|
[RegistryABI, DiscoverProviderFactoryABI, EntityManagerABI].forEach(function (_ref) {
|
|
8683
8832
|
var contractName = _ref.contractName,
|
|
@@ -8738,6 +8887,32 @@ var AudiusABIDecoder = /*#__PURE__*/function () {
|
|
|
8738
8887
|
value: function decodeLogs(_, logs) {
|
|
8739
8888
|
return abiDecoder.decodeLogs(logs);
|
|
8740
8889
|
}
|
|
8890
|
+
}, {
|
|
8891
|
+
key: "decodeAbi",
|
|
8892
|
+
value: function decodeAbi(contractName, encodedABI) {
|
|
8893
|
+
var decodedABI = AudiusABIDecoder.decodeMethod(contractName, encodedABI);
|
|
8894
|
+
var mapping = new Map(); // map without leading underscore in _userId
|
|
8895
|
+
|
|
8896
|
+
decodedABI.params.forEach(function (param) {
|
|
8897
|
+
mapping.set(param.name.substring(1), param.value);
|
|
8898
|
+
});
|
|
8899
|
+
return mapping;
|
|
8900
|
+
}
|
|
8901
|
+
}, {
|
|
8902
|
+
key: "recoverSigner",
|
|
8903
|
+
value: function recoverSigner(_ref2) {
|
|
8904
|
+
var encodedAbi = _ref2.encodedAbi,
|
|
8905
|
+
chainId = _ref2.chainId,
|
|
8906
|
+
entityManagerAddress = _ref2.entityManagerAddress;
|
|
8907
|
+
var decodedAbi = this.decodeAbi('EntityManager', encodedAbi);
|
|
8908
|
+
var data = signatureSchemas.generators.getManageEntityData(chainId, entityManagerAddress, decodedAbi.get("userId"), decodedAbi.get("entityType"), decodedAbi.get("entityId"), decodedAbi.get("action"), decodedAbi.get("metadata"), decodedAbi.get("nonce"));
|
|
8909
|
+
var sig = decodedAbi.get("subjectSig");
|
|
8910
|
+
if (sig === undefined) throw new Error("subjectSig is not present in decoded abi");
|
|
8911
|
+
return sigUtil.recoverTypedSignature({
|
|
8912
|
+
data: data,
|
|
8913
|
+
sig: sig
|
|
8914
|
+
});
|
|
8915
|
+
}
|
|
8741
8916
|
}]);
|
|
8742
8917
|
|
|
8743
8918
|
return AudiusABIDecoder;
|
|
@@ -29015,155 +29190,6 @@ var Auth = /*#__PURE__*/_createClass(function Auth() {
|
|
|
29015
29190
|
logger: new Logger()
|
|
29016
29191
|
});
|
|
29017
29192
|
|
|
29018
|
-
/**
|
|
29019
|
-
* This file includes schemas for use in EIP-712 compliant signature generation and
|
|
29020
|
-
* signature validation, generator functions for generating data
|
|
29021
|
-
* in the form needed by eth_personalSign / eth-sig-util's signTypedData functions,
|
|
29022
|
-
* generators for contract signing domains, and a helper function for generating
|
|
29023
|
-
* cryptographically secure nonces in nodejs or in the browser.
|
|
29024
|
-
* modeled off: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md
|
|
29025
|
-
*/
|
|
29026
|
-
var domains = {};
|
|
29027
|
-
|
|
29028
|
-
function getDomainData(contractName, signatureVersion, chainId, contractAddress) {
|
|
29029
|
-
return {
|
|
29030
|
-
name: contractName,
|
|
29031
|
-
version: signatureVersion,
|
|
29032
|
-
chainId: chainId,
|
|
29033
|
-
verifyingContract: contractAddress
|
|
29034
|
-
};
|
|
29035
|
-
}
|
|
29036
|
-
|
|
29037
|
-
domains.getEntityManagerDomain = function (chainId, contractAddress) {
|
|
29038
|
-
return getDomainData('Entity Manager', '1', chainId, contractAddress);
|
|
29039
|
-
};
|
|
29040
|
-
|
|
29041
|
-
var schemas = {};
|
|
29042
|
-
/* contract signing domain */
|
|
29043
|
-
|
|
29044
|
-
schemas.domain = [{
|
|
29045
|
-
name: 'name',
|
|
29046
|
-
type: 'string'
|
|
29047
|
-
}, {
|
|
29048
|
-
name: 'version',
|
|
29049
|
-
type: 'string'
|
|
29050
|
-
}, {
|
|
29051
|
-
name: 'chainId',
|
|
29052
|
-
type: 'uint256'
|
|
29053
|
-
}, {
|
|
29054
|
-
name: 'verifyingContract',
|
|
29055
|
-
type: 'address'
|
|
29056
|
-
}];
|
|
29057
|
-
schemas.manageEntity = [{
|
|
29058
|
-
name: 'userId',
|
|
29059
|
-
type: 'uint'
|
|
29060
|
-
}, {
|
|
29061
|
-
name: 'entityType',
|
|
29062
|
-
type: 'string'
|
|
29063
|
-
}, {
|
|
29064
|
-
name: 'entityId',
|
|
29065
|
-
type: 'uint'
|
|
29066
|
-
}, {
|
|
29067
|
-
name: 'action',
|
|
29068
|
-
type: 'string'
|
|
29069
|
-
}, {
|
|
29070
|
-
name: 'metadata',
|
|
29071
|
-
type: 'string'
|
|
29072
|
-
}, {
|
|
29073
|
-
name: 'nonce',
|
|
29074
|
-
type: 'bytes32'
|
|
29075
|
-
}];
|
|
29076
|
-
var generators = {};
|
|
29077
|
-
|
|
29078
|
-
function getRequestData(domainDataFn, chainId, contractAddress, messageTypeName, messageSchema, message) {
|
|
29079
|
-
var domainData = domainDataFn(chainId, contractAddress);
|
|
29080
|
-
var types = {
|
|
29081
|
-
EIP712Domain: schemas.domain
|
|
29082
|
-
};
|
|
29083
|
-
types[messageTypeName] = messageSchema;
|
|
29084
|
-
return {
|
|
29085
|
-
types: types,
|
|
29086
|
-
domain: domainData,
|
|
29087
|
-
primaryType: messageTypeName,
|
|
29088
|
-
message: message
|
|
29089
|
-
};
|
|
29090
|
-
}
|
|
29091
|
-
/* User Factory Generators */
|
|
29092
|
-
|
|
29093
|
-
|
|
29094
|
-
generators.getAddUserRequestData = function (chainId, contractAddress, handle, nonce) {
|
|
29095
|
-
var message = {
|
|
29096
|
-
handle: handle,
|
|
29097
|
-
nonce: nonce
|
|
29098
|
-
};
|
|
29099
|
-
return getRequestData(domains.getUserFactoryDomain, chainId, contractAddress, 'AddUserRequest', schemas.addUserRequest, message);
|
|
29100
|
-
};
|
|
29101
|
-
|
|
29102
|
-
generators.getManageEntityData = function (chainId, contractAddress, userId, entityType, entityId, action, metadata, nonce) {
|
|
29103
|
-
var message = {
|
|
29104
|
-
userId: userId,
|
|
29105
|
-
entityType: entityType,
|
|
29106
|
-
entityId: entityId,
|
|
29107
|
-
action: action,
|
|
29108
|
-
metadata: metadata,
|
|
29109
|
-
nonce: nonce
|
|
29110
|
-
};
|
|
29111
|
-
return getRequestData(domains.getEntityManagerDomain, chainId, contractAddress, 'ManageEntity', schemas.manageEntity, message);
|
|
29112
|
-
};
|
|
29113
|
-
/** Return a secure random hex string of nChar length in a browser-compatible way
|
|
29114
|
-
* Taken from https://stackoverflow.com/questions/37378237/how-to-generate-a-random-token-of-32-bit-in-javascript
|
|
29115
|
-
*/
|
|
29116
|
-
|
|
29117
|
-
|
|
29118
|
-
function browserRandomHash(nChar) {
|
|
29119
|
-
// convert number of characters to number of bytes
|
|
29120
|
-
var nBytes = Math.ceil(nChar = (+nChar || 8) / 2); // create a typed array of that many bytes
|
|
29121
|
-
|
|
29122
|
-
var u = new Uint8Array(nBytes); // populate it wit crypto-random values
|
|
29123
|
-
|
|
29124
|
-
window.crypto.getRandomValues(u); // convert it to an Array of Strings (e.g. '01', 'AF', ..)
|
|
29125
|
-
|
|
29126
|
-
var zpad = function zpad(str) {
|
|
29127
|
-
return '00'.slice(str.length) + str;
|
|
29128
|
-
};
|
|
29129
|
-
|
|
29130
|
-
var a = Array.prototype.map.call(u, function (x) {
|
|
29131
|
-
return zpad(x.toString(16));
|
|
29132
|
-
}); // Array of String to String
|
|
29133
|
-
|
|
29134
|
-
var str = a.join('').toLowerCase(); // and snip off the excess digit if we want an odd number
|
|
29135
|
-
|
|
29136
|
-
if (nChar % 2) str = str.slice(1); // return what we made
|
|
29137
|
-
|
|
29138
|
-
return str;
|
|
29139
|
-
} // We need to detect whether the nodejs crypto module is available to determine how to
|
|
29140
|
-
// generate secure random numbers below
|
|
29141
|
-
|
|
29142
|
-
|
|
29143
|
-
var nodeCrypto;
|
|
29144
|
-
|
|
29145
|
-
try {
|
|
29146
|
-
nodeCrypto = require('crypto');
|
|
29147
|
-
} catch (e) {
|
|
29148
|
-
nodeCrypto = null;
|
|
29149
|
-
}
|
|
29150
|
-
|
|
29151
|
-
function getNonce() {
|
|
29152
|
-
// detect whether we are in browser or in nodejs, and use the correct csprng
|
|
29153
|
-
if (typeof window === 'undefined' || window === null) {
|
|
29154
|
-
return '0x' + nodeCrypto.randomBytes(32).toString('hex');
|
|
29155
|
-
} else {
|
|
29156
|
-
return '0x' + browserRandomHash(64);
|
|
29157
|
-
}
|
|
29158
|
-
}
|
|
29159
|
-
|
|
29160
|
-
var signatureSchemas = {
|
|
29161
|
-
domains: domains,
|
|
29162
|
-
schemas: schemas,
|
|
29163
|
-
generators: generators,
|
|
29164
|
-
getNonce: getNonce
|
|
29165
|
-
};
|
|
29166
|
-
|
|
29167
29193
|
({
|
|
29168
29194
|
contractAddress: servicesConfig.entityManagerContractAddress,
|
|
29169
29195
|
web3ProviderUrl: servicesConfig.web3ProviderUrl,
|