Skip to content

Commit

Permalink
Update MSL
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljscript committed Jun 10, 2024
1 parent ff8b8d1 commit 28dbf28
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions apps/wallet-mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ PODS:
- React-Core
- react-native-haskell-shelley (6.0.0-alpha.9):
- React
- react-native-message_signing-library (1.0.2):
- react-native-message_signing-library (1.0.3):
- React
- react-native-mmkv (2.11.0):
- MMKV (>= 1.2.13)
Expand Down Expand Up @@ -826,7 +826,7 @@ SPEC CHECKSUMS:
amplitude-react-native: 1ea3d5e1f80ccc357dd178c55c29e51c89f1cd11
boost: 57d2868c099736d80fcd648bf211b4431e51a558
BVLinearGradient: e3aad03778a456d77928f594a649e96995f1c872
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
EXApplication: d8f53a7eee90a870a75656280e8d4b85726ea903
EXBarCodeScanner: 8e23fae8d267dbef9f04817833a494200f1fce35
EXCamera: 0fbfa338a3776af2722d626a3437abe33f708aad
Expand All @@ -843,7 +843,7 @@ SPEC CHECKSUMS:
FBLazyVector: 12ea01e587c9594e7b144e1bfc86ac4d9ac28fde
FBReactNativeSpec: faca7d16c37626ca5780a87adef703817722fe61
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libaom: 144606b1da4b5915a1054383c3a4459ccdb3c661
libavif: 84bbb62fb232c3018d6f1bab79beea87e35de7b7
Expand Down Expand Up @@ -877,7 +877,7 @@ SPEC CHECKSUMS:
react-native-ble-plx: f10240444452dfb2d2a13a0e4f58d7783e92d76e
react-native-config: 86038147314e2e6d10ea9972022aa171e6b1d4d8
react-native-haskell-shelley: 4015aef14eca3ecf5e8d8718e8d1b47cdcf60f84
react-native-message_signing-library: e81294a3cd40d74d3d83f0a1de72aa319238f09a
react-native-message_signing-library: 8d52817fc7157104b97a9b60f45b33a19528db88
react-native-mmkv: e97c0c79403fb94577e5d902ab1ebd42b0715b43
react-native-pager-view: 0ccb8bf60e2ebd38b1f3669fa3650ecce81db2df
react-native-quick-base64: 62290829c619fbabca4c41cfec75ae759d08fc1c
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"@emurgo/cross-csl-mobile": "4.4.0",
"@emurgo/cross-msl-mobile": "^1.0.0",
"@emurgo/csl-mobile-bridge": "6.0.0-alpha.9",
"@emurgo/msl-mobile-bridge": "^1.0.2",
"@emurgo/msl-mobile-bridge": "^1.0.3",
"@emurgo/react-native-blockies-svg": "^0.0.2",
"@emurgo/react-native-hid": "^5.15.6",
"@emurgo/yoroi-lib": "0.15.5-alpha.7",
Expand Down
6 changes: 6 additions & 0 deletions apps/wallet-mobile/src/yoroi-wallets/cardano/cip30/cip30.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,20 @@ class CIP30Extension {
async signData(rootKey: string, address: string, payload: string): Promise<{signature: string; key: string}> {
const {csl, release} = getCSL()
try {
console.log('signData', rootKey, address, payload)
const payloadInBytes = Buffer.from(payload, 'utf-8')

const normalisedAddress = await normalizeToAddress(csl, address)
console.log('normalisedAddress', normalisedAddress)
const bech32Address = await normalisedAddress?.toBech32(undefined)
if (!bech32Address || !normalisedAddress) throw new Error('Invalid address')

const path = getDerivationPathForAddress(bech32Address, this.wallet, true)
console.log('path', path)
const signingKey = await createRawTxSigningKey(rootKey, path)
console.log('signingKey', signingKey)
const coseSign1 = await cip8.sign(Buffer.from(await normalisedAddress.toHex(), 'hex'), signingKey, payloadInBytes)
console.log('coseSign1', coseSign1)
const key = await MSL.COSEKey.new(await MSL.Label.fromKeyType(MSL.KeyType.OKP))
await key.setAlgorithmId(await MSL.Label.fromAlgorithmId(MSL.AlgorithmId.EdDSA))
await key.setHeader(
Expand All @@ -154,6 +159,7 @@ class CIP30Extension {
await MSL.CBORValue.newBytes(await (await signingKey.toPublic()).asBytes()),
)

console.log('generating results')
return {
signature: Buffer.from(await coseSign1.toBytes()).toString('hex'),
key: Buffer.from(await key.toBytes()).toString('hex'),
Expand Down
19 changes: 19 additions & 0 deletions apps/wallet-mobile/src/yoroi-wallets/cardano/cip8/cip8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,33 @@ import {Buffer} from 'buffer'
const MSL = init('cip8')

export const sign = async (address: Buffer, signKey: PrivateKey, payload: Buffer) => {
console.log('signing', address, signKey, payload)
console.log('-----------------------------------')
console.log('MSL', MSL)
console.log('MSL.HeaderMap', MSL.HeaderMap)
console.log('MSL.HeaderMap.new', MSL.HeaderMap.new)
try {
const h = await MSL.HeaderMap.new()

Check failure on line 14 in apps/wallet-mobile/src/yoroi-wallets/cardano/cip8/cip8.ts

View workflow job for this annotation

GitHub Actions / check

'h' is assigned a value but never used. Allowed unused vars must match /^_/u
} catch (e) {
console.log('error', e)
}
const protectedHeader = await MSL.HeaderMap.new()
console.log('protectedHeader', protectedHeader)
await protectedHeader.setAlgorithmId(await MSL.Label.fromAlgorithmId(MSL.AlgorithmId.EdDSA))
console.log('protectedHeader', protectedHeader)
await protectedHeader.setHeader(await MSL.Label.newText('address'), await MSL.CBORValue.newBytes(address))
console.log('protectedHeader', protectedHeader)
const protectedSerialized = await MSL.ProtectedHeaderMap.new(protectedHeader)
console.log('protectedSerialized', protectedSerialized)
const unprotected = await MSL.HeaderMap.new()
console.log('unprotected', unprotected)
const headers = await MSL.Headers.new(protectedSerialized, unprotected)
console.log('headers', headers)
const builder = await MSL.COSESign1Builder.new(headers, payload, false)
console.log('builder', builder)
const toSign = await (await builder.makeDataToSign()).toBytes()
console.log('toSign', toSign)
const signedSigStruct = await (await signKey.sign(toSign)).toBytes()
console.log('signed', signedSigStruct)
return builder.build(signedSigStruct)
}
39 changes: 7 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2167,10 +2167,10 @@
dependencies:
base-64 "0.1.0"

"@emurgo/msl-mobile-bridge@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@emurgo/msl-mobile-bridge/-/msl-mobile-bridge-1.0.2.tgz#3241ff5728a7b34b890641843b36c62b6876d09f"
integrity sha512-RQ+X8ovF09jPr3xwG1XVAr/O2YFVZFDGALbLPMEjszvSw12Su3FNgLGvMwXfSvL9T/csR0BF1NqkGauJONedmw==
"@emurgo/msl-mobile-bridge@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@emurgo/msl-mobile-bridge/-/msl-mobile-bridge-1.0.3.tgz#7d1f64c144a14afcbdccbf016241d37408914f32"
integrity sha512-Asc+rPSXKRfFCJJeOJoGjp+oHk95inQTy44j+/ds1kk3p+6oYq/sn57VjjmGz+DqiDtEqtLZnDpryk7fS/J6Wg==
dependencies:
base-64 "0.1.0"

Expand Down Expand Up @@ -21199,16 +21199,7 @@ string-natural-compare@^3.0.1:
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -21321,7 +21312,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -21349,13 +21340,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -22968,7 +22952,7 @@ workerpool@6.2.1:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343"
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down Expand Up @@ -23004,15 +22988,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
Expand Down

0 comments on commit 28dbf28

Please sign in to comment.